PHP код:
#include <a_samp>
#include <dof2>
#include <sscanf2>
#include <Pawn.CMD>
enum PlayerGasolina
{
Gasolina
}
new pGasolina[MAX_PLAYERS][PlayerGasolina];
new gstring[256];
new gasolinaa;
//-----------------------------------------------------------------------
#define DiretorioGasolina "Gasolina/%s.ini"
#define fuction
#define mensagem(%0,%1,%2) format(gstring, sizeof(gstring),%1,%2), SendClientMessageToAll(%0, gstring)
#define mensagemp(%0,%1,%2,%3) format(gstring, sizeof(gstring),%2,%3), SendClientMessage(%0,%1, gstring)
#define publico%0(%1) forward %0(%1); public %0(%1)
//------------------------------------------------------------------------------
public OnPlayerConnect(playerid)
{
if(!DOF2_FileExists(GasolinaPlayer(playerid)))
{
SendClientMessage(playerid, -1, "| INFO | Vocк nгo й registrado, mais jб se registrou");
DOF2_CreateFile(GasolinaPlayer(playerid));
DOF2_SetInt(GasolinaPlayer(playerid), "Gasolina", 100);
}
else
{
SetTimerEx("SalvarGasolina",5000,true,"d",playerid);
pGasolina[playerid][Gasolina] = DOF2_GetInt(GasolinaPlayer(playerid), "Gasolina");
mensagemp(playerid,-1,"| INFO | Vocк tem %d de Litros de Gasolina.", pGasolina[playerid][Gasolina]);
return 1;
}
CarregarGasolina(playerid);
return 1;
}
publico ContarGasolina(playerid)
{
pGasolina[playerid][Gasolina] --;
//SendClientMessage(playerid, -1, "| INFO | Estб Comeзando a contar os gastos da Gasolina.");
return 1;
}
public OnFilterScriptExit()
{
// for(new i = 0; i < MAX_PLAYERS; ++i) if(IsPlayerConnected(i)) SalvarGasolina(i); Isso nгo funciona
DOF2_Exit();
return 1;
}
public OnPlayerStateChange( playerid, newstate, oldstate )
{
if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
{
gasolinaa = SetTimerEx("ContarGasolina",20000,true,"d",playerid);
SendClientMessage(playerid, -1, "| INFO | Contar Gasolina On!");
}
else
{
KillTimer(gasolinaa);
SendClientMessage(playerid, -1, "| INFO | Parar de Contar Gasolina On");
SendClientMessage(playerid, -1, "| ERRO | Vocк saiu do Veнculo e parou de contar a gasolina.");
}
return 1;
}
public OnPlayerDisconnect(playerid, reason) return SalvarGasolina(playerid);
public OnPlayerUpdate(playerid) return 1;
publico SalvarGasolina(playerid)
{
DOF2_SetInt(GasolinaPlayer(playerid), "Gasolina", pGasolina[playerid][Gasolina]);
DOF2_SaveFile();
return 1;
}
fuction CarregarGasolina(playerid)
{
pGasolina[playerid][Gasolina] = DOF2_GetInt(GasolinaPlayer(playerid), "Gasolina", pGasolina[playerid][Gasolina]);
pGasolina[playerid][Gasolina] = pGasolina[playerid][Gasolina];
return 1;
}
fuction GasolinaPlayer(playerid)
{
static nome[MAX_PLAYER_NAME],bug[35];
GetPlayerName(playerid, nome, 44);
format(bug, sizeof(bug), DiretorioGasolina, nome);
return bug;
}
CMD:litros(playerid, params[])
{
mensagemp(playerid,-1,"| INFO | Vocк tem %d de Litros de Gasolina.", pGasolina[playerid][Gasolina]);
return 1;
}
CMD:abastecer(playerid, params[])
{
new gasolina;
if(sscanf(params, "d", gasolina)) return SendClientMessage(playerid, -1, "/Abastecer [litros]");
if(!IsPlayerInVehicle(playerid, GetPlayerVehicleID(playerid))) return SendClientMessage(playerid, -1, "| ERRO | Vocк nгo estб em um Veнculo");
if(gasolina > 100 || gasolina < 0) return SendClientMessage(playerid, -1,"XXX");
pGasolina[playerid][Gasolina] =gasolina;
mensagemp(playerid,-1,"| INFO | Vocк abasteceu %d de Litros!", gasolina);
return 1;
}