11.01.2013, 11:32
i made an saving/register script for my server with tutorial. and added some stuff now it saves like this.
PHP код:
Admin = 0
Kills = 0
Deaths = 0
Level = 0
Vw = 0
WEAPON 1 = 0
WEAPON AMMU 1 = 0
WEAPON 2 = 0
WEAPON AMMU 2 = 0
WEAPON 3 = 0
WEAPON AMMU 3 = 0
WEAPON 4 = 0
WEAPON AMMU 4 = 0
WEAPON 5 = 0
WEAPON AMMU 5 = 0
WEAPON 6 = 0
WEAPON AMMU 6 = 0
WEAPON 7 = 0
WEAPON AMMU 7 = 0
WEAPON 8 = 0
WEAPON AMMU 8 = 0
[data]
Password = 241828579
Health = 0.000000
Armour = 0.000000
Cash = 0
Admin = 0
Kills = 0
Deaths = 0
Skin = 0
Level = 0
Pos_x = 0
Pos_y = 0
Pos_z = 0
Vw = 0
WEAPON 1 = 0
WEAPON AMMU 1 = 0
WEAPON 2 = 0
WEAPON AMMU 2 = 0
WEAPON 3 = 0
WEAPON AMMU 3 = 0
WEAPON 4 = 0
WEAPON AMMU 4 = 0
WEAPON 5 = 0
WEAPON AMMU 5 = 0
WEAPON 6 = 0
WEAPON AMMU 6 = 0
WEAPON 7 = 0
WEAPON AMMU 7 = 0
WEAPON 8 = 0
WEAPON AMMU 8 = 0
PHP код:
#include <YSI\y_ini>
#include <zcmd>
#include <sscanf2>
#include <a_samp>
#include <fly>
#define PATH "TeroAdmin/Users/%s.ini"
#define DIALOG_REGISTER 1
#define DIALOG_LOGIN 2
#define DIALOG_SUCCESS_1 3
#define DIALOG_SUCCESS_2 4
#define COL_WHITE "{FFFFFF}"
#define COL_RED "{F81414}"
#define COL_GREEN "{00FF22}"
#define COL_LIGHTBLUE "{00CED1}"
#define COLOR_GREY 0xAFAFAFAA
#define COLOR_GREEN 0x33AA33AA
#define COLOR_RED 0xAA3333AA
#define COLOR_YELLOW 0xFFFF00AA
#define COLOR_WHITE 0xFFFFFFAA
#define COLOR_BLUE 0x0000BBAA
#define COLOR_LIGHTBLUE 0x33CCFFAA
#define COLOR_ORANGE 0xFF9900AA
#define COLOR_RED 0xAA3333AA
#define COLOR_LIME 0x10F441AA
#define COLOR_MAGENTA 0xFF00FFFF
#define COLOR_NAVY 0x000080AA
#define COLOR_AQUA 0xF0F8FFAA
#define COLOR_CRIMSON 0xDC143CAA
#define COLOR_FLBLUE 0x6495EDAA
#define COLOR_BISQUE 0xFFE4C4AA
#define COLOR_BLACK 0x000000AA
#define COLOR_CHARTREUSE 0x7FFF00AA
#define COLOR_BROWN 0XA52A2AAA
#define COLOR_CORAL 0xFF7F50AA
#define COLOR_GOLD 0xB8860BAA
#define COLOR_GREENYELLOW 0xADFF2FAA
#define COLOR_INDIGO 0x4B00B0AA
#define COLOR_IVORY 0xFFFF82AA
#define COLOR_LAWNGREEN 0x7CFC00AA
#define COLOR_SEAGREEN 0x20B2AAAA
#define COLOR_LIMEGREEN 0x32CD32AA //<--- Dark lime
#define COLOR_MIDNIGHTBLUE 0X191970AA
#define COLOR_MAROON 0x800000AA
#define COLOR_OLIVE 0x808000AA
#define COLOR_ORANGERED 0xFF4500AA
#define COLOR_PINK 0xFFC0CBAA // - Light light pink
#define COLOR_SPRINGGREEN 0x00FF7FAA
#define COLOR_TOMATO 0xFF6347AA // - Tomato >:/ sounds wrong lol... well... :P
#define COLOR_YELLOWGREEN 0x9ACD32AA //- like military green
#define COLOR_MEDIUMAQUA 0x83BFBFAA
#define COLOR_MEDIUMMAGENTA 0x8B008BAA // dark magenta ^^
stock PlayerName(playerid)
{
new pName[25];
GetPlayerName(playerid, pName, sizeof(pName));
return pName;
}
enum pInfo
{
pPass,
Float:pHealth,
Float:pArmour,
pCash,
pAdmin,
pKills,
pDeaths,
pSkin,
pLevel,
pPos_x,
pPos_y,
pPos_z,
pVw,
pW1,
pWam1,
pW2,
pWam2,
pW3,
pWam3,
pW4,
pWam4,
pW5,
pWam5,
pW6,
pWam6,
pW7,
pWam7,
pW8,
pWam8
}
new PlayerInfo[MAX_PLAYERS][pInfo];
forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
INI_Int("Password",PlayerInfo[playerid][pPass]);
INI_Int("Health",PlayerInfo[playerid][pArmour]);
INI_Int("Armour",PlayerInfo[playerid][pHealth]);
INI_Int("Cash",PlayerInfo[playerid][pCash]);
INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
INI_Int("Kills",PlayerInfo[playerid][pKills]);
INI_Int("Deaths",PlayerInfo[playerid][pDeaths]);
INI_Int("Skin",PlayerInfo[playerid][pSkin]);
INI_Int("Level",PlayerInfo[playerid][pLevel]);
INI_Int("Pos_x",PlayerInfo[playerid][pPos_x]);
INI_Int("Pos_y",PlayerInfo[playerid][pPos_y]);
INI_Int("Pos_z",PlayerInfo[playerid][pPos_z]);
INI_Int("Vw",PlayerInfo[playerid][pVw]);
INI_Int("WEAPON 1",PlayerInfo[playerid][pW1]);
INI_Int("WEAPON AMMU 1",PlayerInfo[playerid][pWam1]);
INI_Int("WEAPON 2",PlayerInfo[playerid][pW2]);
INI_Int("WEAPON AMMU 2",PlayerInfo[playerid][pWam2]);
INI_Int("WEAPON 3",PlayerInfo[playerid][pW3]);
INI_Int("WEAPON AMMU 3",PlayerInfo[playerid][pWam3]);
INI_Int("WEAPON 4",PlayerInfo[playerid][pW4]);
INI_Int("WEAPON AMMU 4",PlayerInfo[playerid][pWam4]);
INI_Int("WEAPON 5",PlayerInfo[playerid][pW5]);
INI_Int("WEAPON AMMU 5",PlayerInfo[playerid][pWam5]);
INI_Int("WEAPON 6",PlayerInfo[playerid][pW6]);
INI_Int("WEAPON AMMU 6",PlayerInfo[playerid][pWam6]);
INI_Int("WEAPON 7",PlayerInfo[playerid][pW7]);
INI_Int("WEAPON AMMU 7",PlayerInfo[playerid][pWam7]);
INI_Int("WEAPON 8",PlayerInfo[playerid][pW8]);
INI_Int("WEAPON AMMU 8",PlayerInfo[playerid][pWam8]);
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;
}
public OnPlayerConnect(playerid)
{
InitFly(playerid);
if(fexist(UserPath(playerid)))
{
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COL_WHITE"Login",""COL_WHITE"Type your password below to login.","Login","Quit");
}
else
{
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,""COL_WHITE"Registering...",""COL_WHITE"Type your password below to register a new account.","Register","Quit");
}
return 1;
}
//------------------------------------------------------------------------
//------------------------------------------------------------------------
//------------------------------------------------------------------------
//commandz
//------------------------------------------------------------------------
//------------------------------------------------------------------------
//------------------------------------------------------------------------
CMD:clearchat(playerid,params[])
{
if( PlayerInfo[ playerid ][ pAdmin ] < 1 ) return SendClientMessage( playerid, COLOR_RED, "ERROR: You must be level 1 to use this command!" );
{
for( new i = 0; i <= 100; i ++ ) SendClientMessageToAll( COLOR_WHITE, "" );
} return 1;
}
CMD:fly(playerid, params[])
{
if(PlayerInfo[playerid][pAdmin] >= 2)
{
StartFly(playerid);
}
return 1;
}
CMD:stopfly(playerid, params[])
{
if(PlayerInfo[playerid][pAdmin] >= 2)
{
StopFly(playerid);
}
return 1;
}
CMD:kick(playerid, params[])
{
if(PlayerInfo[playerid][pAdmin] >= 3) {
new PID; //define the playerid we wanna kick
new reason[64]; //the reason, put into a string
new str[128]; //a new message string
new Playername[MAX_PLAYER_NAME], Adminname[MAX_PLAYER_NAME]; //defines the function with the playername we wanna get
GetPlayerName(playerid, Adminname, sizeof(Adminname)); //defines the function with the adminname we wanna get
GetPlayerName(PID, Playername, sizeof(Playername));
if(sscanf(params, "us[64]", PID,reason)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /kick [playerid] [reason]"); //tell sscanf if the parameters/the syntax is written wrong to return a message (PID and the reason used here)
if(!IsPlayerConnected(PID)) // if the ID is wrong or not connected, return a message! (PID used here)
return SendClientMessage(playerid, COLOR_GREY, "Player is not connected!");
format(str, sizeof(str), "'%s' has been kicked by administrator '%s'. Reason: %s ", Playername, Adminname, reason); //format the string we've defined to send the message, playername and adminname are used to receive the information about the names
SendClientMessageToAll(COLOR_RED, str); //send that message to all
Kick(PID); //kick the playerid we've defined
}
else //if he has not got the permissions
{
SendClientMessage(playerid, COLOR_GREY, "You have to be level 3 to use that command!"); //return this message
}
return 1;
}
CMD:ban(playerid, params[])
{
if(PlayerInfo[playerid][pAdmin] >= 3) {
new PID; //define the playerid we wanna ban
new reason[64]; //the reason, put into a string
new str[128]; //a new message string
new Playername[MAX_PLAYER_NAME], Adminname[MAX_PLAYER_NAME]; //defines the function with the playername we wanna get
GetPlayerName(playerid, Adminname, sizeof(Adminname)); //defines the function with the adminname we wanna get
GetPlayerName(PID, Playername, sizeof(Playername));
if(sscanf(params, "us[64]", PID,reason)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /kick [playerid] [reason]"); //tell sscanf if the parameters/the syntax is written wrong to return a message (PID and the reason used here)
if(!IsPlayerConnected(PID)) // if the ID is wrong or not connected, return a message! (PID used here)
return SendClientMessage(playerid, COLOR_GREY, "Player is not connected!");
format(str, sizeof(str), "'%s' has been banned by administrator '%s'. Reason: %s ", Playername, Adminname, reason); //format the string we've defined to send the message, playername and adminname are used to receive the information about the names
SendClientMessageToAll(COLOR_RED, str); //send that message to all
Ban(PID); //Ban the playerid we've defined
}
else //if he has not got the permissions
{
SendClientMessage(playerid, COLOR_GREY, "You have to be level 5 to use that command!"); //return this message
}
return 1;
}
//------------------------------------------------------------------------
//------------------------------------------------------------------------
//------------------------------------------------------------------------
//end of commandz
//------------------------------------------------------------------------
//------------------------------------------------------------------------
//------------------------------------------------------------------------
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch( dialogid )
{
case DIALOG_REGISTER:
{
if (!response) return Kick(playerid);
if(response)
{
if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""COL_WHITE"Registering...",""COL_RED"You have entered an invalid password.\n"COL_WHITE"Type your password below to register a new account.","Register","Quit");
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"data");
INI_WriteInt(File,"Password",udb_hash(inputtext));
INI_WriteFloat(File,"Health",0);
INI_WriteFloat(File,"Armour",0);
INI_WriteInt(File,"Cash",0);
INI_WriteInt(File,"Admin",0);
INI_WriteInt(File,"Kills",0);
INI_WriteInt(File,"Deaths",0);
INI_WriteInt(File,"Skin",0);
INI_WriteInt(File,"Level",0);
INI_WriteInt(File,"Pos_x",0);
INI_WriteInt(File,"Pos_y",0);
INI_WriteInt(File,"Pos_z",0);
INI_WriteInt(File,"Vw",GetPlayerVirtualWorld(playerid));
INI_WriteInt(File,"WEAPON 1",PlayerInfo[playerid][pW1]);
INI_WriteInt(File,"WEAPON AMMU 1",PlayerInfo[playerid][pWam1]);
INI_WriteInt(File,"WEAPON 2",PlayerInfo[playerid][pW2]);
INI_WriteInt(File,"WEAPON AMMU 2",PlayerInfo[playerid][pWam2]);
INI_WriteInt(File,"WEAPON 3",PlayerInfo[playerid][pW3]);
INI_WriteInt(File,"WEAPON AMMU 3",PlayerInfo[playerid][pWam3]);
INI_WriteInt(File,"WEAPON 4",PlayerInfo[playerid][pW4]);
INI_WriteInt(File,"WEAPON AMMU 4",PlayerInfo[playerid][pWam4]);
INI_WriteInt(File,"WEAPON 5",PlayerInfo[playerid][pW5]);
INI_WriteInt(File,"WEAPON AMMU 5",PlayerInfo[playerid][pWam5]);
INI_WriteInt(File,"WEAPON 6",PlayerInfo[playerid][pW6]);
INI_WriteInt(File,"WEAPON AMMU 6",PlayerInfo[playerid][pWam6]);
INI_WriteInt(File,"WEAPON 7",PlayerInfo[playerid][pW7]);
INI_WriteInt(File,"WEAPON AMMU 7",PlayerInfo[playerid][pWam7]);
INI_WriteInt(File,"WEAPON 8",PlayerInfo[playerid][pW8]);
INI_WriteInt(File,"WEAPON AMMU 8",PlayerInfo[playerid][pWam8]);
INI_Close(File);
SetSpawnInfo(playerid, 0, 0, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0);
SpawnPlayer(playerid);
ShowPlayerDialog(playerid, DIALOG_SUCCESS_1, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"Welcome to LS Streets RP Have Fun!","Ok","");
}
}
case DIALOG_LOGIN:
{
if ( !response ) return Kick ( playerid );
if( response )
{
if(udb_hash(inputtext) == PlayerInfo[playerid][pPass])
{
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
SetPlayerArmour(playerid,PlayerInfo[playerid][pArmour]);
SetPlayerHealth(playerid,PlayerInfo[playerid][pHealth]);
SetPlayerSkin(playerid, PlayerInfo[playerid][pSkin]);
GetPlayerPos(playerid,PlayerInfo[playerid][pPos_x],PlayerInfo[playerid][pPos_y],PlayerInfo[playerid][pPos_z]);
SetPlayerVirtualWorld(playerid,PlayerInfo[playerid][pVw]);
GivePlayerWeapon(playerid,PlayerInfo[playerid][pW1],PlayerInfo[playerid][pWam1]);
GivePlayerWeapon(playerid,PlayerInfo[playerid][pW2],PlayerInfo[playerid][pWam2]);
GivePlayerWeapon(playerid,PlayerInfo[playerid][pW3],PlayerInfo[playerid][pWam3]);
GivePlayerWeapon(playerid,PlayerInfo[playerid][pW4],PlayerInfo[playerid][pWam4]);
GivePlayerWeapon(playerid,PlayerInfo[playerid][pW5],PlayerInfo[playerid][pWam5]);
GivePlayerWeapon(playerid,PlayerInfo[playerid][pW6],PlayerInfo[playerid][pWam6]);
GivePlayerWeapon(playerid,PlayerInfo[playerid][pW7],PlayerInfo[playerid][pWam7]);
GivePlayerWeapon(playerid,PlayerInfo[playerid][pW8],PlayerInfo[playerid][pWam8]);
ShowPlayerDialog(playerid, DIALOG_SUCCESS_2, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"You have successfully logged in!","Ok","");
}
else
{
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COL_WHITE"Login",""COL_RED"You have entered an incorrect password.\n"COL_WHITE"Type your password below to login.","Login","Quit");
}
return 1;
}
}
}
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
new
Float:x,
Float:y,
Float:z
;
PlayerInfo[playerid][pSkin] = GetPlayerSkin(playerid);
PlayerInfo[playerid][pCash] = GivePlayerMoney(playerid);
GetPlayerHealth(playerid,PlayerInfo[playerid][pHealth]);
GetPlayerArmour(playerid,PlayerInfo[playerid][pArmour]);
GetPlayerWeaponData(playerid,1,PlayerInfo[playerid][pW1],PlayerInfo[playerid][pWam1]);
GetPlayerWeaponData(playerid,2,PlayerInfo[playerid][pW2],PlayerInfo[playerid][pWam2]);
GetPlayerWeaponData(playerid,3,PlayerInfo[playerid][pW3],PlayerInfo[playerid][pWam3]);
GetPlayerWeaponData(playerid,4,PlayerInfo[playerid][pW4],PlayerInfo[playerid][pWam4]);
GetPlayerWeaponData(playerid,5,PlayerInfo[playerid][pW5],PlayerInfo[playerid][pWam5]);
GetPlayerWeaponData(playerid,6,PlayerInfo[playerid][pW6],PlayerInfo[playerid][pWam6]);
GetPlayerWeaponData(playerid,7,PlayerInfo[playerid][pW7],PlayerInfo[playerid][pWam7]);
GetPlayerWeaponData(playerid,8,PlayerInfo[playerid][pW8],PlayerInfo[playerid][pWam8]);
GetPlayerPos(playerid,x,y,z);
PlayerInfo[playerid][pPos_x] = x;
PlayerInfo[playerid][pPos_y] = y;
PlayerInfo[playerid][pPos_z] = z;
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"data");
INI_WriteFloat(File,"Health",PlayerInfo[playerid][pHealth]);
INI_WriteFloat(File,"Armour",PlayerInfo[playerid][pArmour]);
INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
INI_WriteInt(File,"Skin",PlayerInfo[playerid][pSkin]);
INI_WriteInt(File,"Level",PlayerInfo[playerid][pLevel]);
INI_WriteFloat(File,"Pos_x",PlayerInfo[playerid][pPos_x]);
INI_WriteFloat(File,"Pos_y",PlayerInfo[playerid][pPos_y]);
INI_WriteFloat(File,"Pos_z",PlayerInfo[playerid][pPos_z]);
INI_WriteInt(File,"Vw",GetPlayerVirtualWorld(playerid));
INI_WriteInt(File,"WEAPON 1",PlayerInfo[playerid][pW1]);
INI_WriteInt(File,"WEAPON AMMU 1",PlayerInfo[playerid][pWam1]);
INI_WriteInt(File,"WEAPON 2",PlayerInfo[playerid][pW2]);
INI_WriteInt(File,"WEAPON AMMU 2",PlayerInfo[playerid][pWam2]);
INI_WriteInt(File,"WEAPON 3",PlayerInfo[playerid][pW3]);
INI_WriteInt(File,"WEAPON AMMU 3",PlayerInfo[playerid][pWam3]);
INI_WriteInt(File,"WEAPON 4",PlayerInfo[playerid][pW4]);
INI_WriteInt(File,"WEAPON AMMU 4",PlayerInfo[playerid][pWam4]);
INI_WriteInt(File,"WEAPON 5",PlayerInfo[playerid][pW5]);
INI_WriteInt(File,"WEAPON AMMU 5",PlayerInfo[playerid][pWam5]);
INI_WriteInt(File,"WEAPON 6",PlayerInfo[playerid][pW6]);
INI_WriteInt(File,"WEAPON AMMU 6",PlayerInfo[playerid][pWam6]);
INI_WriteInt(File,"WEAPON 7",PlayerInfo[playerid][pW7]);
INI_WriteInt(File,"WEAPON AMMU 7",PlayerInfo[playerid][pWam7]);
INI_WriteInt(File,"WEAPON 8",PlayerInfo[playerid][pW8]);
INI_WriteInt(File,"WEAPON AMMU 8",PlayerInfo[playerid][pWam8]);
INI_Close(File);
return 1;
}
public OnPlayerSpawn(playerid)
{
return 1;
}
public OnPlayerDeath(playerid, killerid, reason)
{
PlayerInfo[killerid][pKills]++;
PlayerInfo[playerid][pDeaths]++;
return 1;
}