Two Big/Long questions -
Kh4led - 27.08.2012
First, if a player time out or crashes. The money doesn't get saved in the INI...
So is there any function to automaticly save player's status every ONE MINUTE.
Here's my Saving system and my Time/Date system.
pawn Код:
//PlayerInfo.
enum pInfo
{
pPass,
pCash,
pScore,
pAdminLevel,
pKills,
pDeaths,
pBanned
}
new PlayerInfo[MAX_PLAYERS][pInfo];
//========================================================//
public LoadUser_data(playerid,name[],value[])
{
INI_Int("Password",PlayerInfo[playerid][pPass]);
INI_Int("Score",PlayerInfo[playerid][pScore]);
INI_Int("Cash",PlayerInfo[playerid][pCash]);
INI_Int("AdminLevel",PlayerInfo[playerid][pAdminLevel]);
INI_Int("Kills",PlayerInfo[playerid][pKills]);
INI_Int("Deaths",PlayerInfo[playerid][pDeaths]);
INI_Int("Banned",PlayerInfo[playerid][pBanned]);
return 1;
}
stock UserPath(playerid)
{
new string[128],playername[MAX_PLAYER_NAME];
GetPlayerName(playerid,playername,sizeof(playername));
format(string,sizeof(string),PATH,playername);
return string;
}
stock udb_hash(buf[]) {
new length=strlen(buf);
new s1 = 1;
new s2 = 0;
new n;
for (n=0; n<length; n++)
{
s1 = (s1 + buf[n]) % 65521;
s2 = (s2 + s1) % 65521;
}
return (s2 << 16) + s1;
}
//============================================//
//Stock Cash.
stock GivePlayerCash(playerid, money)
{
Cash[playerid] += money;
ResetMoneyBar(playerid);
UpdateMoneyBar(playerid,Cash[playerid]);
return Cash[playerid];
}
stock SetPlayerCash(playerid, money)
{
Cash[playerid] = money;
ResetMoneyBar(playerid);
UpdateMoneyBar(playerid,Cash[playerid]);
return Cash[playerid];
}
stock ResetPlayerCash(playerid)
{
Cash[playerid] = 0;
ResetMoneyBar(playerid);
UpdateMoneyBar(playerid,Cash[playerid]);
return Cash[playerid];
}
stock GetPlayerCash(playerid)
{
return Cash[playerid];
}
//===========================================//
//Public Time/Date.
public time()
{
// HOURS
new hour,minute,second;
gettime(hour,minute,second);
new string[256];
new string2[256];
if (minute <= 9)
{
format(string,25,"%d:0%d",hour,minute);
}
else
{
format(string,25,"%d:%d",hour,minute);
}
// DATE
new day,month,year;
getdate(year,month,day);
if (day <= 9){
format(string2,25,"0%d.%d.%d",day,month,year);
}
else if (month <= 9 && day >= 9) {
format(string2,25,"%d.0%d.%d",day,month,year);
}
else
{
format(string2,25,"%d.%d.%d",day,month,year);
}
if (hour == 0){SetWorldTime(0);}
if (hour == 1){SetWorldTime(1);}
if (hour == 2){SetWorldTime(2);}
if (hour == 3){SetWorldTime(3);}
if (hour == 4){SetWorldTime(4);}
if (hour == 5){SetWorldTime(5);}
if (hour == 6){SetWorldTime(6);}
if (hour == 7){SetWorldTime(7);}
if (hour == 8){SetWorldTime(8);}
if (hour == 9){SetWorldTime(9);}
if (hour == 10){SetWorldTime(10);}
if (hour == 11){SetWorldTime(11);}
if (hour == 12){SetWorldTime(12);}
if (hour == 13){SetWorldTime(13);}
if (hour == 14){SetWorldTime(14);}
if (hour == 15){SetWorldTime(15);}
if (hour == 16){SetWorldTime(16);}
if (hour == 17){SetWorldTime(17);}
if (hour == 18){SetWorldTime(18);}
if (hour == 19){SetWorldTime(19);}
if (hour == 20){SetWorldTime(20);}
if (hour == 21){SetWorldTime(21);}
if (hour == 22){SetWorldTime(22);}
if (hour == 23){SetWorldTime(23);}
if (hour == 24){SetWorldTime(24);}
for(new i=0;i<MAX_PLAYERS;++i)
{
TextDrawHideForPlayer(i,Clock);
TextDrawHideForPlayer(i,Date);
TextDrawSetString(Clock,string);
TextDrawSetString(Date,string2);
TextDrawShowForPlayer(i,Clock);
TextDrawShowForPlayer(i,Date);
}
return 1;
}
//=================================================//
//Public OnPlayerConnect.
public OnPlayerConnect(playerid)
{
new pname[MAX_PLAYER_NAME], string[63 + MAX_PLAYER_NAME];
SendClientMessage(playerid,COLOR_GREEN,"Welcome to San Andreas ");
SendClientMessage(playerid,COLOR_GREEN,"Make sure you read and Abide by our /rules, and obey our admins.");
TogglePlayerClock(playerid, 0);
PlayerInfo[playerid][pAdminLevel] = 0;
PlayerInfo[playerid][pCash] = 0;
GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
PlayerInfo[playerid][pScore] = 0;
SetPlayerScore(playerid, PlayerInfo[playerid][pScore]);
PlayerInfo[playerid][pKills] = 0;
PlayerInfo[playerid][pDeaths] = 0;
if(fexist(UserPath(playerid)))
{
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"{F81414}San Andreas ","{FFFFFF}Welcome back to the server, Please type your password below to login.\n\n{F81414}Please relog with a different username if that's not your account.","Login","Quit");
}
else
{
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,"{F81414}San Andreas ,"{FFFFFF}Welcome, Please type your password below to register a new account.","Register","Quit");
}
GetPlayerName(playerid, pname, sizeof(pname));
format(string, sizeof(string), "%s has joined the server.", pname);
SendClientMessageToAll(COLOR_CYAN, string);
return 1;
}
//================================================================================//
//Public OnPlayerDisconnect.
public OnPlayerDisconnect(playerid, reason)
{
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"Player's Data");
INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
INI_WriteInt(File,"Score",GetPlayerScore(playerid));
INI_WriteInt(File,"AdminLevel",PlayerInfo[playerid][pAdminLevel]);
INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
INI_WriteInt(File,"Banned",PlayerInfo[playerid][pBanned]);
INI_Close(File);
ResetVariables(playerid);
new pname[MAX_PLAYER_NAME], string[63 + MAX_PLAYER_NAME];
GetPlayerName(playerid, pname, sizeof(pname));
format(string, sizeof(string), "%s has Left the server.", pname, aDisconnectNames[reason]);
SendClientMessageToAll(COLOR_CYAN, string);
return 1;
}
//=========================================================//
//Public OnPlayerDeath.
public OnPlayerDeath(playerid, killerid)
{
PlayerInfo[killerid][pKills]++;
PlayerInfo[playerid][pDeaths]++;
PlayerInfo[playerid][pCash] = GetPlayerMoney(playerid);
if(gTeam[playerid] == TEAM_CIVIL)
{
SetPlayerInterior(playerid,0);
SetPlayerPos(playerid,2004.93,1544.25,13.59);
SetPlayerFacingAngle(playerid,270.0);
SetPlayerToTeamColour(playerid);
new mrand =random(50000);
GivePlayerMoney(playerid,-mrand);
}
if(gTeam[playerid] == TEAM_COP)
{
SetPlayerInterior(playerid,0);
SetPlayerPos(playerid,2281.53,2425.36,3.48);
SetPlayerFacingAngle(playerid,0.0);
SetPlayerToTeamColour(playerid);
new mrand =random(30000);
GivePlayerMoney(playerid,-mrand);
}
if(gTeam[playerid] == TEAM_ARMY)
{
SetPlayerInterior(playerid,0);
SetPlayerPos(playerid,278.17,1989.68,17.64);
SetPlayerFacingAngle(playerid,270.0);
SetPlayerToTeamColour(playerid);
new mrand =random(10000);
GivePlayerMoney(playerid,-mrand);
}
if(gTeam[playerid] == TEAM_CIA)
{
SetPlayerInterior(playerid,0);
SetPlayerPos(playerid,2228.01,2457.64,-7.45);
SetPlayerFacingAngle(playerid,90.0);
SetPlayerToTeamColour(playerid);
new mrand =random(20000);
GivePlayerMoney(playerid,-mrand);
}
if(gTeam[playerid] == TEAM_MEDIC)
{
SetPlayerInterior(playerid,0);
SetPlayerPos(playerid,1607.42,1823.57,10.82);
SetPlayerFacingAngle(playerid,0.0);
SetPlayerToTeamColour(playerid);
SetPlayerPos(playerid,1754.43,2072.12,10.82);
SetPlayerFacingAngle(playerid,180.0);
SetPlayerToTeamColour(playerid);
new mrand =random(20000);
GivePlayerMoney(playerid,-mrand);
}
return 1;
}
//=========================================================//
That's the first Question.
Second, I'm using this GPS System.
http://forum.sa-mp.com/showthread.ph...73#post2080873
Everything is working fine, but the Dialog DIALOG_GPS is not showing, even I defined it.
Some Codes..
pawn Код:
new GPS = 0;
new gpsstr[256];
new GPS_Activated[MAX_PLAYERS] = 0;
//=====================================================//
//GPS.
enum gInfo
{
gName[128],
Float:gX,
Float:gY,
Float:gZ
}
new GPSInfo[MAX_GPS][gInfo];
//===============================================//
//Stock AddGPS.
stock AddGPS(name[], Float:x, Float:y, Float:z)
{
GPS++;
format(GPSInfo[GPS][gName],256,"%s",name);
GPSInfo[GPS][gX] = x;
GPSInfo[GPS][gY] = y;
GPSInfo[GPS][gZ] = z;
return 1;
}
//================================================//
//Public ResetVariables.
public ResetVariables(playerid)
{
GPS_Activated[playerid] = 0;
}
//===================================================//
//Public OnFilterScriptInit
public OnFilterScriptInit()
{
print("GPS System successfuly loaded!");
AddGPS("Las Venturas Police Departement", 2289.99,2418.84,10.39);
AddGPS("Las Venturas Fuckyea.", 2289.99,2418.84,10.39);
for(new i = 0; i < GPS+1; ++i)
{
if(i != 0)
{
if(i == 1) format(gpsstr,256,"%s\n",GPSInfo[i][gName]);
if(i != 1) format(gpsstr,256,"%s%s\n",gpsstr,GPSInfo[i][gName]);
}
}
return 1;
}
//=================================================//
public OnPlayerEnterCheckpoint(playerid)
{
if(GPS_Activated[playerid] == 1)
{
SendClientMessage(playerid, COLOR_GREEN, "[GPS]:You have arrived at your destenation.");
DisablePlayerCheckpoint(playerid);
GPS_Activated[playerid] = 0;
}
return 1;
}
//==========================================//
//Public OnDialogResponse.
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
new pname[MAX_PLAYER_NAME], string[63 + MAX_PLAYER_NAME];
switch(dialogid)
{
case DIALOG_GPS:
{
if(!response) return 1;
if(listitem == GPS+1) return 1;
SetPlayerCheckpoint(playerid, GPSInfo[listitem+1][gX], GPSInfo[listitem+1][gY], GPSInfo[listitem+1][gZ],5.0);
GPS_Activated[playerid] = 1;
}
}
return 1;
}
//===============================================//
dcmd_gps(playerid,params[])
{
#pragma unused params
if(GPS_Activated[playerid] == 1) return SendClientMessage(playerid, COLOR_RED, "[GPS] Your GPS is already on.");
if(!IsPlayerInAnyVehicle(playerid))
{
SendClientMessage(playerid, COLOR_RED, "[GPS] You must be in a vehicle to use this command.");
GPS_Activated[playerid] = 0;
}
if(IsPlayerInAnyVehicle(playerid))
{
SendClientMessage(playerid, COLOR_GREEN,"[GPS] You have turned on your GPS.");
ShowPlayerDialog(playerid, DIALOG_GPS, DIALOG_STYLE_LIST, "GPS:", gpsstr, "Choose", "Cancel");
GPS_Activated[playerid] = 1;
}
return 1;
}
//============================================================================//
dcmd_gpsoff(playerid,params[])
{
#pragma unused params
if(GPS_Activated[playerid] == 0) return SendClientMessage(playerid, COLOR_RED, "[GPS] Your GPS isn't turned on.");
if(GPS_Activated[playerid] == 1)
{
DisablePlayerCheckpoint(playerid);
SendClientMessage(playerid, COLOR_GREEN, "[GPS] You have turned off your GPS.");
GPS_Activated[playerid] = 0;
}
return 1;
}
//===========================================================================//
No compiling error at all..
So any help?
Re: Two Big/Long questions -
Unte99 - 27.08.2012
In my opinion, there are two best ways to save the status in this situation:
1) saving the status when money is given to someone
2) using a timer
As for the other question, you didn't tell what the command says after you enter it.
Re: Two Big/Long questions -
Kh4led - 27.08.2012
First, Could you please post a script of a money saving timer that suits my script.
Second, It's in the script. Sends "GPS: Your GPS has been activated" and ShowPlayerDialog.
But the Dialog doesn't show.
NOTE: To add GPS Destinations, I add to OnFilterScriptInit
as said in the GPS System Thread :
http://forum.sa-mp.com/showthread.ph...73#post2080873
pawn Код:
//Public OnFilterScriptInit
public OnFilterScriptInit()
{
print("GPS System successfuly loaded!");
AddGPS("Las Venturas Police Departement", 2289.99,2418.84,10.39);
AddGPS("Las Venturas Fuckyea.", 2289.99,2418.84,10.39);
for(new i = 0; i < GPS+1; ++i)
{
if(i != 0)
{
if(i == 1) format(gpsstr,256,"%s\n",GPSInfo[i][gName]);
if(i != 1) format(gpsstr,256,"%s%s\n",gpsstr,GPSInfo[i][gName]);
}
}
return 1;
}
Sorry forgot to post it in main post, added now.
Solution?
Bump: Anyone?
Re: Two Big/Long questions -
Kh4led - 27.08.2012
REMOVED
Re: Two Big/Long questions -
Kh4led - 27.08.2012
Someone alive?
Re: Two Big/Long questions -
Kh4led - 27.08.2012
Another Bump, someone?