Posts: 43
Threads: 10
Joined: Jun 2015
Reputation:
0
Hey, I want to add a system which does the following:
When a player enters a vehicle, depending on the vehicle's ID, 20 seconds after the player has entered it shows a message, and after 25 seconds, the vehicle explodes.
I've tried different ways but I have problems using timers s: someone help?
Thanks!
Posts: 561
Threads: 27
Joined: Sep 2012
Here you go,
PHP код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
if(GetVehicleModel(vehicleid) == your id)
{
SetTimerEx("Message", 5000, false, "i", playerid);
}
return 1;
}
forward Message(playerid);
public Message(playerid)
{
SendClientMessage(playerid, -1, "Welcome to the vehicle.");
SetTimerEx("Explosion", 5000, false, "i", playerid);
return 1;
}
forward Explosion(playerid);
public Explosion(playerid)
{
new Float:x, Float:y, Float:z
GetPlayerPos(playerid,x,y,z);
CreateExplosion(x,y,z,12, 10.0);
SendClientMessage(playerid, -1, "Trapped LOL.");
return 1;
}
Hope that helps, Rep if it does lol ^^
KillerDVX,
Posts: 280
Threads: 1
Joined: Oct 2014
Reputation:
0
@KillerDVX if Player Tries To Enter A Vehicle, "OnPlayerEnterVehicle" Will Call.
so if i Press F and cancel entering car, that vehicle will explode !
its better to use "OnPlayerStateChange" Callback and check player vehicle id after changing state to DRIVER.
also Use SetVehicleHealth To Explode Vehicle
Posts: 561
Threads: 27
Joined: Sep 2012
Or Trying this as well ?
PHP код:
new IsInVeh[MAX_PLAYERS];
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
if(GetVehicleModel(vehicleid) == your id)
{
SetTimerEx("Message", 5000, false, "i", playerid);
IsInVeh[playerid] = 1;
}
return 1;
}
public OnPlayerExitVehicle(playerid, vehicleid)
{
IsInVeh[playerid] = 0;
return 1;
}
forward Message(playerid);
public Message(playerid)
{
SendClientMessage(playerid, -1, "Welcome to the vehicle.");
SetTimerEx("Explosion", 5000, false, "i", playerid);
return 1;
}
forward Explosion(playerid);
public Explosion(playerid)
{
if(IsInVeh[playerid] = 1)
{
new Float:x, Float:y, Float:z
GetPlayerPos(playerid,x,y,z);
CreateExplosion(x,y,z,12, 10.0);
SendClientMessage(playerid, -1, "Trapped LOL.");
}
return 1;
}
Posts: 561
Threads: 27
Joined: Sep 2012
My fault.. x)
Try this one :
PHP код:
new IsInVeh[MAX_PLAYERS];
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
if(GetVehicleModel(vehicleid) == your id)
{
SetTimerEx("Message", 5000, false, "i", playerid);
IsInVeh[playerid] = 1;
}
return 1;
}
public OnPlayerExitVehicle(playerid, vehicleid)
{
IsInVeh[playerid] = 0;
return 1;
}
forward Message(playerid);
public Message(playerid)
{
SendClientMessage(playerid, -1, "Welcome to the vehicle.");
SetTimerEx("Explosion", 5000, false, "i", playerid);
return 1;
}
forward Explosion(playerid);
public Explosion(playerid)
{
if(IsInVeh[playerid] = 1)
{
new pveh =GetPlayerVehicleID(playerid);
new Float:x, Float:y, Float:z
GetVehiclePos(pveh, x, y, z);
CreateExplosion(x,y,z,12, 10.0);
SendClientMessage(playerid, -1, "Trapped LOL.");
}
return 1;
}