AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   index out of bounds (https://forums.alliedmods.net/showthread.php?t=144563)

fmfs10 12-05-2010 10:14

index out of bounds
 
Hello! I'm trying to do a kz plugin for my self, but i'm having a problem with the timer...

Quote:

public cmd_ShowTime(id) {
if (!is_user_alive(id))
return PLUGIN_HANDLED

if(!g_started[id]) {
ColorChat(id, GREEN, "[KZ] ^1MESSAGE")
return PLUGIN_HANDLED
}

if (ShowTime[id]) {
ShowTime[id] = false
ColorChat(id, GREEN, "[KZ] ^1MESSAGE")
remove_task(id+TASK_ID_SHOWTIME)
return PLUGIN_HANDLED
}

set_task(1.0, "DisplayTime", id+TASK_ID_SHOWTIME, _, _, "b")
ColorChat(id, GREEN, "[KZ] ^1MESSAGE")

return PLUGIN_CONTINUE
}

public DisplayTime(id) {
new tempo[12]

seconds2[id]++
if(seconds2[id] >= 10) {
seconds2[id] = 0
seconds1[id]++
}

if(seconds1[id] >= 6) {
seconds1[id] = 0
minutes2[id]++
}

if(minutes2[id] >= 10) {
minutes2[id] = 0
minutes1[id]++
}

formatex(tempo, 11, "%s%s:%s%s", minutes1[id], minutes2[id], seconds1[id], seconds2[id])

//The location is just for testing
set_hudmessage( 20, 40, 7, 0.9, -1.0, 0, 0.0, 2.0, 0.0, 1.0, -1);
ShowSyncHudMsg(id, tempohud, tempo)


}
I'm receiving the error index out of bounds...
What is happening?

Oh, and there is a better way to do what I want?

Bugsy 12-05-2010 10:32

Re: index out of bounds
 
DisplayTime function is called via set_task with player id + TASK_ID_SHOWTIME as the task id. Then in your DisplayTime function you never subtract the TASK_ID_SHOWTIME to get the player id

PHP Code:

public DisplayTimeid )
{
    
id -= TASK_ID_SHOWTIME;
    
//.... 


fmfs10 12-05-2010 10:46

Re: index out of bounds
 
OH IT WORKED! THANKS!

I needed to change %s to %d too...


Can you say to me if there is a better way to do this?

And there is a way to remove the c4 timer and make the clock icon appear before the timer?


All times are GMT -4. The time now is 11:28.

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