AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [Resolved] Code works on random players only? (https://forums.alliedmods.net/showthread.php?t=47933)

hlstriker 11-30-2006 10:34

[Resolved] Code works on random players only?
 
Hey again everyone, another problem @_@. The code i'm about to post below will only work on some players. It is supposed to work for everyone that touches it.

Code:
public toucherStartFunc(pToucher, pTouched) {     new id = pTouched;     if(!timerUse[id]) {         client_cmd(id, "speak fvox/boop");         hour[id] = 0.0;         minute[id] = 0.0;         second[id] = 1.0;         set_hudmessage(200, 100, 0, -1.0, -5.0, 0, 0.0, 500000.9, 0.0, 0.0, 4);         show_hudmessage(id, "00:00:01");         set_task(1.0, "timerCount", 1, "", 0, "b");     }     timerUse[id] = true;         return PLUGIN_CONTINUE; } public timerCount(id) {     second[id] += 1.0         if(second[id] == 60.0) {         second[id] = 0.0         minute[id] += 1.0     }         if(minute[id] == 60.0) {         minute[id] = 0.0         hour[id] += 1.0     }         new strHour[3];     new strMinute[3];     new strSecond[3];         float_to_str(hour[id], strHour, 2);     float_to_str(minute[id], strMinute, 2);     float_to_str(second[id], strSecond, 2);         switch(hour[id]) {         case 0.0: strHour = "00";         case 1.0: strHour = "01";         case 2.0: strHour = "02";         case 3.0: strHour = "03";         case 4.0: strHour = "04";         case 5.0: strHour = "05";         case 6.0: strHour = "06";         case 7.0: strHour = "07";         case 8.0: strHour = "08";         case 9.0: strHour = "09";     }         switch(minute[id]) {         case 0.0: strMinute = "00";         case 1.0: strMinute = "01";         case 2.0: strMinute = "02";         case 3.0: strMinute = "03";         case 4.0: strMinute = "04";         case 5.0: strMinute = "05";         case 6.0: strMinute = "06";         case 7.0: strMinute = "07";         case 8.0: strMinute = "08";         case 9.0: strMinute = "09";     }         switch(second[id]) {         case 0.0: strSecond = "00";         case 1.0: strSecond = "01";         case 2.0: strSecond = "02";         case 3.0: strSecond = "03";         case 4.0: strSecond = "04";         case 5.0: strSecond = "05";         case 6.0: strSecond = "06";         case 7.0: strSecond = "07";         case 8.0: strSecond = "08";         case 9.0: strSecond = "09";     }         set_hudmessage(200, 100, 0, -1.0, -5.0, 0, 0.0, 500000.9, 0.0, 0.0, 4);     show_hudmessage(id, "%s:%s:%s", strHour, strMinute, strSecond);         return PLUGIN_CONTINUE; }

Please help me fix this :)

jim_yang 11-30-2006 11:03

Re: Code works on random players only?
 
public timerCount(id)this id is a task id
public timerCount(taskid)
so you set_task(1.0, "timerCount", 1, "", 0, "b")
only player #1 will take effect

hlstriker 11-30-2006 12:05

Re: Code works on random players only?
 
Now all the ids in my timerCount() don't work, how do I pass the id down there?

jim_yang 11-30-2006 12:09

Re: Code works on random players only?
 
set_task(1.0, "timerCount", id, "", 0, "b")

jim_yang 11-30-2006 12:15

Re: Code works on random players only?
 
why not use integar
Code:
public timerCount(id) {     second[id] ++     new h,m,s     h = second[id] / 3600     m = (second[id] % 3600) / 60     s = (second[id] % 3600) % 60     set_hudmessage(200, 100, 0, -1.0, -5.0, 0, 0.0, 500000.9, 0.0, 0.0, 4);     show_hudmessage(id, "%02d:%02d:%02d", h,m,s);         return PLUGIN_CONTINUE; }

hlstriker 11-30-2006 12:22

Re: Code works on random players only?
 
I didn't know you could put stuff in between the %s %d %f. Thanks that saves tons of time!

Also... about the set_task i'm still a bit confused. You said the 3rd argument is to pass variables, and others tell me its the set the tasks id.

jim_yang 11-30-2006 12:25

Re: Code works on random players only?
 
set_task(1.0,"function",taskid)
then it pass taskid to your function
public function(taskid)
{
}

id is just a name. you can name it whatever you like
public client_connect(player)
{
}

hlstriker 11-30-2006 12:32

Re: Code works on random players only?
 
Ok just one more question about the format you made...
Code:
show_hudmessage(id, "%02d:%02d:%02d", h,m,s);

Where it is "%02d" what does that 2 represent?

jim_yang 11-30-2006 12:35

Re: Code works on random players only?
 
1-9 print 01-09
10-99 print 10-99


All times are GMT -4. The time now is 07:01.

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