AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Finding an id with name (https://forums.alliedmods.net/showthread.php?t=17395)

Hawk552 08-30-2005 23:06

Finding an id with name
 
In the below code, how would I match the person's name with their id, if no client called the command? It says in cmd_target that someone has to have called it.

Code:
public join_respawn() {     if(surfmap == false)         {         return PLUGIN_CONTINUE     }         if(get_cvar_num("surf_on")==0)         {         return PLUGIN_CONTINUE     }     if ( !get_cvar_num("surf_respawn") )         return PLUGIN_CONTINUE         new arg[32]     read_data(3,arg,31)         //Debug stuff     client_print(0,print_chat,"[AMXX] data is %s",arg)         new id = cmd_target(0,"arg")         /* Spawn the player twice to avoid the HL engine bug */     set_task(0.5,"player_spawn",id)     set_task(0.7,"player_spawn",id)         /* Then give them a suit and a knife */     set_task(0.9,"player_giveitems",id)         return PLUGIN_CONTINUE }

My console gets spammed with this:

Code:

L 08/30/2005 - 22:01:02: [AMXX] [FUN] Invalid player 0 (not in-game)
L 08/30/2005 - 22:01:02: [AMXX] Displaying call trace (plugin "cstrike\addons\amxmodx\plugins\surftools.amxx")
L 08/30/2005 - 22:01:02: [AMXX]    [0] surftools.sma::player_spawn (line 298)
L 08/30/2005 - 22:01:02: [AMXX] [FUN] Invalid player 0 (not in-game)
L 08/30/2005 - 22:01:02: [AMXX] Displaying call trace (plugin "cstrike\addons\amxmodx\plugins\surftools.amxx")
L 08/30/2005 - 22:01:02: [AMXX]    [0] surftools.sma::player_spawn (line 298)
L 08/30/2005 - 22:01:02: [AMXX] [FUN] Player out of range (0)
L 08/30/2005 - 22:01:02: [AMXX] Displaying call trace (plugin "cstrike\addons\amxmodx\plugins\surftools.amxx")
L 08/30/2005 - 22:01:02: [AMXX]    [0] surftools.sma::player_giveitems (line 263)
[AMXX] data is Hawk

Which leads me to believe "id" is improperly matched, and remains at it's default value, 1.

If needed, this is what calls it:

Code:
register_event("TextMsg","join_respawn","a","1=1","2&Game_join_te","2&Game_join_ct")

pdoubleopdawg 08-30-2005 23:13

Player 0 is the server. This means it's trying to spawn every player (The Server)

if(is_player_connected(id)) {
code
}

XxAvalanchexX 08-30-2005 23:19

Try this modified version:

Code:
stock cmd_target_nouser(const arg[],flags = 1) {   new player = find_player("bl",arg)   if (player) {     if ( player != find_player("blj",arg) ) {       return 0         }   }   else if ( ( player = find_player("c",arg) )==0 && arg[0]=='#' && arg[1] )     player = find_player("k",str_to_num(arg[1]))       if (!player) {     return 0   }   if (flags & 1) {     if (get_user_flags(player)&ADMIN_IMMUNITY) {       return 0     }   }   if (flags & 4) {     if (!is_user_alive(player)) {       return 0     }   }   if (flags & 8) {     if (is_user_bot(player)) {       return 0     }   }   return player }

Hawk552 08-30-2005 23:42

Same thing. Here's the entire source code, and the error.

Code:
/* Surf Tools by Hawk552 Description: A combination of plugins containing features including: - Automatic commands / cvars on surf maps - Automatic respawning on surf maps, with an added failsafe of clients being able to say /respawn - Help commands for surfing Credits: Thanks to Geesu for parts of the respawn plugin. Thanks to DahVid for the idea to code the /surfhelp MOTD directly into the plugin. More features included in Surf Tools / Management - Extras */ #include <amxmodx> #include <amxmisc> #include <fun> #define HELP_INTERVAL 60.0 #define UNASSIGNED 0 #define PLUGIN "Surf Tools / Management" #define VERSION "3.1" #define AUTHOR "Hawk552" new bool:surfmap = false new g_arg[64] public plugin_init()     {     checksurf()     register_plugin(PLUGIN,VERSION,AUTHOR)         //Global Commands / Cvars     register_cvar("surf_on","1")         //Respawn     register_cvar("surf_respawn","1")     register_event("DeathMsg","on_Death","a")     register_clcmd("say /respawn","respawn")     register_event("TextMsg","join_respawn","a","1=1","2&Game_join_te","2&Game_join_ct") // Team Joining         //Auto Cvars     register_cvar("surf_autocvars","1")     register_cvar("surf_timelimit","0")     register_concmd("surf_command","surfcommand",ADMIN_CVAR," <command> - executes a command on a surf map")         //Surf Help     register_clcmd("say /surfhelp","surfhelp")     register_cvar("surf_help","1")     if(surfmap == true)         {         set_task(4.0,"exec_cvars")     } } public checksurf()     {     new mapname[64]     get_mapname(mapname,63)     if(containi(mapname,"surf_")!=-1)         {         surfmap = true     }     return PLUGIN_HANDLED } public surfcommand()     {         if(surfmap == false)         {         return PLUGIN_HANDLED             }         if(get_cvar_num("surf_on")==0)         {         return PLUGIN_HANDLED     }         read_argv(1,g_arg,63)         set_task(5.0,"surfcommand_task")         return PLUGIN_HANDLED } public surfcommand_task()     {     if(surfmap == false)         {         return PLUGIN_HANDLED             }         if(get_cvar_num("surf_on")==0)         {         return PLUGIN_HANDLED     }         server_cmd(g_arg)         return PLUGIN_HANDLED } public client_putinserver(id)     {     if(surfmap == false)         {         return PLUGIN_HANDLED             }         if(get_cvar_num("surf_on")==0)         {         return PLUGIN_HANDLED     }         if(get_cvar_num("surf_help")==1)         {         if(surfmap==true)             {             set_task(HELP_INTERVAL,"surfhelpshow",id,_,_,"b")         }     }     return PLUGIN_HANDLED } public surfhelp(id)     {     if(surfmap == false)         {         return PLUGIN_HANDLED             }         if(get_cvar_num("surf_on")==0)         {         return PLUGIN_HANDLED     }     /*  new configsdir[50]     get_configsdir(configsdir,49)     new location[50]     format(location,49,"%s/surf/surfhelp.htm",configsdir)     show_motd(id,location,"Surf Help")     return PLUGIN_HANDLED     */     new motd[2048], title[16], dpos = 0     format(title, 15, "Surf Help")         dpos += format(motd[dpos], 2047-dpos, "<html><head><style type=^"text/css^">pre{color:#FFB000;}body{background:#000000;margin-left:8px;margin-top:0px;}</style></head><pre><body>")     dpos += format(motd[dpos], 2047-dpos, "<b>Before you begin to surf, it's best to learn some simple things to help you out.</b>^n")     dpos += format(motd[dpos], 2047-dpos,"^nBeginner Tips:^n")     dpos += format(motd[dpos], 2047-dpos,"1.) To surf, jump or walk onto one of the curved walls (hereby referted to as 'ramps'). Then simply hold strafe (Default are the A and D keys). This will glitch out the physics and cause you to glide along the walls.^n")     dpos += format(motd[dpos], 2047-dpos,"^n2.) While surfing, NEVER press up, down, or courch; pressing those will cause you to slide off the wall and fall, which in 99% of surf maps will cause you to instantly die.^n")     dpos += format(motd[dpos], 2047-dpos,"^n3.) To change direction (in order to make it to the next ramp), simply press the direction you wish to go, BEFORE flying off of your current ramp.^n")     dpos += format(motd[dpos], 2047-dpos,"^n4.) Surfing takes pratice, so don't be discouraged if you don't get it right the first time.^n")     dpos += format(motd[dpos], 2047-dpos,"^n5.) Yes, all surf maps CAN be completed with normal gravity (800) and normal airaccelerate (10). So don't think that it isn't possible.^n")     dpos += format(motd[dpos], 2047-dpos,"^n4.) Surfing takes pratice, so don't be discouraged if you don't get it right the first time.^n")         show_motd(id, motd, title)         return PLUGIN_HANDLED } public surfhelpshow(id)     {     if(surfmap == false)         {         return PLUGIN_HANDLED             }         if(get_cvar_num("surf_on")==0)         {         return PLUGIN_HANDLED     }     if(get_cvar_num("surf_respawn")==1)         {         client_print(id,print_chat,"[AMXX] Say /surfhelp for surfing help. Also, say /respawn to respawn.")     }     else     {         if(get_cvar_num("surf_respawn")==0)             {             client_print(id,print_chat,"[AMXX] Need help surfing? Say /surfhelp")         }     }     return PLUGIN_CONTINUE } public exec_cvars()     {     if(surfmap == true)         {         if(get_cvar_num("surf_autocvars")==1)             {             set_cvar_string("sv_airaccelerate", "100")             server_cmd("amx_pausecfg pause stats_logging.amxx")             server_cmd("amx_pausecfg pause miscstats.amxx")             server_cmd("amx_pausecfg pause statsx.amxx")             server_cmd("amx_pausecfg pause restmenu.amxx")         }         if(get_cvar_num("surf_timelimit") > 0)             {             set_cvar_num("mp_timelimit", get_cvar_num("surf_timelimit"))         }     }     return PLUGIN_HANDLED } public respawn(id)     {     if(surfmap == false)         {         client_print(id,print_chat,"[AMXX] You can only respawn on surf maps.")         return PLUGIN_HANDLED     }         if(get_cvar_num("surf_on")==0)         {         client_print(id,print_chat,"[AMXX] Sorry, the surf plugin is currently disabled.")         return PLUGIN_HANDLED     }         if(get_cvar_num("surf_respawn")!=1)         {         client_print(id,print_chat,"[AMXX] Respawning is currently disabled.")         return PLUGIN_HANDLED     }     if(!is_user_alive(id))         {         if(get_user_team(id)!=UNASSIGNED)             {             set_task(0.5,"player_spawn",id)             set_task(0.7,"player_spawn",id)                         set_task(0.9,"player_giveitems",id)         }         else         {             client_print(id,print_chat,"[AMXX] You must be on a team to respawn.")         }     }     else     {         client_print(id,print_chat,"[AMXX] You must be dead to respawn.")     }     return PLUGIN_CONTINUE } public player_giveitems(id)     {     give_item(id, "item_suit")     give_item(id, "weapon_knife")         return PLUGIN_CONTINUE } public on_Death(id)     {     if(surfmap == false)         {         return PLUGIN_CONTINUE     }         if(get_cvar_num("surf_on")==0)         {         return PLUGIN_CONTINUE     }     if ( !get_cvar_num("surf_respawn") )         return PLUGIN_CONTINUE         new victim_id = read_data(2)     id=victim_id         /* Spawn the player twice to avoid the HL engine bug */     set_task(0.5,"player_spawn",id)     set_task(0.7,"player_spawn",id)         /* Then give them a suit and a knife */     set_task(0.9,"player_giveitems",id)         return PLUGIN_CONTINUE } public player_spawn(id)     {     spawn(id) } public join_respawn()     {     if(surfmap == false)         {         return PLUGIN_CONTINUE     }         if(get_cvar_num("surf_on")==0)         {         return PLUGIN_CONTINUE     }     if ( !get_cvar_num("surf_respawn") )         return PLUGIN_CONTINUE         new arg[32]     read_data(3,arg,31)         //Debug stuff     client_print(0,print_chat,"[AMXX] data is %s",arg)         new id = cmd_target_nouser(arg,1)         // Spawn the player twice to avoid the HL engine bug     set_task(0.5,"player_spawn",id)     set_task(0.7,"player_spawn",id)         // Then give them a suit and a knife     set_task(0.9,"player_giveitems",id)         return PLUGIN_CONTINUE } stock cmd_target_nouser(const arg[],flags = 1) {     new player = find_player("bl",arg)     if (player) {         if ( player != find_player("blj",arg) ) {             return 0             }     }     else if ( ( player = find_player("c",arg) )==0 && arg[0]=='#' && arg[1] )         player = find_player("k",str_to_num(arg[1]))         if (!player) {         return 0     }     if (flags & 1) {         if (get_user_flags(player)&ADMIN_IMMUNITY) {             return 0         }     }     if (flags & 4) {         if (!is_user_alive(player)) {             return 0         }     }     if (flags & 8) {         if (is_user_bot(player)) {             return 0         }     }     return player }

Code:

L 08/30/2005 - 14:53:40: [AMXX] [FUN] Invalid player 0 (not in-game)
L 08/30/2005 - 14:53:40: [AMXX] Debug is not enabled (plugin "cstrike\addons\amxmodx\plugins\surftools.amxx")
L 08/30/2005 - 14:53:40: [AMXX] [FUN] Invalid player 0 (not in-game)
L 08/30/2005 - 14:53:40: [AMXX] Debug is not enabled (plugin "cstrike\addons\amxmodx\plugins\surftools.amxx")
L 08/30/2005 - 14:53:40: [AMXX] [FUN] Player out of range (0)
L 08/30/2005 - 14:53:40: [AMXX] Debug is not enabled (plugin "cstrike\addons\amxmodx\plugins\surftools.amxx")
L 08/30/2005 - 14:53:41: [AMXX] [FUN] Invalid player 0 (not in-game)
L 08/30/2005 - 14:53:41: [AMXX] Debug is not enabled (plugin "cstrike\addons\amxmodx\plugins\surftools.amxx")
L 08/30/2005 - 14:53:41: [AMXX] [FUN] Invalid player 0 (not in-game)
L 08/30/2005 - 14:53:41: [AMXX] Debug is not enabled (plugin "cstrike\addons\amxmodx\plugins\surftools.amxx")
L 08/30/2005 - 14:53:41: [AMXX] [FUN] Player out of range (0)
L 08/30/2005 - 14:53:41: [AMXX] Debug is not enabled (plugin "cstrike\addons\amxmodx\plugins\surftools.amxx")
L 08/30/2005 - 14:53:49: [AMXX] [FUN] Invalid player 0 (not in-game)
L 08/30/2005 - 14:53:49: [AMXX] Debug is not enabled (plugin "cstrike\addons\amxmodx\plugins\surftools.amxx")
L 08/30/2005 - 14:53:49: [AMXX] [FUN] Invalid player 0 (not in-game)
L 08/30/2005 - 14:53:49: [AMXX] Debug is not enabled (plugin "cstrike\addons\amxmodx\plugins\surftools.amxx")
L 08/30/2005 - 14:53:50: [AMXX] [FUN] Player out of range (0)
L 08/30/2005 - 14:53:50: [AMXX] Debug is not enabled (plugin "cstrike\addons\amxmodx\plugins\surftools.amxx")


XxAvalanchexX 08-31-2005 01:28

Enable debug you fool.

Hawk552 08-31-2005 11:33

*Slaps forehead*

Sorry, I had debug enabled when I had it on my test server. Then I moved it to my normal server to see and forgot to put debug back on. BRB I'll get what it says.

Edit:
Code:

L 08/31/2005 - 11:19:28: [AMXX] Function "" was not found
L 08/31/2005 - 11:19:28: [AMXX] Displaying call trace (plugin "cstrike\addons\amxmodx\plugins\surftools.amxx")
L 08/31/2005 - 11:19:28: [AMXX]    [0] surftools.sma::plugin_init (line 57)

It seems the way it's called is a bit messed.

v3x 08-31-2005 12:31

Why not just use cmd_target?

Hawk552 08-31-2005 12:36

Quote:

Originally Posted by v3x
Why not just use cmd_target?

|
|
|
\/

Quote:

Originally Posted by Hawk552
In the below code, how would I match the person's name with their id, if no client called the command? It says in cmd_target that someone has to have called it.

Edit: Ok it's reading the data properly, it says "[AMXX] data is Hawk" and all, but doesn't respawn the person. I made a stupid mistake and compiled a version that had this:

Code:
    register_event("TextMsg","","a","1=1","2&Game_join_te","2&Game_join_ct")

Instead of
Code:
    register_event("TextMsg","join_respawn","a","1=1","2&Game_join_te","2&Game_join_ct")

Edit again:

Now it's giving me this:

Code:

L 08/31/2005 - 08:29:56: [AMXX] [FUN] Invalid player 0 (not in-game)
L 08/31/2005 - 08:29:56: [AMXX] Debug is not enabled (plugin "cstrike\addons\amxmodx\plugins\surftools.amxx")
L 08/31/2005 - 08:29:57: [AMXX] [FUN] Invalid player 0 (not in-game)
L 08/31/2005 - 08:29:57: [AMXX] Debug is not enabled (plugin "cstrike\addons\amxmodx\plugins\surftools.amxx")
L 08/31/2005 - 08:29:57: [AMXX] [FUN] Player out of range (0)
L 08/31/2005 - 08:29:57: [AMXX] Debug is not enabled (plugin "cstrike\addons\amxmodx\plugins\surftools.amxx")

But no errors when in debug. It seems the id checker part isn't working properly either.

Xanimos 08-31-2005 14:10

use cmd_target(1,Playername,flags)

I dont think the caller id matters.

XxAvalanchexX 08-31-2005 15:20

The caller id is used so that cmd_target knows who to send messages such as "Client has immunity" and "No player was found" to, and also for the flag that makes it so it can't be run on yourself.


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

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