Need help with vehicle scripting please -
iSkull - 29.01.2013
Hello. I'm trying to script an AT400 interior. When a player types /enter near an AT400, he enters that interior.
If someone drove the ATC400 to another place, when the player inside the interior type /exit, he spawns at the AT400 position.
Can somebody help me with that? The problem is I don't know how to save a specified vehicle into the data. I mean there could be 3 - 4 AT400 spawned. How to mark the AT400 I have entered, so I can get its pos later?
Thanks in advance
Re: Need help with vehicle scripting please -
[KHK]Khalid - 29.01.2013
You could create a per-player global variable for this:
pawn Код:
new Entered_AT400_ID[MAX_PLAYERS];
// When he enters a AT400 successfully
Entered_AT400_ID[playerid] = vehicleid; // the AT400 ID
// And this is an example of getting the position of a player's AT400
new Float:vPos[3];
GetVehiclePos(Entered_AT400_ID[playerid], vPos[0], vPos[1], vPos[2]);
Somethings you may need to take care of:
- If you have a vehicle locking system, then check if a vehicle is unlocked on /enter.
- When a player exits a AT400, check if their Z position is high enough and then give them a parachute.
- When a AT400 explodes, you may want to kill the players inside it. Example:
pawn Код:
public OnVehicleDeath(vehicleid, killerid)
{
// loop through all players once a vehicle dies
for(new i = 0; i < MAX_PLAYERS; i ++)
{
if(!IsPlayerConnected(i) || IsPlayerNPC(i))
continue; // will skip if they are not connected or are NPCs
if(Entered_AT400_ID[i] == vehicleid) // if the dead vehicle is a player's AT400
{
SetPlayerHealth(i, 0.0); // Kill them?
}
}
return 1;
}
Re: Need help with vehicle scripting please -
iSkull - 29.01.2013
Special thanks! +rep
But, at
Код:
// When he enters a AT400 successfully
Entered_AT400_ID[playerid] = vehicleid; // the AT400 ID
How'd I get the ID of the AT400 I just /enter'ed?
Re: Need help with vehicle scripting please -
[KHK]Khalid - 29.01.2013
Here you go:
pawn Код:
// A function to get the ID of a nearby AT400
stock GetNearbyAT400ID(playerid, Float:distance)
{
new RETURN = INVALID_VEHICLE_ID;
for(new i = 0; i < MAX_VEHICLES; i ++)
{
if(GetVehicleModel(i) == 577)
{
new Float:X, Float:Y, Float:Z;
GetVehiclePos(i, X, Y, Z);
if(GetPlayerDistanceFromPoint(playerid, X, Y, Z) <= distance)
{
RETURN = i;
break;
}
}
}
return RETURN;
}
Example:
pawn Код:
// How to use
new AT400ID = GetNearbyAT400ID(playerid, 3.0);
if(AT400ID == INVALID_VEHICLE_ID)
{
SendClientMessage(playerid, -1, "Error: No aeroplanes around!");
}
else
{
// Teleport them to interior
// And store the ID:
Entered_AT400_ID[playerid] = AT400ID;
}
Re: Need help with vehicle scripting please -
iSkull - 29.01.2013
Awesome! Thank you! More rep.