How can I add /givekey
#1

Hi,

How can i add givekey/takekey for vehicles? And i wanna if user havent key, cant engine. Sorry for my bad English. Im not a pawn coder, im trying to be. So i need examples.

CarData enum;
PHP код:
enum carData {
    
carID,
    
carExists,
    
carModel,
    
carOwner,
    
Float:carPos[4],
    
carColor1,
    
carColor2,
    
carPaintjob,
    
carLocked,
    
carMods[14],
    
carImpounded,
    
carImpoundPrice,
    
carFaction,
    
carSiren,
    
carWeapons[5],
    
carAmmo[5],
    
carVehicle
}; 
/engine cmd;
PHP код:
CMD:motor(playeridparams[])
{
    new 
vehicleid GetPlayerVehicleID(playerid);
    if (!
IsEngineVehicle(vehicleid))
        return 
SendErrorMessage(playerid"Bu komutu araз iзinde kullanabilirsin.");
    if (
GetPlayerState(playerid) != PLAYER_STATE_DRIVER)
        return 
SendErrorMessage(playerid"Sьrьcь değilsiniz.");
    if (
CoreVehicles[vehicleid][vehFuel] < 1)
        return 
SendErrorMessage(playerid"Aracın benzin deposu boş.");
    if (
ReturnVehicleHealth(vehicleid) <= 300)
        return 
SendErrorMessage(playerid"Araз hasarlı gцrьnьyor, зalıştırılamaz.");
    switch (
GetEngineStatus(vehicleid))
    {
        case 
false:
        {
            
SetEngineStatus(vehicleidtrue);
            
ShowPlayerFooter(playerid"You have ~g~started~w~ the engine!");
            
SendNearbyMessage(playerid30.0COLOR_PURPLE"** %s kontağı зevirip aracın motorunu зalıştırır.."ReturnName(playerid0));
        }
        case 
true:
        {
            
SetEngineStatus(vehicleidfalse);
            
ShowPlayerFooter(playerid"You have ~r~stopped~w~ the engine!");
            
SendNearbyMessage(playerid30.0COLOR_PURPLE"** %s kontağı з."ReturnName(playerid0));
        }
    }
    return 
1;

/lock cmd;

PHP код:
CMD:lock(playeridparams[])
{
    static
        
id = -1;
    if (!
IsPlayerInAnyVehicle(playerid) && (id = (House_Inside(playerid) == -1) ? (House_Nearest(playerid)) : (House_Inside(playerid))) != -&& House_IsOwner(playeridid))
    {
        if (!
HouseData[id][houseLocked])
        {
            
HouseData[id][houseLocked] = true;
            
House_Save(id);
            
ShowPlayerFooter(playerid"You have ~r~locked~w~ your house!");
            
PlayerPlaySound(playerid11450.00.00.0);
        }
        else
        {
            
HouseData[id][houseLocked] = false;
            
House_Save(id);
            
ShowPlayerFooter(playerid"You have ~g~unlocked~w~ your house!");
            
PlayerPlaySound(playerid11450.00.00.0);
        }
    }
    else if (!
IsPlayerInAnyVehicle(playerid) && (id = (Business_Inside(playerid) == -1) ? (Business_Nearest(playerid)) : (Business_Inside(playerid))) != -1)
    {
        if (
Business_IsOwner(playeridid))
        {
            if (!
BusinessData[id][bizLocked])
            {
                
BusinessData[id][bizLocked] = true;
                
Business_Refresh(id);
                
Business_Save(id);
                
ShowPlayerFooter(playerid"You have ~r~locked~w~ the business!");
                
PlayerPlaySound(playerid11450.00.00.0);
            }
              else
            {
                
BusinessData[id][bizLocked] = false;
                
Business_Refresh(id);
                
Business_Save(id);
                
ShowPlayerFooter(playerid"You have ~g~unlocked~w~ the business!");
                
PlayerPlaySound(playerid11450.00.00.0);
            }
        }
    }
    else if (!
IsPlayerInAnyVehicle(playerid) && (id = (Entrance_Inside(playerid) == -1) ? (Entrance_Nearest(playerid)) : (Entrance_Inside(playerid))) != -1)
    {
        if (
strlen(EntranceData[id][entrancePass]))
        {
            
Dialog_Show(playeridEntrancePassDIALOG_STYLE_INPUT"Entrance Pass""Please enter the password for this entrance:""Submit""Cancel");
        }
    }
    else if ((
id Car_Nearest(playerid)) != -1)
    {
        static
            
engine,
            
lights,
            
alarm,
            
doors,
            
bonnet,
            
boot,
            
objective;
        
GetVehicleParamsEx(CarData[id][carVehicle], enginelightsalarmdoorsbonnetbootobjective);
        if (
Car_IsOwner(playeridid) || (PlayerData[playerid][pFaction] != -&& CarData[id][carFaction] == GetFactionType(playerid)))
        {
            if (!
CarData[id][carLocked])
            {
                
CarData[id][carLocked] = true;
                
Car_Save(id);
                
ShowPlayerFooter(playerid"You have ~r~locked~w~ the vehicle!");
                
PlayerPlaySound(playerid11450.00.00.0);
                
SetVehicleParamsEx(CarData[id][carVehicle], enginelightsalarm1bonnetbootobjective);
            }
            else
            {
                
CarData[id][carLocked] = false;
                
Car_Save(id);
                
ShowPlayerFooter(playerid"You have ~g~unlocked~w~ the vehicle!");
                
PlayerPlaySound(playerid11450.00.00.0);
                
SetVehicleParamsEx(CarData[id][carVehicle], enginelightsalarm0bonnetbootobjective);
            }
        }
    }
    else 
SendErrorMessage(playerid"You are not in range of anything you can lock.");
    return 
1;

Reply
#2

We need the CarData enum.
Reply
#3

not necessarily, he can create a KeyCar variable [playerid] = -1; when connecting and after trying to make the order.

CMD:givekey(playerid, params[])
{
new id;
sscanf(params,"u",id)) return SendClientMessage(playerid, -1, "/givekey [username/id]");
if(!IsPlayerInVehicle(playerid, /*Your vehicle*/)) return /*Message*/
KeyCar[id] = /*Your vehicle ID*/
...
return 1;
}

it's just a simple exemple, you must to try to make your own commands
Reply
#4

Quote:
Originally Posted by Florin48
Посмотреть сообщение
not necessarily, he can create a KeyCar variable [playerid] = -1; when connecting and after trying to make the order.

CMD:givekey(playerid, params[])
{
new id;
sscanf(params,"u",id)) return SendClientMessage(playerid, -1, "/givekey [username/id]");
if(!IsPlayerInVehicle(playerid, /*Your vehicle*/)) return /*Message*/
KeyCar[id] = /*Your vehicle ID*/
...
return 1;
}

