AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   get_user_name [shows server name] [help] (https://forums.alliedmods.net/showthread.php?t=105686)

mAr7obg 10-07-2009 06:41

get_user_name [shows server name] [help]
 
I use this script, but instead the name of the player earning the name of my server :cry: if I might help a little to optimize
PHP Code:

#include <amxmodx>
#include <cstrike>
#include <fun>
public plugin_init() {
 
register_plugin"x-","x","x" )
 
register_event"DeathMsg",  "Event_Death",  "a" 
}
public 
Event_Death(id)  {
 
//random hud
 
new random(256)
 new 
random(256)
 new 
random(256)
 
//last player
 
new players_ct[32], players_t[32], ictite;
 
get_players(players_ct,ict,"ae","CT")   
 
get_players(players_t,ict,"ae","TERRORIST")  
 
// get players
 
new name[32]
 
get_user_name(id,name,31)
 if( 
ite == ) { 
  
client_cmd(0,"spk server/stayinalive"); 
  
set_hudmessage(r,g,b, -1.00.3006.06.0)
  
show_hudmessage(0"%s is alone :)"name)
  } else if( 
ict == ) { 
  
client_cmd(id,"spk server/stayinalive");
  
set_hudmessage(r,g,b, -1.00.3006.06.0)
  
show_hudmessage(0"%s is alone :)"name)
 }
}
public 
plugin_precache() {
 
precache_sound("server/stayinalive.wav")



Jon 10-07-2009 07:13

Re: get_user_name [shows server name] [help]
 
There is no index passed in DeathMsg. You need to retrive the index with read_data(). http://wiki.amxmodx.org/Half-Life_1_...vents#DeathMsg

mAr7obg 10-07-2009 07:22

Re: get_user_name [shows server name] [help]
 
i resolved the problem with this code
PHP Code:

#include <amxmodx>
#include <cstrike>
#include <fun>
public plugin_init() {
 
register_plugin"x-","x","x" )
 
register_event"DeathMsg",  "Event_Death",  "a" 
}
public 
Event_Death(id)  {
 
//random hud
 
new random(256)
 new 
random(256)
 new 
random(256)
 
//last player
 
new players_ct[32], players_t[32], ictite;
 
get_players(players_ct,ict,"ae","CT")   
 
get_players(players_t,ict,"ae","TERRORIST")  
 
// get players
 
new name1[32], name2[32]
 
get_user_name(players_ct[0],name1,32)
 
get_user_name(players_t[0],name2,32)
 if( 
ite == ) { 
  
client_cmd(0,"spk server/stayinalive"); 
  
set_hudmessage(r,g,b, -1.00.3006.06.0)
  
show_hudmessage(0"%s is alone :)"name1)
  } else if( 
ict == ) { 
  
client_cmd(id,"spk server/stayinalive");
  
set_hudmessage(r,g,b, -1.00.3006.06.0)
  
show_hudmessage(0"%s is alone :)"name2)
 }
}
public 
plugin_precache() {
 
precache_sound("server/stayinalive.wav")



mAr7obg 10-07-2009 07:36

Re: get_user_name [shows server name] [help]
 
delte

Alucard^ 10-07-2009 09:53

Re: get_user_name [shows server name] [help]
 
Good but the id in the public of the DeathMsg is useless. The DeathMsg is a global event.

vitorrd 10-07-2009 12:23

Re: get_user_name [shows server name] [help]
 
As Jon said, you must use read_data. Also, read http://www.amxmodx.org/funcwiki.php?go=func&id=165 for information on get_user_name. A note is written in the comments section stating that if the specified ID is 0, the server's name is returned (your variable is not used by DeathMsg, therefore it is 0).

mAr7obg 10-07-2009 13:15

Re: get_user_name [shows server name] [help]
 
Quote:

Originally Posted by Alucard^ (Post 954873)
Good but the id in the public of the DeathMsg is useless. The DeathMsg is a global event.

then how to do it without DeathMsg
Last version
PHP Code:

#include <amxmodx>
#include <cstrike>
#include <fun>
#define prpsounds 2
new preplist[prpsounds][]=
{
 
"server/stayinalive"
 
"server/force"
}
public 
plugin_init() {
 
register_plugin"x-","x","x" )
 
register_event"DeathMsg",  "Event_Death",  "a" 
}
public 
Event_Death(id)  {
 
//======== •Random colors
 
new random(256)
 new 
random(256)
 new 
random(256)
 
//======== •Last player
 
new players_ct[32], players_t[32], ictite;
 
get_players(players_ct,ict,"ae","CT")   
 
get_players(players_t,ict,"ae","TERRORIST")  
 
//======== •Get players
 
new name1[32], name2[32]
 
get_user_name(players_ct[0],name1,32)
 
get_user_name(players_t[0],name2,32)
 
//======== •Random Sounds
 
new q
 q 
random_num(0,prpsounds-1)
 
//======== •Begin
 
if( ite == ) { 
  
client_cmd(0,"spk %s",preplist[q]);
  
set_hudmessage(r,g,b, -1.00.3006.06.0)
  
show_hudmessage(0"%s is alone :)"name1)
  } else if( 
ict == ) { 
  
client_cmd(0,"spk %s",preplist[q]);
  
set_hudmessage(r,g,b, -1.00.3006.06.0)
  
show_hudmessage(0"%s is alone :)"name2)
 }
 
//======== •End
}
public 
plugin_precache() {
 
precache_sound("server/stayinalive.wav")
 
precache_sound("server/force.wav")
 return 
PLUGIN_CONTINUE
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1026\\ f0\\ fs16 \n\\ par }
*/ 


