/repair cmd help
#1

It's kinda messed up,
Quote:

CMD:repair(playerid, params[])
{
if (!IsPlayerAdmin(playerid))
{
SendClientMessage(playerid, -1, "SERVER:Unknown Command.");
}
else if (IsPlayerAdmin(playerid))
{
SendClientMessage(playerid, -1, "Vehicle repaired");
}
if (!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, -1, "ERROR: You're not in a vehicle.");
{
RepairVehicle(GetPlayerVehicleID(playerid));
}
return 1;
}

If a random players connect, and types /repair while he is not in a car the following appears: SERVER:Unknown Command , and "You're Not in a Vehicle". BUT I want that "You're not in a vehicle" doesn't appear. please help. AND if a random player is in a car and types /repair then appears SERVER:Unknown Command, but the car repairs?? weird.
SO MY QUESTION IS THIS: Can you make it that ONLY admins can use /repair and if a random players types /repair the server says SERVER:Unknown Command. and If a admin types /repair while not in car this appears: "ERROR: You're not in a vehicle" and if a admin is in a car and types /repair this appears: "Vehicle Repaired"
Reply
#2

If you find any error, Any thing special you didn't have and now you have it, Please let me know.
pawn Код:
CMD:repair(playerid, params[])
{
if(IsPlayerConnected(playerid)) // First check if he is online.
{
if (!IsPlayerAdmin(playerid))
{
SendClientMessage(playerid, -1, "SERVER:Unknown Command.");
return 1;
}
if (!IsPlayerInAnyVehicle(playerid))
{
SendClientMessage(playerid, -1, "ERROR: You're not in a vehicle.");
return 1;
}
RepairVehicle(GetPlayerVehicleID(playerid));
SendClientMessage(playerid, -1, "Vehicle repaired");
}
return 1;
}
Reply
#3

// First you should probably change it to return the message instead of continue, as even if one statement turns false it will continue to execute the next if statement.

pawn Код:
CMD:repair(playerid, params[])
{
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "SERVER:Unknown Command.");
    if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, -1, "ERROR: You're not in a vehicle.");
   
    RepairVehicle(GetPlayerVehicleID(playerid));
    return 1;
}
Hope this helps.
Reply
#4

Thank you its working perfectly.
Reply
#5

But Do I have to type , return 1; after every SendClientMessage?
Reply
#6

Quote:
Originally Posted by saffierr
Посмотреть сообщение
But Do I have to type , return 1; after every SendClientMessage?
No, you put return 1; after a command to ensure that it does not send to the player that the command is invalid.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)