How would i save this - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: How would i save this (
/showthread.php?tid=349007)
How would i save this -
Geniuss - 07.06.2012
Well i followed this tutorial
https://sampforum.blast.hk/showthread.php?tid=169284
And it is working fine im just wondering would i be able to save the fuel that are in player owned cars so when they log out log back in there fuel will be the same as what it was when they logged out.
Thank You
Help Is Appreciated
Re: How would i save this -
Calgon - 07.06.2012
Yes. You can save the information to the playerfile.
Show us your code for saving player vehicles.
Re: How would i save this -
Geniuss - 07.06.2012
Well i have been trying by my self this is what i have
In my PlayerStats enum
pawn Код:
Car1Fuel,
Car2Fuel,
Car3Fuel,
OnGameModeInIt
pawn Код:
for(new i=0;i<MAX_VEHICLES;i++)
{
fuel[i] = 100; //sets every car's fuel to 100 in a loop
}
pawn Код:
public timer_fuel_lower()
{
new engine, lights, alarm, doors, bonnet, boot, objective;
for(new i=0;i<MAX_PLAYERS;i++) { //loop for all players
if (isrefuelling[i]) continue; //stop when a player is already refuelling
new vid = GetPlayerVehicleID(i); //getting vehicle ID
if (GetPlayerVehicleSeat(i) == 0 && EngineOn[vid] == 1) { //if the player is a driver (it should only lower the fuel when theres an driver!)
fuel[vid] = fuel[vid] -1; //lowering fuel value
if(IsPlayerInVehicle(i, Player[i][CarLinkID]))
{
Player[i][Car1Fuel] = -1;
SavePlayerData(i);
}
if (fuel[vid]<1) //if fuel is empty
{
fuel[vid] = 0; //setting fuel to 0 (else the timer will set it to -1 -2 -3 etc before removing player)
RemovePlayerFromVehicle(i); //remove player out of vehicle
GameTextForPlayer(i,"~r~You are out of ~w~fuel~r~!",5000,4); //show text
}
}
new string[125];format(string,sizeof string,"Fuel:%i",fuel[vid]); //preparing string with next fuel value
TextDrawSetString(td_fuel[i],string); //updating textdraw
}
return 1;
}
pawn Код:
public timer_refuel(playerid)
{
new vid = GetPlayerVehicleID(playerid);
fuel[vid] = fuel[vid] = 100; //restoring fuel to 100
isrefuelling[playerid] = 0;//resetting anti-spam thingy :3
TextDrawSetString(td_fuel[playerid],"Fuel:100"); //small update on textdraw
TogglePlayerControllable(playerid,1); //unfreeze player
}
SavePlayerData
pawn Код:
dini_IntSet(string, "Car1Fuel", Player[playerid][Car1Fuel]);
dini_IntSet(string, "Car2Fuel", Player[playerid][Car2Fuel]);
dini_IntSet(string, "Car3Fuel", Player[playerid][Car3Fuel]);
Register Player
pawn Код:
dini_IntSet(string, "Car1Fuel", Player[playerid][Car1Fuel]);
dini_IntSet(string, "Car2Fuel", Player[playerid][Car2Fuel]);
dini_IntSet(string, "Car3Fuel", Player[playerid][Car3Fuel]);
On Player Login Attempt
pawn Код:
Player[playerid][Car1Fuel] = dini_Int(string, "Car1Fuel");
Player[playerid][Car2Fuel] = dini_Int(string, "Car2Fuel");
Player[playerid][Car3Fuel] = dini_Int(string, "Car3Fuel");
On Player State Change
pawn Код:
if (newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
{
new vid = GetPlayerVehicleID(playerid);
new string[125];format(string,sizeof string,"Fuel:%i",fuel[vid]); //quickly doing a small update on fuel (so it wont jump from 100 to its real value)
TextDrawSetString(td_fuel[playerid],string);
TextDrawShowForPlayer(playerid,td_fuel[playerid]); //showing if an player is a driver or passenger of the ar
}
else
{
TextDrawHideForPlayer(playerid,td_fuel[playerid]); //hiding if a player isnt driving/or an passenger
}
Thank You
Help Is Appreciated