script help
#1

Код:
	if(strcmp(cmd, "/descuiemasina", true) == 0)
	{
	    tmp = strtok(cmdtext, idx);
		if(!strlen(tmp))
		{
			SendUsage(playerid,"/descuiemasina [carid]");
			return 1;
		}
		new carid = strval(tmp);
		if(PlayerData[playerid][pMember] == 10 || PlayerData[playerid][pLeader] == 10)
		{
			if(PlayerData[playerid][pRank] >= 5)
			{
				if(VehLocked[carid] == 1)
				{
			 		SendClientMessage(playerid, COLOR_GRAD1, "Server: Masina descuiata");
			 		VehLocked[carid] = 0;
			 		GetVehicleParamsEx(carid,engine,lights,alarm,doors,bonnet,boot,objective);
					SetVehicleParamsEx(carid,engine,lights,alarm,0,bonnet,boot,objective);
				    return 1;
				}
				else
				{
				    SendClientMessage(playerid, COLOR_GRAD1, "Masina este deja descuitata!");
				}
			}
			else
			{
   				SendClientMessage(playerid, COLOR_GRAD1, "Nu ai rank 5+!");
			}
		}
		else
		{
  			SendClientMessage(playerid, COLOR_GRAD1, "Nu esti membru remorcari auto!");
		}
		return 1;
	}
hello , i do have a script that unlock's cars but the problem is that it need's the car ID , i want to change it that unlocks the closest car
Reply
#2

Put this somewhere in your script, probably where you have your publics and your forwards:

Код:
forward GetClosestCar(playerid);
public GetClosestCar(playerid)
{
     if (!IsPlayerConnected(playerid))
     {
          return -1;
     }
     new Float:prevdist = 100000.000;
     new prevcar;
     for (new carid = 0; carid < MAX_VEHICLES; carid++)
     {
          new Float:dist = GetDistanceToCar(playerid,carid);
          if ((dist < prevdist))
          {
               prevdist = dist;
               prevcar = carid;
          }
     }
     return prevcar;
}
That gets the closest car to you, I think you can manage the rest.

EDIT:
Код:
new carid = GetClosestCar(playerid);
VehLocked[carid] = 0;
GetVehicleParamsEx(carid,engine,lights,alarm,doors,bonnet,boot,objective);
SetVehicleParamsEx(carid,engine,lights,alarm,0,bonnet,boot,objective);
That should work if you add it to your command.

Hope I helped!
Reply
#3

I guess this is what you're looking for. I've explained my code in comments, tell me if you need further explanation though!
pawn Код:
if(strcmp(cmd, "/descuiemasina", true) == 0)
{
    if(PlayerData[playerid][pMember] == 10 || PlayerData[playerid][pLeader] == 10)
    {
        if(PlayerData[playerid][pRank] >= 5)
        {
            new Float:distance = 12.0; // The maximum range which we check vehicles around
            new Float:X, Y, Z;
            GetPlayerPos(playerid, X, Y, Z);
            new engine,lights,alarm,doors,bonnet,boot,objective;
            for(new i = 0; i < MAX_VEHICLES; i ++) // Loop through all vehicles
            {
                // Ignore invalid vehicles
                if(GetVehicleModel(i) == 0)
                    continue;
                   
                // If this vehicle is actually locked
                if(VehLocked[i] == 1)
                {
                    // This vehicle is locked. Now let's check if it's in the range of this player.
                    if(GetVehicleDistanceFromPoint(i, X, Y, Z) <= distance)
                    {
                        VehLocked[i] = 0;
                        GetVehicleParamsEx(i,engine,lights,alarm,doors,bonnet,boot,objective);
                        SetVehicleParamsEx(i,engine,lights,alarm,0,bonnet,boot,objective);
                    }
                }
            }
        }
        else
        {
            SendClientMessage(playerid, COLOR_GRAD1, "Nu ai rank 5+!");
        }
    }
    else
    {
        SendClientMessage(playerid, COLOR_GRAD1, "Nu esti membru remorcari auto!");
    }
    return 1;
}
Reply
#4

https://sampwiki.blast.hk/wiki/Useful_F...#GetClosestCar
No need for silly loops.
Reply
#5

Quote:
Originally Posted by arad55
Посмотреть сообщение
That function obviously uses a loop internally.
Reply
#6

PHP код:
stock GetClosestVehicle(playeridFloat:range)
{
    new
        
Float:pos[3],
        
Float:distance,
        
Float:precedent_distance range +1,
        
precedent;
        
    
GetPlayerPos(playeridpos[0], pos[1], pos[2]);    
        
    for(new 
vehicleid 1vehicleid MAX_VEHICLESvehicleid++)
    {    
        
distance GetVehicleDistanceFromPoint(vehicleidpos[0], pos[1], pos[2]);
        if(
distance <= range && distance <= precedent_distance)
        {
            
precedent vehicleid;
            
precedent_distance distance;
        }
    }
    return 
precedent;

And for use in command :
PHP код:
CMD:unlock(playeridparams[])
{
      new 
vehicle GetClosestVehicle(playerid3);
      if(
vehicle == INVALID_VEHICLE_ID) return SCM(playerid, -1"No vehicle at proximate");
      
// Lock/Unlock your veh and the ID of car is in variable "vehicle"
      
return 1;

Sorry for this bad script, I'm on phone
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)