30.11.2015, 12:27
It is very much possible.
I will show you how I do it myself, which might not be the best way to do it, but it works:
This is my /taxi command. It allows the player to go on duty, off duty, change the driving fare and whatnot. Take a look at it and try to copy the way I did it. If you need an explanation just say so.
I will show you how I do it myself, which might not be the best way to do it, but it works:
Код:
CMD:taxi(playerid, params[]) { if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_ERROR, "Error:"ERROR" You must be driving a vehicle to use this command."); if(GetPlayerVehicleSeat(playerid) != 0) return SendClientMessage(playerid, COLOR_ERROR, "Error:"ERROR" You must be the driver of this vehicle."); new Func[15], amount; if(pInfo[playerid][Job] != Taxi) return SendClientMessage(playerid, COLOR_ERROR, NOPE); Func = "bla"; sscanf(params, "s[15]i", Func, amount); if(!strcmp(Func, "fare", true)) { if(pInfo[playerid][TaxiDuty] == 0) return SendClientMessage(playerid, COLOR_ERROR, "Error:"ERROR" You have to be working in order to choose your fare."); if(sscanf(params, "s[15]i", Func, amount)) return SendClientMessage(playerid, COLOR_USAGE, "USAGE: "USAGE"/taxi fare [amount]]"); if(amount < 1 || amount > 10) return SendClientMessage(playerid, COLOR_ERROR, "Error:"ERROR" The fare may only be between 1 and 10 US dollars."); if(pInfo[playerid][TaxiFare] == amount) { format(Message, sizeof(Message), "Error:"ERROR" Your taxi fare is already $%d.", amount); return SendClientMessage(playerid, COLOR_ERROR, Message); } pInfo[playerid][TaxiFare] = amount; format(Message, sizeof(Message), "(Info):"INFO2" You have successfully set your taxi fare to be $%d.", amount); SendClientMessage(playerid, COLOR_INFO2, Message); } else if(!strcmp(Func, "duty", true)) { if(pInfo[playerid][TaxiDuty] == 0) { if(GetVehicleModel(GetPlayerVehicleID(playerid)) != 420 && GetVehicleModel(GetPlayerVehicleID(playerid)) != 438) return SendClientMessage(playerid, COLOR_ERROR, "Error:"ERROR" You may only use this command while driving a taxi."); pInfo[playerid][TaxiDuty] = 1; SendClientMessage(playerid, COLOR_INFO2, "(Info):"INFO2" You are now on taxi duty."); } else { pInfo[playerid][TaxiDuty] = 0; SendClientMessage(playerid, COLOR_ERROR, "(Info):"ERROR" You are now off taxi duty."); } } else if(!strcmp(Func, "startmeter", true)) { if(pInfo[playerid][TaxiDuty] == 0) return SendClientMessage(playerid, COLOR_ERROR, "Error:"ERROR" You have to be working in order to start the meter."); if(GetVehicleModel(GetPlayerVehicleID(playerid)) != 420 && GetVehicleModel(GetPlayerVehicleID(playerid)) != 438) return SendClientMessage(playerid, COLOR_ERROR, "Error:"ERROR" You may only use this command while driving a taxi."); if(pInfo[playerid][TaxiMeter] == 1) return SendClientMessage(playerid, COLOR_ERROR, "Error:"ERROR" The meter is already running!"); pInfo[playerid][AmountToPay] = 0; pInfo[playerid][TaxiMeter] = 1; GetPlayerPos(playerid, pInfo[playerid][pX], pInfo[playerid][pY], pInfo[playerid][pZ]); SetTimerEx("AddToTaxiMoney", 5000, false, "ifff", playerid, pInfo[playerid][pX], pInfo[playerid][pY], pInfo[playerid][pZ]); SendClientMessage(playerid, COLOR_INFO2, "(Info):"INFO2" The meter is now running."); } else if(!strcmp(Func, "stopmeter", true)) { if(pInfo[playerid][TaxiDuty] == 0) return SendClientMessage(playerid, COLOR_ERROR, "Error:"ERROR" You have to be working in order to stop the meter."); if(GetVehicleModel(GetPlayerVehicleID(playerid)) != 420 && GetVehicleModel(GetPlayerVehicleID(playerid)) != 438) return SendClientMessage(playerid, COLOR_ERROR, "Error:"ERROR" You may only use this command while driving a taxi."); if(pInfo[playerid][TaxiMeter] == 0) return SendClientMessage(playerid, COLOR_ERROR, "Error:"ERROR" The meter is not running."); pInfo[playerid][TaxiMeter] = 0; format(Message, sizeof(Message), "(Info):"INFO2" The meter is no longer running. The amount is $%d.", pInfo[playerid][AmountToPay]); SendClientMessage(playerid, COLOR_INFO2, Message); } else return SendClientMessage(playerid, COLOR_USAGE, "USAGE:"USAGE" /taxi [duty|fare|startmeter|stopmeter]"); return 1; }