Remove object after 10 seconds
#1

I want the object disappear after 10 second if no one pick it..

PHP код:
public OnPlayerCommandText(playeridcmdtext[])
{
    new 
cmd[256];
    new 
idx;
    new 
string[256];
    new 
sendername[MAX_PLAYER_NAME];
    
cmd strtok(cmdtextidx);
    if(
strcmp(cmd"/dropgun"true) == || strcmp(cmd"/dgun"true) == 0)
    {
        new 
gunID GetPlayerWeapon(playerid);
        new 
gunAmmo GetPlayerAmmo(playerid);
        if(
gunID != && gunAmmo != 0)
        {
            new 
MAX_OBJ+1;
            for(new 
0sizeof(ObjCoords); a++)
            {
                if(
ObjCoords[a][0] == 0.0)
                {
                    
a;
                    break;
                }
            }
            if(
MAX_OBJ) return SendClientMessage(playerid0x33AA3300"You can not throw weapons at the moment, try back later!!");
            new 
gunname[25];
            new 
buffer[100];
            
GetWeaponNameEx(gunIDgunnamesizeof(gunname));
            
GetPlayerName(playeridsendernamesizeof(sendername));
            
format(buffersizeof(buffer), "You threw %s"gunname);
            
SendClientMessage(playerid0x33AA3300buffer);
            
RemovePlayerWeapon(playeridgunID);
            
ObjectID[f][0] = gunID;
            
ObjectID[f][1] = gunAmmo;
            
GetPlayerPos(playeridObjCoords[f][0], ObjCoords[f][1], ObjCoords[f][2]);
            
object[f] = CreateObject(GunObjects[gunID][0],ObjCoords[f][0],ObjCoords[f][1],ObjCoords[f][2]-1,93.7,120.0,120.0);
            {
            
format(stringsizeof(string), "* %s drop their %s."sendernamegunname);
            }
            
ProxDetector(30.0playeridstringCOLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
            
ApplyAnimation(playerid"BOMBER""BOM_Plant"4.000000);
            return 
1;
        }
    } 
Reply
#2

Use a timer.

SetTimer function
SetTimerEx function

Now, once the timer is up then you would do DestroyObject or if you use a streamer the streamers function.
Reply
#3

Quote:
Originally Posted by Steven82
Посмотреть сообщение
Use a timer.

SetTimer function
SetTimerEx function

Now, once the timer is up then you would do DestroyObject or if you use a streamer the streamers function.
I tried.. but it doesnt work..

here the code:

Код:
forward DestroyObject2();

stock Destroy(playerid)
{
    SetTimer("DestroyObject2",3000,false);
}

public DestroyObject2()
{
	new f = MAX_OBJ+1;
	for(new a = 0; a < sizeof(ObjCoords); a++)
	{
	DestroyObject(object[f]);
	}
}

public OnPlayerCommandText(playerid, cmdtext[])
{
	new cmd[256];
	new idx;
	new string[256];
	new sendername[MAX_PLAYER_NAME];
	cmd = strtok(cmdtext, idx);
	if(strcmp(cmd, "/dropgun", true) == 0 || strcmp(cmd, "/dgun", true) == 0)
	{
		new gunID = GetPlayerWeapon(playerid);
		new gunAmmo = GetPlayerAmmo(playerid);
		if(gunID != 0 && gunAmmo != 0)
		{
			new f = MAX_OBJ+1;
			for(new a = 0; a < sizeof(ObjCoords); a++)
			{
				if(ObjCoords[a][0] == 0.0)
				{
					f = a;
					break;
				}
			}
			if(f > MAX_OBJ) return SendClientMessage(playerid, 0x33AA3300, "You can not throw weapons at the moment, try back later!!");
		    new gunname[25];
		    new buffer[100];
			GetWeaponNameEx(gunID, gunname, sizeof(gunname));
			GetPlayerName(playerid, sendername, sizeof(sendername));
			format(buffer, sizeof(buffer), "You threw %s", gunname);
			SendClientMessage(playerid, 0x33AA3300, buffer);
			RemovePlayerWeapon(playerid, gunID);
			ObjectID[f][0] = gunID;
			ObjectID[f][1] = gunAmmo;
	        GetPlayerPos(playerid, ObjCoords[f][0], ObjCoords[f][1], ObjCoords[f][2]);
	        object[f] = CreateObject(GunObjects[gunID][0],ObjCoords[f][0],ObjCoords[f][1],ObjCoords[f][2]-1,93.7,120.0,120.0);
			{
	        format(string, sizeof(string), "* %s drop their %s.", sendername, gunname);
	        }
			ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
			ApplyAnimation(playerid, "BOMBER", "BOM_Plant", 4.0, 0, 0, 0, 0, 0);
			SetTimer("Destroy",10000,false); 
			return 1;
		}
	}
Reply
#4

Did you make the callback for the timer?
Reply
#5

Quote:
Originally Posted by pojefauzan
Посмотреть сообщение
I tried.. but it doesnt work..

here the code:

Код:
forward DestroyObject2();

stock Destroy(playerid)
{
    SetTimer("DestroyObject2",3000,false);
}

public DestroyObject2()
{
	new f = MAX_OBJ+1;
	for(new a = 0; a < sizeof(ObjCoords); a++)
	{
	DestroyObject(object[f]);
	}
}

public OnPlayerCommandText(playerid, cmdtext[])
{
	new cmd[256];
	new idx;
	new string[256];
	new sendername[MAX_PLAYER_NAME];
	cmd = strtok(cmdtext, idx);
	if(strcmp(cmd, "/dropgun", true) == 0 || strcmp(cmd, "/dgun", true) == 0)
	{
		new gunID = GetPlayerWeapon(playerid);
		new gunAmmo = GetPlayerAmmo(playerid);
		if(gunID != 0 && gunAmmo != 0)
		{
			new f = MAX_OBJ+1;
			for(new a = 0; a < sizeof(ObjCoords); a++)
			{
				if(ObjCoords[a][0] == 0.0)
				{
					f = a;
					break;
				}
			}
			if(f > MAX_OBJ) return SendClientMessage(playerid, 0x33AA3300, "You can not throw weapons at the moment, try back later!!");
		    new gunname[25];
		    new buffer[100];
			GetWeaponNameEx(gunID, gunname, sizeof(gunname));
			GetPlayerName(playerid, sendername, sizeof(sendername));
			format(buffer, sizeof(buffer), "You threw %s", gunname);
			SendClientMessage(playerid, 0x33AA3300, buffer);
			RemovePlayerWeapon(playerid, gunID);
			ObjectID[f][0] = gunID;
			ObjectID[f][1] = gunAmmo;
	        GetPlayerPos(playerid, ObjCoords[f][0], ObjCoords[f][1], ObjCoords[f][2]);
	        object[f] = CreateObject(GunObjects[gunID][0],ObjCoords[f][0],ObjCoords[f][1],ObjCoords[f][2]-1,93.7,120.0,120.0);
			{
	        format(string, sizeof(string), "* %s drop their %s.", sendername, gunname);
	        }
			ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
			ApplyAnimation(playerid, "BOMBER", "BOM_Plant", 4.0, 0, 0, 0, 0, 0);
			SetTimer("Destroy",10000,false); 
			return 1;
		}
	}
here
Reply
#6

Thats not a callback?

a callback is something like this
pawn Код:
forward Example(playerid); // This is how to make custom callbacks
public Example(playerid)
{
 // code here
}
To use timers, you need to create callbacks. And the callback represents when the timer ends. So in your case under the timer callback you would Destroy the object.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)