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

Handle:timer not working for all players?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Fastmancz
Senior Member
Join Date: Jul 2013
Location: Czech Republic
Old 01-23-2015 , 17:48   Handle:timer not working for all players?
Reply With Quote #1

Hi,

I use timer for Welcome message.
PHP Code:
public OnPluginStart()
{
CreateTimer(5.0Welcome);
}

public 
Action:Welcome(Handle:timerany:client)
{
  new 
String:name[32];
  
GetClientName(clientname32);
  
PrintToChat(client"Welcome on server %s"name);

Problem:
[SM] Native "PrintToChat" reported: Client index 0 is invalid.

Where is problem? I use Handle:timer on other plugin and problem is same.

Last edited by Fastmancz; 01-23-2015 at 17:48.
Fastmancz is offline
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 01-23-2015 , 18:10   Re: Handle:timer not working for all players?
Reply With Quote #2

Take a look at the definition of the CreateTimer function.
Its third parameter is passed to the callback and it defaults to INVALID_HANDLE which is defines as 0.
Since you didn't pass a third parameter to CreateTimer, your callback will receive the default value of 0.
With that out the way, you'll probably understand that you code cannot work like that because there is no client index you pass.
Please note that you should not use client id's for timers, use a client serial or user id instead. The wiki has an example (the second one) of what you want to do.
__________________

Last edited by Impact123; 01-23-2015 at 18:29.
Impact123 is offline
RedSword
SourceMod Plugin Approver
Join Date: Mar 2006
Location: Quebec, Canada
Old 01-24-2015 , 17:35   Re: Handle:timer not working for all players?
Reply With Quote #3

You also might want to either launch the timer OnClientConnected and pass the client user id / client serial id (as said by Impact123) and revert it back to a client Id in the Timer callback function, or simply loop from 1 to MaxClients if you really want it to start OnPluginStart (depending on what you really want to do).
__________________
My plugins :
Red Maze
Afk Bomb
RAWR (per player/rounds Awp Restrict.)
Kill Assist
Be Medic

You can also Donate if you appreciate my work
RedSword 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 05:30.


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