Hi Guys ..want to save the driver license
#1

Hi ...
I found this register / save script time ago and now I want to save
the Driver License that is got by my Command "/getdriverlicense"..
it contains
Код:
DriverLicense[playerid] = 1;
And also I defined it

Код:
new DriverLicense[MAX_PLAYERS];
I put it in my GameMode like this


Код:
  new idx;
  cmd = strtok(cmdtext, idx);
 	new tmp[256];
  new playername[MAX_PLAYER_NAME];
  if (strcmp(cmd, "/login", true) ==0 )
	{
	  if(IsPlayerConnected(playerid))
	  {
	    new tmppass[160];
			if(LoggedIn[playerid] == 1)
			{
				SendClientMessage(playerid, COLOR_GREY, "You Are Already Logged In.");
				return 1;
			}
			tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_GREY, "USAGE: /login [password]");
				return 1;
			}
			strmid(tmppass, tmp, 0, strlen(cmdtext), 300);
			Encrypt(tmppass);
			OnPlayerLogin(playerid,tmppass);
		}
		return 1;
	}
	if (strcmp(cmd, "/register", true)==0)
	{
		//new string[265];
		tmp = strtok(cmdtext, idx);
		if(!strlen(tmp))
		{
			SendClientMessage(playerid, COLOR_GREY, "USAGE: /register [password]");
			return 1;
		}
		if (PAccount[playerid] == 1)
		{
			SendClientMessage(playerid, COLOR_GREY, "That Name Is Already Registered");
			return 1;
		}

		strmid(PlayerInfo[playerid][pPassword], tmp, 0, strlen(cmdtext), 300);
		Encrypt(PlayerInfo[playerid][pPassword]);
		GetPlayerName(playerid, playername, sizeof(playername));
		format(string, sizeof(string), "%s.txt", playername);
		new File: file = fopen(string, io_read);
		if (file)
		{
			SendClientMessage(playerid, COLOR_GREY, "That Name Is Already Registered");
			fclose(file);
			return 1;
		}
		new File:hFile;
		hFile = fopen(string, io_append);
		new var[32];//
    format(var, 32, "%s\n", PlayerInfo[playerid][pPassword]);fwrite(hFile, var);
    format(var, 32, "Kills=%d\n",PlayerInfo[playerid][pKills]);fwrite(hFile, var);
    format(var, 32, "Deaths=%d\n",PlayerInfo[playerid][pDeaths]);fwrite(hFile, var);
    PlayerInfo[playerid][pCash] = GetPlayerMoney(playerid);
    format(var, 32, "Money=%d\n",PlayerInfo[playerid][pCash]);fwrite(hFile, var);
    
    format(var, 32, "DrivingLicense=%d\n",DrivingLicense[playerid]);fwrite(hFile, var);
    
		fclose(hFile);
		SendClientMessage(playerid, COLOR_YELLOW, "You Have Registered!");
		OnPlayerLogin(playerid,PlayerInfo[playerid][pPassword]);
		return 1;
	}
Код:
public Encrypt(string[])
{
	for(new x=0; x < strlen(string); x++)
	 {
		 string[x] += (3^x) * (x % 15);
		 if(string[x] > (0xff))
		 {
			 string[x] -= 64;
		 }
	 }
	return 1;
}


