AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [HAM] Outputs message twice (https://forums.alliedmods.net/showthread.php?t=273217)

CodingIsHard 10-15-2015 09:42

[HAM] Outputs message twice
 
PHP Code:

RegisterHam(Ham_Spawn"player""fwHamSpawnPlayer");

public 
fwHamSpawnPlayer(id) {
    
client_print_color(idRED"^3Spawned!");
    
set_task(5.0"fnNameProfit"id);
}

public 
fnNameProfit(id) {
    
client_print_color(idRED"^3Hi!");
    return 
PLUGIN_HANDLED;


Whenever i output it 5 seconds after the spawn, plugin prints it twice to the chat with a second delay. Am i doing anything wrong or is this supposed to happen? I tried to HAM_SUPERCED it, i am not a smart man.
Is there a IRC channel or anything for quick and (possibly) dumb questions i could ask occasionally if i can't find the answer after wasting 2 hours of my life. :)

Note: It only happens when the map begins -- on the very first round, second, third etc it only prints once.

HamletEagle 10-15-2015 09:56

Re: [HAM] Outputs message twice
 
Register HAM as post and check is_user_alive before doing anything.

CodingIsHard 10-15-2015 10:05

Re: [HAM] Outputs message twice
 
Done, done.
Still outputs twice.

The fact that only happens once the map starts(after change) makes me cringe..
UPDATE:Wrong, i was absolutely wrong.

Arkshine 10-15-2015 10:13

Re: [HAM] Outputs message twice
 
You did not do add the check then. Check again. Spawn is called a first time when player is put in server (new player, no team yet, not alive), and it will be called again when player actually spawned in the current game (player is now alive). That's why you need to hook as post, and checking if player is alive.

CodingIsHard 10-15-2015 10:19

Re: [HAM] Outputs message twice
 
I just remembered what i saw the other day in a thread, you were correct just you didn't specify where i should've checked wether the player is alive.
I added the check into fwHamPlayerSpawn instead of checking it in my function, makes so much more sense now after the last post.

Cheers, +karma.
Is karma still a thing?


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

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