PDA

View Full Version : Delay execution of code WITHOUT createtimer


maningrey
03-14-2015, 01:01
Hello

As the title says I've been looking for a way to delay the execution of my code for 500 milliseconds. However the only method I know of is createtimer which I cannot use for this specific task.

So does anyone know of another way to delay the code?

Many thanks

RedSword
03-14-2015, 01:07
I don't really see how you could not use a timer; but you can also use GetGameTime (https://sm.alliedmods.net/api/index.php?fastload=show&id=100&) which returns the game time elapsed since map start. Just call it when your code is reach and set it in a variable and in OnGameFrame when GetGameTime > your var + 0.5 you should be able to exec your code.

But I'm not sure about not using timers; posting code would help.

maningrey
03-14-2015, 01:26
I don't really see how you could not use a timer; but you can also use GetGameTime (https://sm.alliedmods.net/api/index.php?fastload=show&id=100&) which returns the game time elapsed since map start. Just call it when your code is reach and set it in a variable and in OnGameFrame when GetGameTime > your var + 0.5 you should be able to exec your code.

But I'm not sure about not using timers; posting code would help.

Hello, thank you for the reply. The plugin is called Timer-mapzones by Zipcore and is quite large. So I'll post the part I'm trying to delay then the entire plugin in pastebin if thats ok?

if (g_mapZones[zone][Type] == ZtReset)
{
Timer_Reset(client);
}
else if (g_mapZones[zone][Type] == ZtStart)
{
if(!g_Settings[NoblockEnable])
SetPush(client);

if(Timer_GetTrack(client) == TRACK_BONUS)
{
if(GetEntProp(client, Prop_Send, "movetype", 1) == 8)
{
Timer_Stop(client, false);
}

else
{
g_iClientLastTrackZone[client] = zone;

if (Timer_Stop(client, false))
{
new bool:enabled = false;
new jumps = 0;
new Float:time;
new fpsmax;

if (Timer_GetClientTimer(client, enabled, time, jumps, fpsmax))
{
new difficulty = 0;
if (g_timerPhysics)
difficulty = Timer_GetStyle(client);

/// NEED DELAY HERE
/// NEED DELAY HERE
/// NEED DELAY HERE
/// NEED DELAY HERE

Timer_FinishRound(client, g_currentMap, time, jumps, difficulty, fpsmax, TRACK_BONUS);
}
}
}
}

I did try to use createtimer with datapacks and the plugin compiled, but I got array out of bounds when Timer_FinishRound fired.

Here is the full code in it's original form

https://pastebin.com/Bz5ewBim

Thank you for the help

RedSword
03-14-2015, 01:54
Could you show what you tried ? (the code with the datapacks as it didn't work; as well as where exactly it did crash)

I found 2.3.0.4.NOT-CSGO; which seems to differ by only 15 lines. You didn't pastebin the full code as you said you did (Timer_FinishRound cannot be found in that pastebin; it is in another file).

I'm pretty sure I would use a data pack where you did say "NEED DELAY HERE", put Timer_FinishRound in another function and have that function be called by the timer. Did you rewind the datapack ?

maningrey
03-14-2015, 02:24
Could you show what you tried ? (the code with the datapacks as it didn't work; as well as where exactly it did crash)

I found 2.3.0.4.NOT-CSGO; which seems to differ by only 15 lines. You didn't pastebin the full code as you said you did (Timer_FinishRound cannot be found in that pastebin; it is in another file).

I'm pretty sure I would use a data pack where you did say "NEED DELAY HERE", put Timer_FinishRound in another function and have that function be called by the timer. Did you rewind the datapack ?

Thank you for the reply, here is my code

if(Timer_GetTrack(client) == TRACK_BONUS)
{
if(GetEntProp(client, Prop_Send, "movetype", 1) == 8)
{
Timer_Stop(client, false);
}

else
{
g_iClientLastTrackZone[client] = zone;

if (Timer_Stop(client, false))
{
new bool:enabled = false;
new jumps = 0;
new Float:time;
new fpsmax;

if (Timer_GetClientTimer(client, enabled, time, jumps, fpsmax))
{
new difficulty = 0;
if (g_timerPhysics)
difficulty = Timer_GetStyle(client);

new Handle:timerpack;
CreateDataTimer(0.5, Timer_FinishBonusDelay, timerpack, TIMER_FLAG_NO_MAPCHANGE);

WritePackCell(timerpack, client);
WritePackCell(timerpack, time);
WritePackCell(timerpack, jumps);
WritePackCell(timerpack, difficulty);
WritePackCell(timerpack, fpsmax);

Timer_FinishRound(client, g_currentMap, time, jumps, difficulty, fpsmax, TRACK_BONUS);
}
}
}
}

public Action:Timer_FinishBonusDelay(Handle:timer, Handle:timerpack)
{

new client;
new time;
new jumps;
new difficulty;
new fpsmax;

ResetPack(timerpack);

client = ReadPackCell(timerpack);
time = ReadPackCell(timerpack);
jumps = ReadPackCell(timerpack);
difficulty = ReadPackCell(timerpack);
fpsmax = ReadPackCell(timerpack);

if(IsClientConnected(client))
{
Timer_FinishRound(client, g_currentMap, time, jumps, difficulty, fpsmax, TRACK_BONUS);
}
}

I would get an array is out of bounds "client" if timer_finishround fired. I wasn't able to figure out why.

RedSword
03-14-2015, 02:54
What line exactly (the out of bounds) ?

Also you could PrintToServer the value of "client" just before the array out-of-bounds line; that might help you.

Also I don't know the plugin really well, but I fear that something is modifying a variable while that timer elapses.

Chdata
03-14-2015, 03:28
Here's exactly what you described in the op. Not sure if it's actually what you're trying to do though.

https://forums.alliedmods.net/showthread.php?t=257587

edit: It's not, do what redsword says.

DeathChaos25
03-14-2015, 12:11
I think it's most likely because you forgot to validate the client?

if (client > 0 && client < MAXPLAYERS)

LambdaLambda
03-14-2015, 23:34
And change client to userid when you're passing it with timers.
https://sm.alliedmods.net/api/index.php?fastload=show&id=402&

Yes, it is pretty much unlikely that player will quit in 0.5secs, but still.

Btw, why you're calling Timer_FinishRound() twice?

maningrey
03-15-2015, 12:21
And change client to userid when you're passing it with timers.
https://sm.alliedmods.net/api/index.php?fastload=show&id=402&

Yes, it is pretty much unlikely that player will quit in 0.5secs, but still.

Btw, why you're calling Timer_FinishRound() twice?

Error, I shortly removed it when two records were spammed. Thank you I got it working :)

LambdaLambda
03-15-2015, 15:12
I've got no idea what you've just said, but I'm glad you handled that. :D