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

[ANY] Check if player is a different one


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ekshon
Junior Member
Join Date: Nov 2020
Old 01-06-2021 , 23:51   [ANY] Check if player is a different one
Reply With Quote #1

Let's say I'm creating a timer.

Code:
CreateTimer(20.0, OnTimer, client);
player [1] disconnects, but another one connects straight after, asserting id [1]

Code:
public Action OnTimer(Handle timer, int client)
{
	if (!IsValidEntity(client)) return Plugin_Stop;

	//do something with the player
}
How to check if this is another player already? I know there's a way to check his entity reference, but in this case I have to create DataPack with client+reference every time I use Timers?
Is there a better way?
ekshon is offline
FAQU
Member
Join Date: Sep 2020
Location: Romania
Old 01-07-2021 , 00:20   Re: [ANY] Check if player is a different one
Reply With Quote #2

You could create a timer for each player, and kill the timer when the player disconnects.

PHP Code:
Handle hTimer[MAXPLAYERS 1];

public 
void OnClientPutInServer(int client)
{
    
hTimer[client] = CreateTimer(20.0Timer_Somethingclient); // Add TIMER_REPEAT flag if you want the timer to repeat
}

public 
void OnClientDisconnect(int client)
{
    
delete hTimer[client];
}

public 
Action Timer_Something(Handle timerint client)
{
    
// do stuff


Last edited by FAQU; 01-07-2021 at 00:20.
FAQU is offline
ekshon
Junior Member
Join Date: Nov 2020
Old 01-07-2021 , 00:31   Re: [ANY] Check if player is a different one
Reply With Quote #3

Quote:
Originally Posted by FAQU View Post
You could create a timer for each player, and kill the timer when the player disconnects.

PHP Code:
Handle hTimer[MAXPLAYERS 1];

public 
void OnClientPutInServer(int client)
{
    
hTimer[client] = CreateTimer(20.0Timer_Somethingclient); // Add TIMER_REPEAT flag if you want the timer to repeat
}

public 
void OnClientDisconnect(int client)
{
    
delete hTimer[client];
}

public 
Action Timer_Something(Handle timerint client)
{
    
// do stuff

Hm, that's a good option, but what if players are able to call multiple timers? That would be a mess.
ekshon is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: The Netherlands
Old 01-07-2021 , 04:16   Re: [ANY] Check if player is a different one
Reply With Quote #4

See the second example on https://wiki.alliedmods.net/Timers_(...#Simple_Values.

You want to pass the userid or client serial to the callback, which is unique for each client.
__________________
Advertisements | REST in Pawn - HTTP client for JSON REST APIs
Please do not PM me with questions. Post in the plugin thread.
DJ Tsunami is offline
ekshon
Junior Member
Join Date: Nov 2020
Old 01-07-2021 , 05:55   Re: [ANY] Check if player is a different one
Reply With Quote #5

Quote:
Originally Posted by DJ Tsunami View Post
See the second example on https://wiki.alliedmods.net/Timers_(...#Simple_Values.

You want to pass the userid or client serial to the callback, which is unique for each client.
Wow thanks! I've missed that part was in a tutorial.
ekshon 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 15:10.


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