IfIsAnyFBIVehNear Stock help
#1

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;
}
Reply
#2

with this you are getting the closest vehicle.
PHP Code:
GetClosestVehicle(playerid)
{
    new 
closestdist 999999999closestvehicle = -1;
    new 
Float:x[2],Float:y[2],Float:z[2],distance;
    for(new 
iMAX_VEHICLESi++)
    {
        
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(playeridfbirangerrange
with this useful function
PHP Code:
IsPlayerNearVehicle(playeridvehicleidFloat:range)
{
    new 
Float:XFloat:YFloat:Z;
    
GetVehiclePos(vehicleidXYZ);
    if(
IsPlayerInRangeOfPoint(playeridrangeXYZ))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 :
Reply
#3

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
Reply
#4

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(playeridx[0],y[0],z[0])); 
Reply
#5

You helped me alot, thanks.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)