Arkshine 10-07-2009 13:19

Re: get_user_name [shows server name] [help]
 
Please read vitorrd.

xPaw 10-07-2009 13:25

Re: get_user_name [shows server name] [help]
 
Not best..

PHP Code:

#include < amxmodx >

new const g_szSounds[ ][ ] = {
    
"server/stayinalive"
    
"server/force"
};

public 
plugin_init( ) {
    
register_plugin"""""" );
    
    
register_event"DeathMsg""EventDeath""a" );
}

public 
plugin_precache( )
    for( new 
isizeof g_szSoundsi++ )
        
precache_soundg_szSounds] );

public 
EventDeath( ) {
    
// This part is stupid but w/e...
    
new iPlayers][ 32 ], iNum];
    
get_playersiPlayers], iNum], "ae""CT" );
    
get_playersiPlayers], iNum], "ae""TERRORIST" );
    
    if( 
iNum] == && iNum] == ) {
        new 
szName][ 32 ];
        
get_user_nameiPlayers][ ], szName], 31 );
        
get_user_nameiPlayers][ ], szName], 31 );
        
        
set_hudmessagerandom256 ), random256 ), random256 ), -1.00.306.06.0 );
        
show_hudmessage0"%s vs %s !"szName], szName] );
    }
    else if( 
iNum] == ) {
        new 
szName32 ];
        
get_user_nameiPlayers][ ], szName31 );
        
        
set_hudmessagerandom256 ), random256 ), random256 ), -1.00.306.06.0 );
        
show_hudmessage0"%s (CT) is alone now :)"szName );
        
        
client_cmd0"spk %s"g_szSoundsrandomsizeof g_szSounds ) ] );
    }
    else if( 
iNum] == ) {
        new 
szName32 ];
        
get_user_nameiPlayers][ ], szName31 );
        
        
set_hudmessagerandom256 ), random256 ), random256 ), -1.00.306.06.0 );
        
show_hudmessage0"%s (T) is alone now :)"szName );
        
        
client_cmd0"spk %s"g_szSoundsrandomsizeof g_szSounds ) ] );
    }



Arkshine 10-07-2009 13:28

Re: get_user_name [shows server name] [help]
 
I hope it's a joke xPaw.


All times are GMT -4. The time now is 22:33.

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