Timer help!
#1

Hey guys! I found this piece of code on the forums

Код:
public OnPlayerExitVehicle(playerid, vehicleid)
{
    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
    {
        new currentveh;
        currentveh = GetPlayerVehicleID(playerid);
        DestroyVehicle(currentveh);
        SetTimerEx("cardestroyedhide", 5000, 0, "i", playerid);
    }
    return 1;
}
This makes it so that when a player exits his car, the car disappears. That's nice, but I want to disappear after a minute, how do I implement that?

Thanks in advance!
-Nick
Reply
#2

Try this:

Код:
public OnPlayerExitVehicle(playerid, vehicleid)
{
    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
    {
        new currentveh;
        currentveh = GetPlayerVehicleID(playerid);
        DestroyVehicle(currentveh);
        SetTimerEx("cardestroyedhide", 60000 , 0, "i", playerid);
    }
    return 1;
}
Reply
#3

Quote:
Originally Posted by gtakillerIV
Посмотреть сообщение
Try this:

Код:
public OnPlayerExitVehicle(playerid, vehicleid)
{
    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
    {
        new currentveh;
        currentveh = GetPlayerVehicleID(playerid);
        DestroyVehicle(currentveh);
        SetTimerEx("cardestroyedhide", 60000 , 0, "i", playerid);
    }
    return 1;
}
Nope, car directly disappears after I get out, it neds to wait one minute after the player gets out
Reply
#4

Should work...


pawn Код:
public OnPlayerExitVehicle(playerid, vehicleid)
{
    for(new i=0; i<MAX_VEHICLES; i++)
    SetTimerEx("ResetCar", 60000, 0,"d", vehicleid);
}
forward ResetCar(vehicleid);
public ResetCar(vehicleid)
{
    DestroyVehicle(vehicleid);
    return 1;
}
Reply
#5

Quote:
Originally Posted by Mr_DjolE
Посмотреть сообщение
Should work...


pawn Код:
public OnPlayerExitVehicle(playerid, vehicleid)
{
    for(new i=0; i<MAX_VEHICLES; i++)
    SetTimerEx("ResetCar", 60000, 0,"d", vehicleid);
}
forward ResetCar(vehicleid);
public ResetCar(vehicleid)
{
    DestroyVehicle(vehicleid);
    return 1;
}
Aww yeah! It works! What happens if a user gets back in the car in that minute? Will the car still disappear?

--EDIT--
Tested, car will disappear, can you also build in that that doesn't happen? Would be greatly apriciatied!
Reply
#6

Код:
forward ResetCar(playerid, vehicleid);
public ResetCar(playerid, vehicleid)
{
	if(!IsPlayerInAnyVehicle(playerid))
 	{
  		DestroyVehicle(vehicleid);
   	}
	return 1;
}
This should work, I hope.

Sorry for lose identations.
Reply
#7

Quote:
Originally Posted by Mr_DjolE
Посмотреть сообщение
Should work...


pawn Код:
public OnPlayerExitVehicle(playerid, vehicleid)
{
    for(new i=0; i<MAX_VEHICLES; i++)// < What is this for? You dont need this.
    SetTimerEx("ResetCar", 60000, 0,"d", vehicleid);
}
forward ResetCar(vehicleid);
public ResetCar(vehicleid)
{
    DestroyVehicle(vehicleid);
    return 1;
}
Remove the for-loop, you dont even use it.
Reply
#8

Quote:
Originally Posted by nickbouwhuis
Посмотреть сообщение
Aww yeah! It works! What happens if a user gets back in the car in that minute? Will the car still disappear?

--EDIT--
Tested, car will disappear, can you also build in that that doesn't happen? Would be greatly apriciatied!
Well try killing timer onplayerentervehicle, that should work i think.

E.g.

pawn Код:
new myTimer;

public OnPlayerExitVehicle(playerid, vehicleid)
{
    myTimer = SetTimerEx("ResetCar", 60000, 0,"d", vehicleid);
}
forward ResetCar(vehicleid);
public ResetCar(vehicleid)
{
    DestroyVehicle(vehicleid);
    return 1;
}
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    KillTimer(myTimer);
    return 1;
}
Reply
#9

pawn Код:
new myTimer[MAX_VEHICLES];

public OnPlayerExitVehicle(playerid, vehicleid)
{
    myTimer[vehicleid] = SetTimerEx("ResetCar", 60000, 0,"d", vehicleid);
}
forward ResetCar(vehicleid);
public ResetCar(vehicleid)
{
    DestroyVehicle(vehicleid);
    return 1;
}
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    KillTimer(myTimer[vehicleid]);
    return 1;
}
small fix
Reply
#10

Quote:
Originally Posted by RedFusion
Посмотреть сообщение
pawn Код:
new myTimer[MAX_VEHICLES];

public OnPlayerExitVehicle(playerid, vehicleid)
{
    myTimer[vehicleid] = SetTimerEx("ResetCar", 60000, 0,"d", vehicleid);
}
forward ResetCar(vehicleid);
public ResetCar(vehicleid)
{
    DestroyVehicle(vehicleid);
    return 1;
}
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    KillTimer(myTimer[vehicleid]);
    return 1;
}
small fix
Thank you soo much for your help! It worked for me!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)