SA-MP Forums Archive
Help me with car lock [/lock] - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Help me with car lock [/lock] (/showthread.php?tid=663401)



Help me with car lock [/lock] - akib - 30.01.2019

When I try /lock vehicle works fine but when i try /lock in near of other owned vehicles by others, it returns vehicle id -1(means no vehicle near)

/lock CMD
PHP код:
CMD:lock(playerid,params[]){
    new 
id,enginelightsalarmdoorsbonnetbootobjective;
    
GetVehicleParamsEx(DynamicVehicle[id][dvehicle_vehicle], enginelightsalarmdoorsbonnetbootobjective);
    
id GetPlayerOwnVehicleID(playerid);
    if(
VehicleInfo[DynamicVehicle[id][dvehicle_vehicle]][vehicle_door]){
        
VehicleInfo[DynamicVehicle[id][dvehicle_vehicle]][vehicle_door] = 0;
        
GameTextForPlayer(playerid"~g~UNLOCKED"20005);
    }else{
        
VehicleInfo[DynamicVehicle[id][dvehicle_vehicle]][vehicle_door] = 1;
        
GameTextForPlayer(playerid"~r~LOCKED"20005);
    }
    
SetVehicleParamsEx(DynamicVehicle[id][dvehicle_vehicle], enginelightsalarmVehicleInfo[DynamicVehicle[id][dvehicle_vehicle]][vehicle_door], bonnetbootobjective);
    return 
1;

GetPlayerOwnVehicleID:
PHP код:
GetPlayerOwnVehicleID(playeridFloatrange 2.0)
{
    new 
id = -1Floatdist rangeFloattempdist;
    for(new 
iMAX_PLAYER_VEHICLEi++)
    {
        if(
DynamicVehicle[i][dvehicle_owner]==PlayerInfo[playerid][pID]){
            
tempdist GetPlayerDistanceFromPoint(playeridDynamicVehicle[i][dvehicle_pos][0], DynamicVehicle[i][dvehicle_pos][1],DynamicVehicle[i][dvehicle_pos][2]);
            if(
tempdist range) continue;
            if(
tempdist <= dist)
            {
                
dist tempdist;
                
id i;
            }
        }
    }
    return 
id;