SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 21/09/2018, 06:58 PM   #1
wallee
Huge Clucker
 
Join Date: Jan 2017
Posts: 307
Reputation: 40
Question y_timers question

Is it better to have 1 "task" of 1000ms with a foreach loop inside doing various checks or having a lot of "timers" for individual players? I have a lot of things and there could be a lot ... like really a lot (maybe up to a thousand timers at once). They will contain very little code though, like a variable reset.

So what would be better?
wallee is offline   Reply With Quote
Old 21/09/2018, 08:18 PM   #2
kingmk
Big Clucker
 
kingmk's Avatar
 
Join Date: Sep 2014
Location: Romania
Posts: 104
Reputation: 22
Default Re: y_timers question

Yes, 1 "task" of 1000ms it's better and safe.

Code:
task GlobalTimer[1000]()
{	
       foreach(new i : Player)
       {
              //All functions for player who need looped. (Ex: OnPlayerIsInVehicle(i); -> Show player vehicle info like KM/h )
       }
       //All basic functions who need looped. (Ex UpdateTime(); )
}
__________________
Follow me on YouTube:
Click
If u need help don't hesitate to PM me.
© X-BURN COMMUNITY

kingmk is offline   Reply With Quote
Old 21/09/2018, 09:34 PM   #3
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,310
Reputation: 3191
Default Re: y_timers question

Use ptask for players.
Y_Less is offline   Reply With Quote
Old 22/09/2018, 05:32 PM   #4
wallee
Huge Clucker
 
Join Date: Jan 2017
Posts: 307
Reputation: 40
Default Re: y_timers question

is there a way to hook ptasks? i tried this:

Code:
ptask Justatimer[1000](playerid)
{
	printf("Original code.");
}

hook:Justatimer(playerid)
{
	printf("Hooked code.")
}
and i get this when compiling:

Code:
warning 203: symbol is never used: "Justatimer@007"
the timer still runs, but the hooked code doesn't
wallee is offline   Reply With Quote
Old 22/09/2018, 05:41 PM   #5
VVWVV
Big Clucker
 
Join Date: Jun 2015
Posts: 144
Reputation: 70
Default Re: y_timers question

Quote:
Originally Posted by wallee View Post
is there a way to hook ptasks? i tried this:

Code:
ptask Justatimer[1000](playerid)
{
	printf("Original code.");
}

hook:Justatimer(playerid)
{
	printf("Hooked code.")
}
and i get this when compiling:

Code:
warning 203: symbol is never used: "Justatimer@007"
the timer still runs, but the hooked code doesn't
This is not implemented yet.
VVWVV is offline   Reply With Quote
Old 22/09/2018, 06:44 PM   #6
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,310
Reputation: 3191
Default Re: y_timers question

Yes, but there are several issues with your code:

1) The syntax for hooks is either Hook:function or hook function. You wrote hook:function which is neither, thatís why you got that warning.

2) ptasks use some under-the-hood name mangling. So the name of the public isnít actually Justatimer but @_yTJustatimer (the prefix makes searching the AMX for ptasks easy, but donít worry about that).

So putting these together, we get:

Code:
hook @_yTJustatimer(playerid)
{
}
However, since @_yT is technically an internal implementation detail it might change. In fact, Iíve just checked the code and there are several different versions. So it is either that or this:

Code:
hook Justatimer(playerid)
{
}
I donít know which version of YSI you are using. This isnít stable because it isnít an external API (so isnít guaranteed to be stable). Just try one till one works.
Y_Less is offline   Reply With Quote
Old 22/09/2018, 06:54 PM   #7
VVWVV
Big Clucker
 
Join Date: Jun 2015
Posts: 144
Reputation: 70
Default Re: y_timers question

Y_Less, does the library have an implementation for hooked timers?

Example:
pawn Code:
ptask foo[1000](playerid) { /*code*/ }
hook ptask foo[1000](playerid) { /*code*/ }
VVWVV is offline   Reply With Quote
Old 22/09/2018, 11:42 PM   #8
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,310
Reputation: 3191
Default Re: y_timers question

No, I literally just wrote how to do that...
Y_Less is offline   Reply With Quote
Old 23/09/2018, 12:08 AM   #9
wallee
Huge Clucker
 
Join Date: Jan 2017
Posts: 307
Reputation: 40
Default Re: y_timers question

This hangs the server:

Code:
hook @_yTJustatimer(playerid)
{
}
This works perfectly:

Code:
hook Justatimer(playerid)
{
}
Can i depend on the second thing or will it change?

(i'm currently using YSI4)
wallee is offline   Reply With Quote
Old 23/09/2018, 12:15 AM   #10
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,310
Reputation: 3191
Default Re: y_timers question

You can't depend on it, no... Also, I know why it hangs, might need to fix that.
Y_Less is offline   Reply With Quote
Reply

Thread Tools
Display Modes

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
A question about y_timers RedGun2015 Scripting Help 1 10/08/2017 11:43 PM
Help y_timers Raefal Scripting Help 1 21/06/2014 11:45 AM
Y_timers help Dusan01 Scripting Help 3 12/05/2014 01:19 PM
About y_timers SnL Scripting Help 6 15/02/2014 11:46 PM
YSI\y_timers zDivine Scripting Help 5 19/04/2013 10:38 AM


All times are GMT. The time now is 01:32 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.