Raised This Month: $ Target: $400
 0% 

Loop while player is alive


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Unreal1
AlliedModders Donor
Join Date: Dec 2010
Old 03-10-2012 , 22:29   Loop while player is alive
Reply With Quote #1

How would I create a loop that executes a command every x amount of seconds while the player is alive.
Unreal1 is offline
thetwistedpanda
Good Little Panda
Join Date: Sep 2008
Old 03-10-2012 , 22:37   Re: Loop while player is alive
Reply With Quote #2

How about CreateTimer(1.0, DatTimer, client, TIMER_REPEAT) and keep a Float:g_fTimerCount[MAXPLAYERS + 1] increasing by 1.0 each iteration of the timer. If they're alive, increase g_fTimerCount. If they're dead, set g_fTimerCount back to 0.0 and wait for them to spawn. If g_fTimerCount >= CommandDelay, g_fTimerCount = 0, IssueCommand. Pesudodrunkocodo.
__________________
thetwistedpanda is offline
Unreal1
AlliedModders Donor
Join Date: Dec 2010
Old 03-10-2012 , 23:52   Re: Loop while player is alive
Reply With Quote #3

Quote:
Originally Posted by thetwistedpanda View Post
How about CreateTimer(1.0, DatTimer, client, TIMER_REPEAT) and keep a Float:g_fTimerCount[MAXPLAYERS + 1] increasing by 1.0 each iteration of the timer. If they're alive, increase g_fTimerCount. If they're dead, set g_fTimerCount back to 0.0 and wait for them to spawn. If g_fTimerCount >= CommandDelay, g_fTimerCount = 0, IssueCommand. Pesudodrunkocodo.
Can you write this out in code?

For example, if I already have:

Code:
public Event_PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast) {
		new client = GetClientOfUserId(GetEventInt(event, "userid"))

//Create the timer stuff here

}

public Action:whattodo(Handle:timer, any:user_index)
{
//Does whatever
}
What do I need to put within the Even_PlayerSpawn meathod so that it executes whattodo on the client every few seconds.

Last edited by Unreal1; 03-10-2012 at 23:53.
Unreal1 is offline
necavi
Veteran Member
Join Date: Sep 2010
Old 03-11-2012 , 00:00   Re: Loop while player is alive
Reply With Quote #4

PHP Code:
public Event_PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast) {
        new 
client GetClientOfUserId(GetEventInt(event"userid"))
        
CreateTimer(1.0,whattodo,client,TIMER_REPEAT);
}

public 
Action:whattodo(Handle:timerany:client)
{
    if(
IsPlayerAlive(client))
    {
        
//dostuff
    
} else {
        
CloseHandle(whattodo);
    }

Something roughly like this would do.
necavi is offline
mcpan313
Senior Member
Join Date: Mar 2010
Old 03-11-2012 , 06:05   Re: Loop while player is alive
Reply With Quote #5

Quote:
Originally Posted by necavi View Post
PHP Code:
public Event_PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast) {
        new 
client GetClientOfUserId(GetEventInt(event"userid"))
        
CreateTimer(1.0,whattodo,client,TIMER_REPEAT);
}

public 
Action:whattodo(Handle:timerany:client)
{
    if(
IsPlayerAlive(client))
    {
        
//dostuff
    
} else {
        
CloseHandle(whattodo);
    }

Something roughly like this would do.
CloseHandle(whattodo); ? why not use return Plugin_Stop;
__________________
sorry, for my poor english.
mcpan313 is offline
Send a message via MSN to mcpan313
necavi
Veteran Member
Join Date: Sep 2010
Old 03-11-2012 , 06:12   Re: Loop while player is alive
Reply With Quote #6

Because I don't tend to write many timers using TIMER_REPEAT, and while I considered return Plugin_Stop, I wasn't entirely sure it worked in that instance.
necavi is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 03-11-2012 , 08:12   Re: Loop while player is alive
Reply With Quote #7

I suggest use global Handle, create timer using Handle array index by client index... (what I writing here ?)

Anyway.

*edit
dam, I noticed if in timer userid return 0, it empty that array index.....
Then let use only client indexs
Spoiler


Like wiki site

Last edited by Bacardi; 03-11-2012 at 08:56.
Bacardi 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 01:34.


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