AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   client_authorized triggers twice? (https://forums.alliedmods.net/showthread.php?t=50989)

mysticssjgoku4 02-08-2007 14:22

client_authorized triggers twice?
 
Gah I'm really angry right now, because I've been making a simple* mind you simple plugin that redistributes weapons back to players on join.

Now I've tried setting tasks with "task_exists" and even global variables for stops....no matter what it always EXECUTES TWICE!?!?!?!? W#%(*@#(@$@(%#)$%
I've been working with this for over 2 hours and I'm really annoyed at this point.

Code:
public client_authorized(id) {     give_weapons(id+6500) } public give_weapons(id) {     id -= 6500     if(g_weapon_hold[id] == 1) return PLUGIN_HANDLED     if(!is_user_connected(id) && !is_user_connecting(id))     {         remove_task(id+6500)         return PLUGIN_HANDLED     }     if(!is_user_alive(id))     {         //client_print(id,print_chat,"[WeaponSave] You have weapons pending. Please spawn immediately for re-distribution.")         set_task(5.0,"give_weapons",id+6500)         return PLUGIN_HANDLED     }     if(g_weapon_hold[id] == 1) return PLUGIN_HANDLED     g_weapon_hold[id] = 1     format(g_Query[id],QUERY_MAX_USER-1,"SELECT WID,WClip,WAmmo,WMode,WAddons,WAddons_Active FROM users_weapons WHERE SteamID='%s'",g_SteamIDS[id])     result = dbi_query(dbc,"%s",g_Query[id])     if(dbi_nextrow(result) > 0)     {         new wid, clip, ammo, mode, extras, extras_active         new num_rows = dbi_num_rows(result)         for(new i=0; i < num_rows;i++)         {             wid = dbi_field(result,1)             clip = dbi_field(result,2)             ammo = dbi_field(result,3)             mode  = dbi_field(result,4)             extras  = dbi_field(result,5)             extras_active  = dbi_field(result,6)             client_print(id,print_console,"WID: %i",wid)             ts_giveweapon(id,wid,clip,extras)             dbi_nextrow(result)         }         client_cmd(id,"weapon_0")     }     dbi_free_result(result)     server_print("GIVEN")     g_weapon_hold[id] = 1     return PLUGIN_HANDLED }

Can anyone help me? Thanks.

buskfaus 02-08-2007 15:40

Re: client_authorized triggers twice?
 
Why don't you simply execute your give_weapons function on client_putinserver ? I think this may help you.

lunarwolfx 02-08-2007 17:32

Re: client_authorized triggers twice?
 
my only guess is that your server has sv_downloadurl enabled so the user connects once and the server checks for files, then forces the user to reconnect. At least, that's what I think happens, I don't use sv_downloadurl so I'm not too sure what happens.

In anycase, buskfaus is probably right, just use client_putinserver

mysticssjgoku4 02-08-2007 17:58

Re: client_authorized triggers twice?
 
client put in server doesn't work with TS correctly for some odd reason.

stupok 02-08-2007 20:25

Re: client_authorized triggers twice?
 
In my experience I've never had a problem with client_putinserver() using TS.

XxAvalanchexX 02-10-2007 03:23

Re: client_authorized triggers twice?
 
I have a hunch. Try removing the give_weapons call and see if it still occurrs twice.

mysticssjgoku4 02-14-2007 01:13

Re: client_authorized triggers twice?
 
Nope, I put a server_print() at the begining, and if its removed, it does nothing, if I put it in client_putinserver(id) it does it twice :S.
client_authorized(id) does the same, and does it twice.

Code:
public client_authorized(id) {     give_weap(id+6500)     return PLUGIN_HANDLED } public give_weap(id) {     server_print("triggered")     if(task_exists(id+6500)) id -= 6500         if(!is_user_connected(id) && !is_user_connecting(id))     {         remove_task(id+6500)         return PLUGIN_HANDLED     }     if(!is_user_alive(id) && !task_exists(id+6500))       {         //client_print(id,print_chat,"[WeaponSave] You have weapons pending. Please spawn immediately for re-distribution.")         set_task(5.0,"give_weap",id+6500)         return PLUGIN_HANDLED     }     if(g_weapon_hold[id] == 1) return PLUGIN_HANDLED     format(g_Query[id],QUERY_MAX_USER-1,"SELECT WID,WClip,WAmmo,WMode,WAddons,WAddons_Active FROM users_weapons WHERE SteamID='%s'",g_SteamIDS[id])     result = dbi_query(dbc,"%s",g_Query[id])     if(dbi_nextrow(result) > 0)     {         new wid, clip, ammo, mode, extras, extras_active         new num_rows = dbi_num_rows(result)         for(new i=0; i < num_rows;i++)         {             if(g_weapon_hold[id] == 1) return PLUGIN_HANDLED             wid = dbi_field(result,1)             clip = dbi_field(result,2)             ammo = dbi_field(result,3)             mode  = dbi_field(result,4)             extras  = dbi_field(result,5)             extras_active  = dbi_field(result,6)             client_print(id,print_console,"WID: %i",wid)             ts_giveweapon(id,wid,clip,extras)             dbi_nextrow(result)         }         g_weapon_hold[id] = 1         client_cmd(id,"weapon_0")     }     dbi_free_result(result)     server_print("GIVEN")     g_weapon_hold[id] = 1     return PLUGIN_HANDLED }

allenwr 02-14-2007 01:25

Re: client_authorized triggers twice?
 
you want it where when a client spawns, they get a gun? because you cant give a user a gun when they "authorize", because they are not alive and or in game to recieve a gun. if i am correct, client authorized indicates that the steam id is validated…

BetaX 02-14-2007 03:02

Re: client_authorized triggers twice?
 
Code:
    if(task_exists(id+6500)) id -= 6500         if(!is_user_connected(id) && !is_user_connecting(id))     {         remove_task(id+6500)         return PLUGIN_HANDLED     }

Something feels wrong there.

I'm thinking that first 'task_exists' is wrong.
If the task does exist, do you want to do:

Code:
        id -= 6500

or do you want:

Code:
       remove_task(id+6500)

Also, should:

Code:
       if(!is_user_connected(id) && !is_user_connecting(id))

have its && changed to a ||?

I recommend writing out your thoughts on a piece of paper to clear out what makes sense and what does not. :| Draw a flowchart or something.

Edit: And for the sake of the processor, change all those id+6500's to a single variable equalling id + 6500... for whatever reason you are doing that.


All times are GMT -4. The time now is 00:41.

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