public OnPlayerLogin(playerid,const string[])
{
  new pname2[MAX_PLAYER_NAME];
	new pname3[MAX_PLAYER_NAME];
	new string2[100];
	new string3[160];
	GetPlayerName(playerid, pname2, sizeof(pname2));
	format(string2, sizeof(string2), "%s.txt", pname2);
	new File: UserFile = fopen(string2, io_read);

	if (UserFile)
	{
		new valtmp[160];
		fread(UserFile, valtmp);strmid(PlayerInfo[playerid][pPassword], valtmp, 0, strlen(valtmp)-1, 300);

		if ((strcmp(PlayerInfo[playerid][pPassword], string, true, strlen(valtmp)-1) == 0))
		{
			new key[160],val[160];
 			new Data[160];
 			while(fread(UserFile,Data,sizeof(Data)))
			{
				key = ini_GetKey(Data);
        if( strcmp( key , "Kills" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pKills] = strval( val ); }
        if( strcmp( key , "Deaths" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pDeaths] = strval( val ); }
        if( strcmp( key , "Money" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pCash] = strval( val ); }

				if( strcmp( key , "License",true ) == 0 ) { val = ini_GetValue( Data ); DrivingLicense[playerid] = strval( val ); }

				GivePlayerMoney(playerid,PlayerInfo[playerid][pCash]);
			}
			fclose(UserFile);
			LoggedIn[playerid] = 1;
			PAccount[playerid] = 1;
		  new kills = PlayerInfo[playerid][pKills];
      SetPlayerScore(playerid, kills);
			GetPlayerName(playerid, pname3, sizeof(pname3));
			format(string3, sizeof(string3), "What's Up %s", pname3);
			SendClientMessage(playerid, COLOR_YELLOW,string3);
		}
		else
		{
			SendClientMessage(playerid, COLOR_RED, "Password Does Not Match Your Name");
			fclose(UserFile);
		}
	}
	return 1;
}

public OnPlayerUpdate(playerid)
{
	if(IsPlayerConnected(playerid))
	{
		if(LoggedIn[playerid])
		{
			new string3[32];
			new pname3[MAX_PLAYER_NAME];
			GetPlayerName(playerid, pname3, sizeof(pname3));
			format(string3, sizeof(string3), "%s.txt", pname3);
			new File: pFile = fopen(string3, io_write);
			if (pFile)
			{
				new var[32];
				format(var, 32, "%s\n", PlayerInfo[playerid][pPassword]);fwrite(pFile, var);
				fclose(pFile);
				new File: hFile = fopen(string3, io_append);
				PlayerInfo[playerid][pCash] = GetPlayerMoney(playerid);
				format(var, 32, "Kills=%d\n",PlayerInfo[playerid][pKills]);fwrite(hFile, var);
				format(var, 32, "Deaths=%d\n",PlayerInfo[playerid][pDeaths]);fwrite(hFile, var);
				format(var, 32, "Money=%d\n",PlayerInfo[playerid][pCash]);fwrite(hFile, var);
				//
				format(var, 32, "DrivingLicense=%d\n",DrivingLicense[playerid]);fwrite(hFile, var);

				fclose(hFile);
			}
		}
	}
	return 1;
}

stock ini_GetKey( line[] )
{
	new keyRes[160];
	keyRes[0] = 0;
  if ( strfind( line , "=" , true ) == -1 ) return keyRes;
  strmid( keyRes , line , 0 , strfind( line , "=" , true ) , sizeof( keyRes) );
  return keyRes;
}

stock ini_GetValue( line[] )
{
	new valRes[160];
	valRes[0]=0;
	if ( strfind( line , "=" , true ) == -1 ) return valRes;
	strmid( valRes , line , strfind( line , "=" , true )+1 , strlen( line ) , sizeof( valRes ) );
	return valRes;
}
But It doesn't save The Driving License ...

Here my command

Код:
  if(strcmp("/getdriverlicense",cmdtext,true) == 0)
  {
  GivePlayerMoney(playerid,-2000);
  SetPlayerPos(playerid,-2026.4285,-98.0583,35.1641);
  SetPlayerInterior(playerid,0);

  SendClientMessage(playerid,COLOR_YELLOW,"Alright you made Your Driving License");
  SendClientMessage(playerid,COLOR_YELLOW,"Now you are able to Drive Cars and Bikes!");

  GameTextForPlayer(playerid,"~r~You Have Payed 2000$ For Your Driving License!",2000,0);

  DrivingLicense[playerid] += 1;
  return 1;
	}
Hope someone read this and help me...

PS: I Have no warnings or errors!


Bearfist
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)