it's just a simple exemple, you must to try to make your own commands
While this will work, it's bad practise. There is a reason why vehicles have an enum, you're offering OP to write un-organized and potentially hard to read code. Not to even mention it won't be possible to save the given key, the key will be reset once the player disconnects which makes the function nearly useless.
Reply
#5

Quote:
Originally Posted by Rufio
Посмотреть сообщение
While this will work, it's bad practise. There is a reason why vehicles have an enum, you're offering OP to write un-organized and potentially hard to read code. Not to even mention it won't be possible to save the given key, the key will be reset once the player disconnects which makes the function nearly useless.
why you want to give him the keys forever, you can sell his vehicle directly then, the order is just to give him keys from the vehicle for a short period of time, I do not think he needs rescue.
Reply
#6

Quote:
Originally Posted by Florin48
Посмотреть сообщение
why you want to give him the keys forever, you can sell his vehicle directly then, the order is just to give him keys from the vehicle for a short period of time, I do not think he needs rescue.
Did I even give the keys "forever"? What you are doing is bad practise as the player might lose connection. If someone sells their vehicle, they won't have access to their vehicle while shared keys let both parties drive the said vehicle.
Reply
#7

Quote:
Originally Posted by Rufio
Посмотреть сообщение
We need the CarData enum.
CarData enum;
PHP код:
enum carData {
    
carID,
    
carExists,
    
carModel,
    
carOwner,
    
Float:carPos[4],
    
carColor1,
    
carColor2,
    
carPaintjob,
    
carLocked,
    
carMods[14],
    
carImpounded,
    
carImpoundPrice,
    
carFaction,
    
carSiren,
    
carWeapons[5],
    
carAmmo[5],
    
carVehicle
}; 
Reply
#8

Quote:
Originally Posted by Rufio
Посмотреть сообщение
Did I even give the keys "forever"? What you are doing is bad practise as the player might lose connection. If someone sells their vehicle, they won't have access to their vehicle while shared keys let both parties drive the said vehicle.
yes, forever or as long as that player has the keys to the car and if one is upset about the other and steals the car because he has a key to it and starts to throw it in the water and she loses insurance points the one who owns the vehicle will be good of payment.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)