Raised This Month: $51 Target: $400
 12% 

Instaspawn being picky? (TF2)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Eaglebird
Junior Member
Join Date: Sep 2007
Old 01-30-2011 , 16:24   Instaspawn being picky? (TF2)
Reply With Quote #1

I'm running into a problem where an instant spawn script I've written is randomly NOT instantly spawning players. Many will spawn instantly while a few will be given respawn wait times.

I have the following code in the plugin:
Code:
public Action:Event_PlayerDeath(Handle:deathevent, const String:name[], bool:dontBroadcast) {
	new bool:FakeDeath = GetEventBool(deathevent, "feign_death");
	VictimIndex = GetClientOfUserId(GetEventInt(deathevent, "userid"));
	if (Instaspawn && !FakeDeath)
	{
		CreateTimer(0.1, Timer_Respawn, VictimIndex);
	}
	return Plugin_Continue;
}

public Action:Timer_Respawn(Handle:timer, any:client)
{
	// Did the client disconnect between our timer and this action?
    if (IsClientInGame(VictimIndex))
	{
		TF2_RespawnPlayer(VictimIndex);
	}
}
Event_playerdeath is hooked on map start, and Instaspawn is false after the first round.

The issue is that, when enabled, many players will spawn instantly, but a few are given normal respawn times. I'm not sure how to track the problem down, and unfortunately I have trouble reproducing the error for myself (listenserver), and I don't want to run debugging on the production machine.

What would cause most clients to trigger TF2_RespawnPlayer() but a random few not to? (the random few being always random, e.g. one player may wait to respawn and, upon respawning, spawn instantly next time he/she dies.)

Also, is it a better idea to hook and unhook events as needed, or hook an event and leave it hooked and use conditions to determine reacting to it?

Last edited by Eaglebird; 01-30-2011 at 16:26. Reason: small spelling error
Eaglebird is offline
Send a message via AIM to Eaglebird Send a message via MSN to Eaglebird Send a message via Skype™ to Eaglebird
Eaglebird
Junior Member
Join Date: Sep 2007
Old 02-02-2011 , 15:28   Re: Instaspawn being picky? (TF2)
Reply With Quote #2

I've rearranged some things, and hooked event_playerdeath on plugin start instead and have used a conditional to determine whether or not to instantly respawn the player.

