Getting the range of player's closest vehicle -
Mattakil - 09.07.2013
Im trying to do some commands, but only make them work if the player is in range of a vehicle, I got a lot on my mind with whatever, and cant seem to think straight. Can someone please help me??(Will +rep anyone who comments anything helpful ofc)
This is what I got
pawn Код:
stock GetPlayerClosestVehicle(playerid)
{
new vehicleid;
Float:X, Float:Y, Float:Z;
GetPlayerPos(playerid, X, Y, Z);
foreach (new i : vehicleid)
{
GetVehicleDistanceFromPoint(vehicleid, X, Y, Z);
return 1;
}
}
stock IsPlayerInRangeOfClosestVehicle(playerid)
{
new veh = GetPlayerClosestVehicle(playerid);
new Float:X, Float:Y, Float:Z;
GetVehiclePos(veh, X, Y, Z);
if(IsPlayerInRangeOfPoint(playerid, 2.0, X, Y, Z);
Re: Getting the range of player's closest vehicle -
Mattakil - 09.07.2013
I just had an idea...would this work?
pawn Код:
stock IsPlayerInRangeOfClosestVehicle(playerid, distance)
{
new veh = GetPlayerClosestVehicle(playerid);
new Float:X, Float:Y, Float:Z;
GetVehiclePos(veh, X, Y, Z);
if(GetPlayerDistanceFromPoint(playerid, X, Y, Z) <=distance);
{
return 1;
}
}
Re: Getting the range of player's closest vehicle -
CoaPsyFactor - 09.07.2013
Well, with this you do nothing, but really nothing, you should check in GetPLayerClosestVehicle IsPlayerInRangeOfPoint, with Vehicleis position coords in foreach.
Re: Getting the range of player's closest vehicle -
Mattakil - 09.07.2013
I could, but stocks are neater imo
Re: Getting the range of player's closest vehicle -
Jefff - 09.07.2013
pawn Код:
GetPlayerClosestVehicle(playerid)
{
new
Float:X,
Float:Y,
Float:Z,
Float:Distance,
Float:DefaultDistance = 999999999.9,
vID = INVALID_VEHICLE_ID;
for(new carid = 1; carid != MAX_VEHICLES; carid++)
if(IsValidVehicle(carid))
{
GetVehiclePos(carid,X,Y,Z);
Distance = GetPlayerDistanceFromPoint(playerid, X, Y, Z);
if(Distance < DefaultDistance)
{
DefaultDistance = Distance;
vID = carid;
}
}
return vID;
}
bool:IsPlayerInRangeOfClosestVehicle(playerid, Float:Range = 10.0)
{
new veh = GetPlayerClosestVehicle(playerid);
if(veh == INVALID_VEHICLE_ID) return false;
new Float:X, Float:Y, Float:Z;
GetVehiclePos(veh, X, Y, Z);
return !!IsPlayerInRangeOfPoint(playerid, Range, X, Y, Z);
}
or
pawn Код:
Float:IsPlayerInRangeOfClosestVehicle(playerid, Float:Range = 10.0)
{
new veh = GetPlayerClosestVehicle(playerid);
if(veh == INVALID_VEHICLE_ID) return -1.0;
new Float:X, Float:Y, Float:Z, Float:Distance;
GetVehiclePos(veh, X, Y, Z);
Distance = GetPlayerDistanceFromPoint(playerid, X, Y, Z);
if(IsPlayerInRangeOfPoint(playerid, Range, X, Y, Z))
return Distance;
return Distance;
}
pawn Код:
if(-1.0 < IsPlayerInRangeOfClosestVehicle(playerid) < Your_Range)
{
// do something
}
Re: Getting the range of player's closest vehicle -
Mattakil - 09.07.2013
THanks, but I just had another idea, havent tested or nothing, but what about this??
stock LockVehicle(vehicleid)
{
new veh = GetPlayerClosestVehicle(playerid);
if(IsPlayerInRangeOfPoint(playerid, 2.0, veh)
{
new engine, lights, alarm, doors, bonnet, boot, objective);
SetVehicleParamsEx(vehicleid, engine, lights, alarm, 0, bonnet, boot, objective);
}
}
Re: Getting the range of player's closest vehicle -
Jefff - 09.07.2013
Top of GM
Re: Getting the range of player's closest vehicle -
Mattakil - 10.07.2013
Quote:
Originally Posted by Jefff
|
hahaha, very funny...
Fucking Troll.
Re: Getting the range of player's closest vehicle -
SwisherSweet - 10.07.2013
Quote:
Originally Posted by Jefff
|
You think just because ur a high roller you can o off topic some people dont know uow to scipt like you, so please stop its anoyying to everyone im suprised you have not been warned yet i see yiu going off topic always