IfIsNearFBIVeh help -
MarioKamani - 02.03.2018
Anyone can get this command to work
ONLY when there is a
FBI VEHICLE near, and when the
boot is open?
Code:
CMD:weaponequip(playerid, params[])
{
new GunID, pID, playerID, tarid;
new vehicleid = GetClosestVehicle(playerid),engine,lights, alarm, doors, bonnet, boot, objective;
GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
if(sscanf(params, "ui", pID, GunID)) return SendClientMessage(playerid, COL_ERROR, "SERVER: /weaponequip [PlayerID] [WeaponID = (1:smg|2:m4|3:sniper|4:deagle|5:armour)");
if(pID == INVALID_PLAYER_ID) return SendClientMessage(playerid, COL_ERROR, "SERVER: Player is not connected!");
if(!boot) return SendClientMessage(playerid, COL_ERROR, "SERVER: The boot of the Federal Rancher is not open!");
{
switch(GunID)
{
case 1:
{
GivePlayerWeapon(pID, 29, 250);
SendClientMessage(tarid, 0x00FF00FF, "You have been equipped with a SMG.");
}
case 2:
{
GivePlayerWeapon(pID, 31, 400);
SendClientMessage(tarid, 0x00FF00FF, "You have been equipped with a M4.");
}
case 3:
{
GivePlayerWeapon(pID, 34, 30);
SendClientMessage(tarid, 0x00FF00FF, "You have been equipped with a Sniper.");
}
case 4:
{
GivePlayerWeapon(pID, 24, 250);
SendClientMessage(tarid, 0x00FF00FF, "You have been equipped with a Desert Eagle.");
}
case 5:
{
SetPlayerArmour(pID, 100.0);
SendClientMessage(tarid, 0x00FF00FF, "You have been equipped with Armour.");
}
default:
{
return SendClientMessage(tarid, COL_ERROR, "SERVER: Choose between 1-5.");
}
}
}
return 1;
}
Re: IfIsAnyFBIVehNear Stock help -
PepsiCola23 - 02.03.2018
with this you are getting the closest vehicle.
PHP Code:
GetClosestVehicle(playerid)
{
new closestdist = 999999999, closestvehicle = -1;
new Float:x[2],Float:y[2],Float:z[2],distance;
for(new i; i < MAX_VEHICLES; i++)
{
GetVehiclePos(i,x[0],y[0],z[0]);
//if(x[0] == 0.0 && y[0] == 0.0 && z[0] == 0.0) return -1;
GetPlayerPos(playerid,x[1],y[1],z[1]);
distance = floatround(GetDistanceBetweenPoints(x[0],y[0],z[0],x[1],y[1],z[1]));
if(distance < closestdist) {
closestdist = distance;
closestvehicle = i;
}
}
return closestvehicle;
}
it simply loops trought the vehicles and sees what the nearest vehicle is.
so you can use this in your cmd like
PHP Code:
fbiranger = GetClosestVehicle(playerid);
then you need to use
PHP Code:
IsPlayerNearVehicle(playerid, fbiranger, range)
with this useful function
PHP Code:
IsPlayerNearVehicle(playerid, vehicleid, Float:range)
{
new Float:X, Float:Y, Float:Z;
GetVehiclePos(vehicleid, X, Y, Z);
if(IsPlayerInRangeOfPoint(playerid, range, X, Y, Z))return true;
else return false;
}
and you need to do another check to see if the car has the model of the fbi rancher.
PHP Code:
GetVehicleModel
You have the cars list here :
Re: IfIsAnyFBIVehNear Stock help -
MarioKamani - 02.03.2018
C:\Users\Mario\Desktop\[SAMP] 0.3.DL RP\gamemodes\as.pwn(27

: error 017: undefined symbol "GetDistanceBetweenPoints"
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase
Even if i add this:
Code:
Float:GetDistanceBetweenPoints(Float:pos1X, Float:pos1Y, Float:pos1Z, Float:pos2X, Float:pos2Y, Float:pos2Z)
{
return floatadd(floatadd(floatsqroot(floatpower(floatsub(pos1X, pos2X), 2)), floatsqroot(floatpower(floatsub(pos1Y, pos2Y), 2))), floatsqroot(floatpower(floatsub(pos1Z, pos2Z), 2)));
}
it still gives errors:
Code:
C:\Users\Mario\Desktop\[SAMP] 0.3.DL RP\gamemodes\as.pwn(379) : warning 208: function with tag result used before definition, forcing reparse
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase
Re: IfIsAnyFBIVehNear Stock help -
PepsiCola23 - 02.03.2018
you need this
PHP Code:
Float:GetDistanceBetweenPoints(Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2)
{
return floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
}
or you can simply use
PHP Code:
GetPlayerDistanceFromPoint
like this
PHP Code:
distance = floatround(GetPlayerDistanceFromPoint(playerid, x[0],y[0],z[0]));
Re: IfIsAnyFBIVehNear Stock help -
MarioKamani - 02.03.2018
You helped me alot, thanks.