PHP Code:
public Action:Event_PlayerDeath(Handle:deathevent, const String:name[], bool:dontBroadcast) {
    if (!
Instaspawn)
    {
        return 
Plugin_Continue;
    }
    else
    {
        new 
bool:FakeDeath GetEventBool(deathevent"feign_death");
        new 
VictimId GetEventInt(deathevent"userid");
        
VictimIndex GetClientOfUserId(VictimId);
        if ((
IsClientInGame(VictimIndex)) && (!FakeDeath))
        {
            
CreateTimer(0.1Timer_RespawnVictimIndex);
        }
        else
        {
            return 
Plugin_Continue;
        }
    }
    return 
Plugin_Continue;

PHP Code:
public Action:Timer_Respawn(Handle:timerany:client)
{
    
TF2_RespawnPlayer(VictimIndex);

Still, the script seems to be picky about who it respawns. Most people get respawned, others have to wait for normal respawn times. I"m not sure how to debug this, and testing the script on my own listenserver I cannot recreate the problem no matter how many times I try.
Eaglebird is offline
Send a message via AIM to Eaglebird Send a message via MSN to Eaglebird Send a message via Skype™ to Eaglebird
toazron1
Senior Member
Join Date: Oct 2006
Old 02-02-2011 , 15:35   Re: Instaspawn being picky? (TF2)
Reply With Quote #3

Try increasing the timer for the respawn, it could be the delay is too short.

Also, you don't need the last
Code:
        else 
        { 
            return Plugin_Continue; 
        }
EDIT:

IIRC, its better to pass the userid though the timers, not the clientid. Can someone clear that up?
__________________
toazron1 is offline
Send a message via AIM to toazron1
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 02-02-2011 , 15:43   Re: Instaspawn being picky? (TF2)
Reply With Quote #4

Quote:
Originally Posted by toazron1 View Post
IIRC, its better to pass the userid though the timers, not the clientid. Can someone clear that up?

Yep.

GetClientUserId() - Pass into the timer
GetClientOfUserId - Retrieve from the timer and check it's not 0 (maybe?) or IsClientInGame().
__________________
Silvers is offline
Eaglebird
Junior Member
Join Date: Sep 2007
Old 02-02-2011 , 16:37   Re: Instaspawn being picky? (TF2)
Reply With Quote #5

TF2_RespawnPlayer requires the player index, though. Testing on a listenserver wouldn't show the difference since for the first player (myself), the RPI == userid.

What's the difference in what I pass to the timer? They're both integers, no?

Quote:
Originally Posted by toazron1 View Post
Try increasing the timer for the respawn, it could be the delay is too short.
I've seen this same implementation in other respawn plugins. They'd probably go lower if the timers had such accuracy, but I haven't had a problem with this until just recently. If it is, in fact, the delay being problematic, what would cause it to work normally in the past but only recently start acting up?

Last edited by Eaglebird; 02-02-2011 at 16:40.
Eaglebird is offline
Send a message via AIM to Eaglebird Send a message via MSN to Eaglebird Send a message via Skype™ to Eaglebird
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 02-02-2011 , 17:01   Re: Instaspawn being picky? (TF2)
Reply With Quote #6

If someone leaves before the timer has executed, and somebody else joins, they could have the same client ID and therefore you would be affecting somebody else. But if you pass the user ID into the timer, this is incremented everytime someone joins, so passing this into the timer ensures you're affecting the correct client.
__________________
Silvers is offline
Eaglebird
Junior Member
Join Date: Sep 2007
Old 02-02-2011 , 18:34   Re: Instaspawn being picky? (TF2)
Reply With Quote #7

Quote:
Originally Posted by Silvers View Post
If someone leaves before the timer has executed, and somebody else joins, they could have the same client ID and therefore you would be affecting somebody else. But if you pass the user ID into the timer, this is incremented everytime someone joins, so passing this into the timer ensures you're affecting the correct client.
So I may as well call IsClientInGame() inside the timer, as I was before. Still, the timer shouldn't be affected by either, but rather TF2_RespawnPlayer(). Is an invalid player index supplied to TF2_RespawnPlayer going to cause the timer to not be called for other players?
Eaglebird is offline
Send a message via AIM to Eaglebird Send a message via MSN to Eaglebird Send a message via Skype™ to Eaglebird
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 02-02-2011 , 19:22   Re: Instaspawn being picky? (TF2)
Reply With Quote #8

PHP Code:
public Action:Event_PlayerDeath(Handle:deathevent, const String:name[], bool:dontBroadcast) {
    if (!
Instaspawn)
    {
        return 
Plugin_Continue;
    }
    else
    {
        new 
bool:FakeDeath GetEventBool(deathevent"feign_death");
        new 
VictimId GetEventInt(deathevent"userid");
        
VictimIndex GetClientOfUserId(VictimId);
        if ((
IsClientInGame(VictimIndex)) && (!FakeDeath))
        {
            
CreateTimer(0.1Timer_RespawnVictimId);
        }
        else
        {
            return 
Plugin_Continue;
        }
    }
    return 
Plugin_Continue;
}


public 
Action:Timer_Respawn(Handle:timerany:client)
{
    
client GetClientOfUserId(client);
    if( 
IsClientInGame(client) )
        
TF2_RespawnPlayer(client);

No it won't affect other players if it fails for one, but you should just do the above and it won't fail.

Not sure why it wouldn't work every time as I don't write plugins for TF2.



EDIT: Just noticed this is why maybe: you should use client instead of VictimIndex, since that was not declared within the timer:

Replace:
public Action:Timer_Respawn(Handle:timer, any:client)
{
TF2_RespawnPlayer(VictimIndex);
}

With:
public Action:Timer_Respawn(Handle:timer, any:client)
{
TF2_RespawnPlayer(
client);
}
__________________

Last edited by Silvers; 02-02-2011 at 20:14.
Silvers is offline
Eaglebird
Junior Member
Join Date: Sep 2007
Old 02-02-2011 , 20:06   Re: Instaspawn being picky? (TF2)
Reply With Quote #9

Except VictimIndex is being passed to the timer, which is what the third parameter is in CreateTimer(). If I change the timer's "any:client" to "any:VictimIndex", I get a compilation error about variable shadowing.

Also notice that VictimIndex is not created with new in that event, which is because it is created before any of the 'code'. If I use VictimId as it is now, I get a compilation error that VictimId is undefined, since it is created within the scope of the event. Further, how does the timer know that the client specified is the client we're trying to respawn, and not the server/sourcemod calling the timer?
Eaglebird is offline
Send a message via AIM to Eaglebird Send a message via MSN to Eaglebird Send a message via Skype™ to Eaglebird
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 02-02-2011 , 20:14   Re: Instaspawn being picky? (TF2)
Reply With Quote #10

From my understand the variable within the timer any:... and the variable VictimIndex are not shared.

I don't understand your second question. Please view the post above, I have edited it. It was supposed to be client = GetClientOfUserId(client)
__________________
Silvers is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 17:50.


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