Engine and renting problem. -
MartiQ - 28.11.2012
Hello.
So I have a little problem with my server. I was trying to add renting system after I added engine system.
All commands works fine, but the problem is, that I can start engine and not pay for rent. How is it possible that player firstly enter command /hirecar and after that command is successful, he can use command /engine. Here is the script:
Код:
public OnPlayerStateChange(playerid, newstate, oldstate) {
new newcar = GetPlayerVehicleID(playerid);
new string[256];
#if defined DEBUG
printf("[debug] OnPlayerStateChange(%d, %d, %d)", playerid, newstate, oldstate);
#endif
if(newstate == PLAYER_STATE_DRIVER) {
if(Engine[newcar] == 0) {
if(!IsNotAEngineCar(newcar)) {
new engine,lights,alarm,doors,bonnet,boot,objective,panels,tires;
GetVehicleParamsEx(newcar,engine,lights,alarm,doors,bonnet,boot,objective);
SetVehicleParamsEx(newcar,VEHICLE_PARAMS_OFF,lights,alarm,doors,bonnet,boot,objective);
GetVehicleDamageStatus(newcar,panels,doors,lights,tires);
UpdateVehicleDamageStatus(newcar, panels, doors, 5, tires);
TextDrawShowForPlayer(playerid, EngineOffTD);
}
}
TextDrawShowForPlayer(playerid, Speedometer[playerid]);
SpeedoTimer[playerid] = SetTimerEx("Speedo", 100, 1, "i", playerid);
TextDrawShowForPlayer(playerid, FuelTD[playerid]);
format(string, sizeof(string), "~b~Fuel:~w~ %d%", VehicleFuel[newcar]);
TextDrawSetString(FuelTD[playerid], string);
if(Engine[newcar] == 1)
{
FuelTimer[playerid] = SetTimerEx("FuelLowerTimer", 30000, 1, "ii", playerid, newcar);
}
if(IsARentCar(newcar))
{
if(HireCar[playerid] == newcar)
{ }
else
{
TextDrawHideForPlayer(playerid,Textdrawz[playerid]);
TextDrawSetString(Textdrawz[playerid],"~w~Info: Car rent price is: ~g~$50.~w~~n~Tip: To be able use command ~g~/lock~w~ write ~g~/hirecar~w~.");
TextDrawShowForPlayer(playerid,Textdrawz[playerid]);
return true;
}
}
Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys) {
#if defined DEBUG
printf("[debug] OnPlayerKeyStateChange(%d, %d, %d)", playerid, newkeys, oldkeys);
#endif
new vehicleid = GetPlayerVehicleID(playerid);
if(newkeys == KEY_HANDBRAKE)
{
if(IsPlayerInAnyVehicle(playerid))
{
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
if(Engine[GetPlayerVehicleID(playerid)] == 0)
{
if(HireCar[playerid] != vehicleid) {
return 1;
}
KillTimer(FuelTimer[playerid]);
new engine, lights, alarm, doors, bonnet, boot, objective;
GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
SetVehicleParamsEx(vehicleid, 1, 1, alarm, doors, bonnet, boot, objective);
TextDrawHideForPlayer(playerid, EngineOffTD);
FuelTimer[playerid] = SetTimerEx("FuelLowerTimer", 30000, 1, "ii", playerid, vehicleid);
Engine[vehicleid] = 1;
SpeedoTimer[playerid] = SetTimerEx("Speedo", 100, 1, "i", playerid);
}
}
}
}
Код:
CMD:hirecar(playerid, params[]) {
new string[64],
vehicleid;
vehicleid = GetPlayerVehicleID(playerid);
if(IsPlayerConnected(playerid)) {
if(IsARentCar(vehicleid)) {
if (playerVariables[playerid][pMoney] < 50)
{
SendClientMessage(playerid, COLOR_PURPLE,"ERROR: You dont have enough money !");
return true;
}
/*if(HireCar[playerid] != 999)
{
gCarLock[HireCar[playerid]] = 0;
UnLockCar(HireCar[playerid]);
}*/
HireCar[playerid] = GetPlayerVehicleID(playerid);
playerVariables[playerid][pMoney] -= 50;
PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
format(string, sizeof(string), "Thank you for using our car. Command: /lock");
SendClientMessage(playerid, COLOR_WHITE, string);
format(string, sizeof(string), "Tip: To stop using car: /unhirecar");
SendClientMessage(playerid, COLOR_WHITE, string);
TogglePlayerControllable(playerid, true);
TextDrawHideForPlayer(playerid, Textdrawz[playerid]);
}
}
return true;
}
Код:
CMD:engine(playerid, params[])
{
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
new vehicleid = GetPlayerVehicleID(playerid); //string[256];
if(Engine[vehicleid] == 1)
{
new engine, lights, alarm, doors, bonnet, boot, objective;
GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
SetVehicleParamsEx(vehicleid, 0, lights, alarm, doors, bonnet, boot, objective);
TextDrawShowForPlayer(playerid, EngineOffTD);
KillTimer(FuelTimer[playerid]);
KillTimer(SpeedoTimer[playerid]);
Engine[vehicleid] = 0;
}
else
{
KillTimer(FuelTimer[playerid]);
new engine, lights, alarm, doors, bonnet, boot, objective;
GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
SetVehicleParamsEx(vehicleid, 1, 1, alarm, doors, bonnet, boot, objective);
TextDrawHideForPlayer(playerid, EngineOffTD);
FuelTimer[playerid] = SetTimerEx("FuelLowerTimer", 30000, 1, "ii", playerid, vehicleid);
Engine[vehicleid] = 1;
SpeedoTimer[playerid] = SetTimerEx("Speedo", 100, 1, "i", playerid);
}
}
else return SendClientMessage(playerid, COLOR_WHITE, "You have to be inside vehicle to start engine.");
return 1;
}
I hope you can help me.
Best wishes, MartiQ