Timer Delay without using Callbacks
#1

Basically I want the following code to work without having to use " SetTimer() as the delay. Is there another way to use delays to pause code from executing but remain inside the same function?

Код:
{
	SendClientMessage(playerid, 0xF1CB45FF, "Beginning Operation");
	SetPlayerPos(playerid, 268.5968,1857.6873,9.8133); // Operating Table
	ApplyAnimation(playerid,"SUNBATHE ","Lay_Bac_in",4.0,1,1,1,1,1);
	SetTimer("OperateDelay", 10000, true);
	ApplyAnimation(playerid,"SUNBATHE ","Lay_Bac_out",4.0,1,1,1,1,1);
}
So something like :

Код:
{
	SendClientMessage(playerid, 0xF1CB45FF, "Beginning Operation");
	SetPlayerPos(playerid, 268.5968,1857.6873,9.8133); // Operating Table
	ApplyAnimation(playerid,"SUNBATHE ","Lay_Bac_in",4.0,1,1,1,1,1);
	Delay(10000);
	ApplyAnimation(playerid,"SUNBATHE ","Lay_Bac_out",4.0,1,1,1,1,1);
}
I find it hard to believe you can't pause code contained inside of a function doing something like :

Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
	if (strcmp("/operate", cmdtext, true, 10) == 0)
	{
	SendClientMessage(playerid, 0xF1CB45FF, "Beginning Operation");
	SetPlayerPos(playerid, 268.5968,1857.6873,9.8133); // Operating Table
	ApplyAnimation(playerid,"SUNBATHE ","Lay_Bac_in",4.0,1,1,1,1,1);
	Delay(10000);
	ApplyAnimation(playerid,"SUNBATHE ","Lay_Bac_out",4.0,1,1,1,1,1);
	SetPlayerHealth(playerid,100);
	SendClientMessage(playerid, 0xF1CB45FF, "You're all Patched Up!!"); 
       return 1;
	}
return 0;
}
If anyone knows an alternative method to using the SetTimer() please let me know as I've tried searching for the words Delay and Timer and Time Delay and can't find anything. I really thought this would be simple to find.

AFAIK using wait() will stop the global code .. aka.. EVERYTHING and not just the local code if i'm wrong then an example of how to get what i need to work would be sooooo appreciated. this is kinda my last shot at finding a way.
Reply
#2

PAWN is single threaded, so a timer is really the only viable option other than pausing your entire script for 10 seconds.
Reply
#3

hmm Thanks for the answer.. i guess I wouldn't mind using the timer if it wern't for the fact that I want to teleport a player elsewhere then have the rest of the code only affect the player teleported.. but can't get it to recognise that the player I just teleported is still the same player that needs to have the rest of the actions applied to it so :

Код:
public OperateDelay (playerid)
{	
	ApplyAnimation(playerid,"SUNBATHE ","Lay_Bac_out",4.0,1,1,1,1,1);
	SetPlayerHealth(playerid,100);
	SendClientMessage(playerid, 0xF1CB45FF, "You're all Patched Up!!"); 
        return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
	if (strcmp("/operate", cmdtext, true, 10) == 0)
	{
	SendClientMessage(playerid, 0xF1CB45FF, "Beginning Operation");
	SetPlayerPos(playerid, 268.5968,1857.6873,9.8133); // Operating Table
	ApplyAnimation(playerid,"SUNBATHE ","Lay_Bac_in",4.0,1,1,1,1,1);
	SetTimer("OperateDelay", 10000, true);
        return 1;
	}
return 0;
}
using that code it's not making my player stand back up after the 10 second timer delay and I know its probably something simple I'm missing or maybe not but I can't make it realise that the playerid is meant to be the same player that typed in that command
Reply
#4

pawn Код:
SetTimerEx("OperateDelay", 10000, true, "i", playerid);
Reply
#5

ahh Thank you so much yes this will be a very useful thing to have.. I saw SetTimerEx but didn't think it worked any different to the normal SetTimer .. just read up now that it is way more powerful than the more basic SetTimer
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)