AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Shows weird name (https://forums.alliedmods.net/showthread.php?t=146890)

bibu 01-02-2011 14:57

Shows weird name
 
Is it right like that, cause I get weird names, the print is a string.

PHP Code:

new szName[32];

get_user_name(attackerszNamecharsmax(szName)) 


fysiks 01-02-2011 15:21

Re: Shows weird name
 
What is the value of attacker?

bibu 01-02-2011 16:36

Re: Shows weird name
 
What do you mean with value?

SpeeDeeR 01-02-2011 16:39

Re: Shows weird name
 
He means it won't give proper name if the attacker's value isnt id.

bibu 01-02-2011 16:44

Re: Shows weird name
 
Oh nono, there you go:

PHP Code:

in init:

register_event"Damage""eventDamage""b" );

public 
eventDamage( )
{
    if( 
g_bKnifeHit )
    {
        
g_bKnifeHit false;
        
        static 
victim;
        
victim g_HitData[iVictim];
        
        if( !( 
<= victim <= 32 ) )
        {
            return 
PLUGIN_CONTINUE;
        }
        
        static 
attacker;
        
attacker g_HitData[iAttacker];
        
        static 
Float:distance;
        
distance g_HitData[flDistance];
        
        static 
Float:health;
        
pevvictimpev_healthhealth );
        
        static 
rgb;
        
GetHudColorrg);
        
        static 
Float:xFloat:y;
        
GetHudCoordsx);
        
        
set_hudmessagergbxy00.0get_pcvar_floatg_pCVarHudHoldtime ), 0.00.0);
        
        new 
szName[32];
        
        if( 
g_HitData[iAttack] == STAB )
        {
            
show_hudmessageattacker"Stab Stats (%s)^nDistance: %f (max: 32.0)^nHit: %s (%s)^nDamage: %i"\
                , 
g_szTraceType[TraceType:!g_HitData[iHitgroup]],\
                
distanceget_user_name(victimszNamecharsmax(szName))  ,\
                
g_szHitgroup[g_HitData[iHitgroup]], pevvictimpev_dmg_take ) );
        
            if( 
health 0.0 )
            {
                
ColorChatvictimBLUE"[Knife Distance] %s stabbed you within %f units (%s)!",\
                    
get_user_name(attackerszNamecharsmax(szName))  ,\
                    
distanceg_szHitgroup[g_HitData[iHitgroup]] );
                
                if( 
distance >= get_pcvar_floatg_pCVarSoundGodlikeStab ) )
                {
                    
ColorChat0RED"[Knife Distance] %s stabbed %s within %f units (%s)!",\
                        
get_user_name(attackerszNamecharsmax(szName))  , get_user_name(victimszNamecharsmax(szName))  ,\
                        
distanceg_szHitgroup[g_HitData[iHitgroup]] );
                    
client_cmd0"spk %s"g_szSound[GODLIKE] );
                        
                }
                else if( 
distance >= get_pcvar_floatg_pCVarSoundWickedSickStab ) )
                {
                    
ColorChat0GREEN"[Knife Distance] %s stabbed %s within %f units (%s)!",\
                        
get_user_name(attackerszNamecharsmax(szName))  , get_user_name(victimszNamecharsmax(szName))  ,\
                        
distanceg_szHitgroup[g_HitData[iHitgroup]] );
                    
client_cmd0"spk %s"g_szSound[WICKEDSICK] );
                }
            }
        }
        else
        {
            
show_hudmessageattacker"Slash Stats (%s)^nDistance: %f (max: 48.0)^nHit: %s (%s)^nDamage: %i"\
                , 
g_szTraceType[TraceType:!g_HitData[iHitgroup]],\
                
distanceget_user_name(victimszNamecharsmax(szName))  ,\
                
g_szHitgroup[g_HitData[iHitgroup]], pevvictimpev_dmg_take ) );
            
            if( 
health 0.0 )
            {
                
ColorChatvictimBLUE"[Knife Distance] %s slashed you within %f units (%s)!",\
                    
get_user_name(attackerszNamecharsmax(szName))  ,\
                    
distanceg_szHitgroup[g_HitData[iHitgroup]] );
                
                if( 
distance >= get_pcvar_floatg_pCVarSoundGodlikeSlash ) )
                {
                    
ColorChat0RED"[Knife Distance] %s slashed %s within %f units (%s)!",\
                        
get_user_name(attackerszNamecharsmax(szName))  , get_user_name(victimszNamecharsmax(szName))  ,\
                        
distanceg_szHitgroup[g_HitData[iHitgroup]] );
                    
client_cmd0"spk %s"g_szSound[GODLIKE] );
                }
                else if( 
distance >= get_pcvar_floatg_pCVarSoundWickedSickSlash ) )
                {
                    
ColorChat0GREEN"[Knife Distance] %s slashed %s within %f units (%s)!",\
                        
get_user_name(attackerszNamecharsmax(szName))  , get_user_name(victimszNamecharsmax(szName))  ,\
                        
distanceg_szHitgroup[g_HitData[iHitgroup]] );
                    
client_cmd0"spk %s"g_szSound[WICKEDSICK] );
                }
            }
        }
    }
    
    return 
PLUGIN_CONTINUE;



Exolent[jNr] 01-02-2011 19:32

Re: Shows weird name
 
Code:
ColorChat( victim, BLUE, "[Knife Distance] %s stabbed you within %f units (%s)!",     get_user_name(attacker, szName, charsmax(szName))  ,     distance, g_szHitgroup[g_HitData[iHitgroup]] );
There is your problem.
You have to use that in a different line and then use the variable as the print argument.
Code:
get_user_name(attacker, szName, charsmax(szName)); ColorChat( victim, BLUE, "[Knife Distance] %s stabbed you within %f units (%s)!",     szName  ,     distance, g_szHitgroup[g_HitData[iHitgroup]] );
That occurs more than once in the code, so be sure to correct them all.

bibu 01-03-2011 12:04

Re: Shows weird name
 
I didn't really understand what you mean, do I need to use 2 new szName[32]; ?

reinert 01-03-2011 12:16

Re: Shows weird name
 
No, you've to get name before printing it, like you can't print that, what you didn't get yet...

get name
send name...

not -
send name
get name...

bibu 01-03-2011 13:30

Re: Shows weird name
 
Quote:

Originally Posted by reinert (Post 1385244)
No, you've to get name before printing it, like you can't print that, what you didn't get yet...

get name
send name...

not -
send name
get name...

It's everytime like that print %s(variable, ...)

ConnorMcLeod 01-03-2011 13:53

Re: Shows weird name
 
Yes, but string variable array has to be filled first.

PHP Code:

get_user_name(idnamecharsmax(name))
client_print(idprint_chat"Hello %s"name


Also, if you do :

PHP Code:

client_print(idprint_chat"Hello %s"get_user_name(idnamecharsmax(name))) 

then what is passed is not the index of the string, but the result of get_user_name, and get_user_name result is the length of the name.
So amxx try to format %s with a wrong index you obtain weird names wuch as sound/weapons/xbow.wav


All times are GMT -4. The time now is 02:07.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.