08.07.2010, 17:20
(
Последний раз редактировалось Hiddos; 09.07.2010 в 10:21.
)
I'll be using OnPlayerKeyStateChange here for entering RC vehicles.
Here's what we're gonna use:
A define for the range of when the player can or can't enter a RC vehicle
OnPlayerKeyStateChange
Enough shit, let's get started:
Put this above your script, but under your #includes. You might wish to enter the range without a new #define though.
Here's just a basic stock function I made, you might like to use it for further scripting as well.
Put it down your script (Anywhere will do, but I usually do it completely down).
Thanks to Sergei for showing this method.
Now the hard work is done, this'll be easy. Or maybe not.
Beginning of our OnPlayerKeyStateChange callback.
Here's the part for exiting the vehicle. Now it may sound weird why exiting goes first, but it's easier.
You might be wondering why I won't simply use 'RemovePlayerFromVehicle', as it does almost the same. The weird thing is, this function doesn't work with RC vehicles. Trailers unconfirmed.
Now for entering a vehicle:
So your OnPlayerKeyStateChange should now look like this:
*The '&' in a check ('if()', for example), checks if the value is in the given variable. You could do it with if(newkeys== 16), but then it'd check if he only presses the enter button. So in this case, the '&' checks if a player presses the Enter button, and it doesn't minds if he presses another key.
Hope you could do something with this. Here's a little filterscript you might like to use, in-case the above doesn't works.
Link: http://pastebin.com/hn6dBpNR
Questions may be asked in this thread.
- Hiddos was here.
Here's what we're gonna use:
A define for the range of when the player can or can't enter a RC vehicle
OnPlayerKeyStateChange
Enough shit, let's get started:
Put this above your script, but under your #includes. You might wish to enter the range without a new #define though.
pawn Код:
#define RC_ENTER_RANGE 8 // Range in foot
Put it down your script (Anywhere will do, but I usually do it completely down).
Thanks to Sergei for showing this method.
pawn Код:
stock IsVehicleRCVehicle(vehicleid)
{
switch(GetVehicleModel)
{
case 441,464,465,501,564,594: return 1;
}
return 0;
}
pawn Код:
public OnPlayerKeyStateChange(playerid,newstate,oldstate)
{
if(newkeys & 16) // Is the 'key value' of the enter vehicle control.
Here's the part for exiting the vehicle. Now it may sound weird why exiting goes first, but it's easier.
pawn Код:
new Float:x,Float:y,Float:z;
if(IsPlayerInAnyVehicle(playerid) && IsVehicleRCVehicle(GetPlayerVehicleID(playerid)) // Checks if the player is in a vehicle and, if so, if the vehicle is a RC vehicle.
{
GetVehiclePos(GetPlayerVehicleID(playerid),x,y,z);
SetPlayerPos(playerid,x,y,z);
return 1; // OnPlayerKeyStateChange won't be executed any further.
}
Now for entering a vehicle:
pawn Код:
for(new v; v < MAX_VEHICLES; v++) // Loop through all vehicles
{
GetVehiclePos(v,x,y,z);
if(IsPlayerInRangeOfPoint(playerid,RC_ENTER_RANGE,x,y,z) && IsVehicleRCVehicle(v)) //Check if the player is near a RC vehicle.
{
PutPlayerInVehicle(playerid,v,0); // Put the player in the RC vehicle
return 1; // OnPlayerKeyStateChange won't be executed any further.
}
}
pawn Код:
public OnPlayerKeyStateChange(playerid,newstate,oldstate)
{
if(newkeys & 16) // Is the 'key value' of the enter vehicle control.new Float:x,Float:y,Float:z; Scroll down for more information about this '&'
{
if(IsPlayerInAnyVehicle(playerid) && IsVehicleRCVehicle(GetPlayerVehicleID(playerid)) // Checks if the player is in a vehicle and, if so, if the vehicle is a RC vehicle.
{
GetVehiclePos(GetPlayerVehicleID(playerid),x,y,z);
SetPlayerPos(playerid,x,y,z);
return 1; // OnPlayerKeyStateChange won't be executed any further.
}
for(new v; v < MAX_VEHICLES; v++) // Loop through all vehicles
{
GetVehiclePos(v,x,y,z);
if(IsPlayerInRangeOfPoint(playerid,RC_ENTER_RANGE,x,y,z) && IsVehicleRCVehicle(v)) //Check if the player is near a RC vehicle.
{
PutPlayerInVehicle(playerid,v,0); // Put the player in the RC vehicle
return 1; // OnPlayerKeyStateChange won't be executed any further.
}
}
}
return 1;
}
Hope you could do something with this. Here's a little filterscript you might like to use, in-case the above doesn't works.
Link: http://pastebin.com/hn6dBpNR
Questions may be asked in this thread.
- Hiddos was here.