19.03.2011, 18:36
Okay so I just finished this script without testing it, but found no errors in the making. Don't flame me as I have not tested this yet and YES, I'm a noob ffs.
Features:
It freezes the player once they are in any car, removes them from the car, resets their weapons, and puts them back to their nearest vehicle closest to them.
Credits:
Badger (for the idea)
Me (for the script)
Features:
Quote:
It's a little too basic. Good idea and all, but resetting the weapons when a player enters a vehicle doesn't always work. And it is only driver drive-by. It's pretty good, just you could make it more accurate (e.g. freezes them for a second when they are in the vehicle, ejects them, disarms them and puts them back in). |
pawn Код:
#include <a_samp>
forward TakePlayerFromVehicle(playerid);
forward PutPlayerInCar(playerid);
new Weapons[MAX_PLAYERS][12];
new WeaponAmmo[MAX_PLAYERS][12];
new PlayerVehicle[MAX_PLAYERS];
new PutPlayerVehicle[MAX_PLAYERS];
new Car;
public OnFilterScriptInit()
{
print("Anti-Driveby Loaded...");
return 1;
}
public OnFilterScriptExit()
{
print("Anti-Driveby Un-Loaded...");
return 1;
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if (newstate==PLAYER_STATE_DRIVER || newstate==PLAYER_STATE_PASSENGER)
{
for(new i=0;i<12;i++)
{
GetPlayerWeaponData(playerid, i, Weapons[playerid][i], WeaponAmmo[playerid][i]);
}
TogglePlayerControllable(playerid, 0); // freeze the player while in the vehicle
PlayerVehicle[playerid] = SetTimerEx("TakePlayerFromVehicle",1000,0,"i",playerid); // Sets a timer of about 1 second to eject the player from the car
}
if (newstate==PLAYER_STATE_ONFOOT && oldstate==PLAYER_STATE_DRIVER)
{
for(new i=0;i<12;i++)
{
GivePlayerWeapon(playerid, Weapons[playerid][i], WeaponAmmo[playerid][i]); //give their weapon back if they aint in the car anymore.
}
}
return 1;
}
public TakePlayerFromVehicle(playerid)
{
if(IsPlayerInAnyVehicle(playerid)) //check if the player is in ANY vehicle
{
RemovePlayerFromVehicle(playerid); //removes the player from the current vehicle
ResetPlayerWeapons(playerid); //Resets the players weapons before going back in the car
PutPlayerVehicle[playerid] = SetTimerEx("PutPlayerInCar",2000,0,"i",playerid); //sets a timer of about 2 seconds to put the player back in the vehicle
}
return 1;
}
public PutPlayerInCar(playerid)
{
Car = GetNearestVehicle(playerid, 1); //Gets the nearest vehicle close to you (you can modify the distance if you want, I did this for my own purposes)
PutPlayerInVehicle(playerid, Car, 0); //Put the player in the vehicle
}
stock Float:GetDistanceBetweenPoints(Float:X, Float:Y, Float:Z, Float:PointX, Float:PointY, Float:PointZ) return floatsqroot(floatadd(floatadd(floatpower(floatsub(X, PointX), 2.0), floatpower(floatsub(Y, PointY), 2.0)), floatpower(floatsub(Z, PointZ), 2.0)));
stock GetNearestVehicle(playerid, Float:Distance = 1000.0)
{
if(!Distance) Distance = 1000.0;
new Float:X[2], Float:Y[2], Float:Z[2], Float:NearestPos = floatabs(Distance), NearestVehicle = INVALID_VEHICLE_ID;
GetPlayerPos(playerid, X[0], Y[0], Z[0]);
for(new i; i<MAX_VEHICLES; i++)
{
if(!IsVehicleStreamedIn(i, playerid) || IsPlayerInVehicle(playerid, i)) continue;
GetVehiclePos(i, X[1], Y[1], Z[1]);
if(NearestPos > GetDistanceBetweenPoints(X[0], Y[0], Z[0], X[1], Y[1], Z[1])) NearestPos = GetDistanceBetweenPoints(X[0], Y[0], Z[0], X[1], Y[1], Z[1]), NearestVehicle = i;
}
return NearestVehicle;
}
Badger (for the idea)
Me (for the script)