30.01.2015, 15:19
Hello , i tried to make Vehicle insurance system . But i am facing some bugs . As i don't have any idea of how to make it . Here is the my code .
OnGamemodeInit()
Public function
When player try to buy vehicle
When Player Try to insure his vehicle by Clicking on list item in dialogbox.
That's all my code . As This look clearly make sense that it won't work . But i don't have any idea what to do . I want to make a system that on vehicle insurance expiration The Vehicle Destroy . and He can renew his insurance again by clicking on list item in dialog box . When code is the last one.
PHP код:
new Insurancetimer;
new VehicleInsurance[MAX_DVEHICLES];
PHP код:
Insurancetimer = SetTimer("Destroycar", 100, true);
PHP код:
forward Destroycar(playerid);
public Destroycar(playerid)
{
new vehicleid = GetPVarInt(playerid, "DialogValue1");
new id = GetVehicleID(vehicleid);
if(GetPlayerVehicleAccess(playerid, id) < 2) // This will detect whether this vehicle is owned by player or not.
{
SendClientMessage(playerid, -1 "You don't have keys of this vehicle");
}
if(gettime() > Insurancetimer)
{
SendClientMessage(playerid, -1, "Insurance ended");
InsuranceTime[vehicleid] = 0;
DestroyVehicle(VehicleID[vehicleid]);
}
//return 1;
}
PHP код:
if(GetPlayerVehicles(playerid) >= MAX_PLAYER_VEHICLES)
{
ShowErrorDialog(playerid, "You can't buy any more vehicles! Max: " #MAX_PLAYER_VEHICLES );
return 1;
}
new id = GetPVarInt(playerid, "DialogValue1");
if(GetPlayerMoney(playerid) < VehicleValue[id])
{
ShowErrorDialog(playerid, "You don't have enough money to buy this vehicle!");
return 1;
}
new freeid = GetFreeVehicleID();
if(!freeid)
{
ShowErrorDialog(playerid, "Vehicle dealership is out of stock!");
return 1;
}
GivePlayerMoney(playerid, -VehicleValue[id]);
new dealerid = strval(VehicleOwner[id]);
VehicleCreated[freeid] = VEHICLE_PLAYER;
VehicleModel[freeid] = VehicleModel[id];
VehiclePos[freeid] = DealershipPos[dealerid];
VehicleColor[freeid] = VehicleColor[id];
VehicleInterior[freeid] = VehicleInterior[id];
VehicleWorld[freeid] = VehicleWorld[id];
VehicleValue[freeid] = VehicleValue[id];
GetPlayerName(playerid, VehicleOwner[freeid], sizeof(VehicleOwner[]));
VehicleNumberPlate[freeid] = DEFAULT_NUMBER_PLATE;
for(new d=0; d < sizeof(VehicleTrunk[]); d++)
{
VehicleTrunk[freeid][d][0] = 0;
VehicleTrunk[freeid][d][1] = 0;
}
for(new d=0; d < sizeof(VehicleMods[]); d++)
{
VehicleMods[freeid][d] = 0;
}
VehiclePaintjob[freeid] = 255;
VehicleLock[freeid] = 0;
VehicleAlarm[freeid] = 0;
VehicleInsurance[freeid] = 1;
UpdateVehicle(freeid, 0);
SaveVehicle(freeid);
new msg[128];
format(msg, sizeof(msg), "You have bought this vehicle for $%d", VehicleValue[id]);
SendClientMessage(playerid, COLOR_WHITE, msg);
PHP код:
new vehicleid = GetPVarInt(playerid, "DialogValue1");
if(GetPlayerVehicleAccess(playerid, vehicleid) < 2)
{
ShowErrorDialog(playerid, "You are not the owner of this vehicle!");
return 1;
}
SendClientMessage(playerid, COLOR_WHITE, "You vehicle insurance renewed.");
InsuranceTime[vehicleid] = gettime() + 60*60*24*2;
UpdateVehicle(vehicleid, 1);
PutPlayerInVehicle(playerid, VehicleID[vehicleid], 0);
SaveVehicle(vehicleid);