AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   set task doesnt want to work. (https://forums.alliedmods.net/showthread.php?t=25856)

Willmaker 03-21-2006 23:43

set task doesnt want to work.
 
Im having trouble with this plugin. I want it to check a players time spent on a server. Now for the sake of testing, that value is 15 seconds.

When I use a set_task to check a players time every second, it doesnt do anything when a players time gets to 15 seconds. But if I use client_PreThink instead, it works. Now I would use client_prethink, but it executed the code 40-50 times, which I dont want, as I want it to play a sound also and it gets quite loud.

So I wanted to know why client_prethink works in this case, but set_task doesnt.


Edit - Problem solved. Attachments removed, no longer needed.

teame06 03-22-2006 00:03

Code:
public check_time(){ //If prethink is used here it works, but set_task doesnt.     new players[32], count     get_players( players[32], count, "c") // Skip bots         new i, name[32], id, playtime     for(i = 0; i < count; i++)     {         name[0] = 0         id = players[i]                 get_user_name(id, name, 17)         playtime = get_user_time(id)         store_time = playtime + connecttime[id]         if(store_time == 15) {             client_print(0, print_chat,"If you are seeing this, then it is working.")         }     } }

When you do task like that for all players, You have do something like I did above.

Willmaker 03-22-2006 00:10

Thank you so much. +karma on the way.

But I did need to change
Code:
get_players( players[32], count, "c") // Skip bots
to
Code:
get_players( players, count, "c") // Skip bots

v3x 03-22-2006 00:11

tsk tsk teame06 :P

SubStream 03-22-2006 09:31

--Edited--

Willmaker 03-22-2006 09:37

connecttime[id] is a global variable which is an integer, stored in a mysql database. Basically, when a player plays on a server and leaves, the amount of time they played would be stored as connecttime

SubStream 03-22-2006 10:35

--Edited--

Rixorster 03-22-2006 13:46

IDK about that, but here's another way:
Code:
public plugin_init() {     set_task(15.0,"textloop") } public textloop(id) {     client_print(0, print_chat,"If you are seeing this, then it is working.") }
;P (it works, trust me, now +karma me ;D )

akysiev 03-22-2006 13:50

SubStream: Yes, what you wrote should work fine. Although instead of storing it as a global var, you could use modulo as well :)

Really though, set_task was made for this type of stuff.

Oh, and Rix, I don't think that's what he's looking for. He want to track user time, not display that message to everyone every 15 seconds. Furthermore, you have id as a parameter in the textloop function while set_task does not pass along an integer parameter but rather an array parameter and the one you provided does not pass any parameters at all. Hell, it doesn't even loop like the name suggests it would.

[ --<-@ ] Black Rose 03-22-2006 13:52

it wouldn't loop. also no id, so why do you have id defined in textloop?
Code:
public plugin_init() {     set_task(15.0,"textloop", 0, _, _, "b") } public textloop() {     client_print(0, print_chat,"If you are seeing this, then it is working.") }


All times are GMT -4. The time now is 16:32.

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