SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 07/06/2012, 07:48 PM   #1
Mikibey
Little Clucker
 
Join Date: May 2012
Posts: 37
Reputation: 0
Default How to check a value?

So basically i have this script:
Code:
	if(strcmp(cmd, "/givemoney", true) == 0)
    {
        new tmp[30];
        tmp = strtok(cmdtext, idx);
        new otherplayer = strval(tmp);

        if(IsPlayerConnected(otherplayer))
        {
            GivePlayerMoney(otherplayer, 50000);
        }
        return 1;
    }
and this enums:
Code:
enum pInfo
{
	Float:x,
	Float:y,
	Float:z,
	Float:a,
	Wep1,
	Wep2,
	Wep3,
	Wep4,
	Wep5,
	Wep6,
	Wep7,
	Wep8,
	Ammo1,
	Ammo2,
	Ammo3,
	Ammo4,
	Ammo5,
	Ammo6,
	Ammo7,
	Ammo8,
	Hour,
	Min,
	Password[MAX_PASS_SIZE+1],
	Logged,
	FalseLogins,
	Admin,      <------This one
}
I want my admin enum to be checked,and if its set to 1,in the user's dini file,then the command works,if its not then it will not work and it will give a message.
I must mention that my system is dini.(Yes it sucks but for starters like me its gold).

I just need the syntax for checking a value,in a dini user file.

Thanks for helping me
Mikibey is offline   Reply With Quote
Old 07/06/2012, 07:55 PM   #2
zDevon
Huge Clucker
 
Join Date: Jan 2012
Location: Charlotte, NC (USA)
Posts: 298
Reputation: 31
Default Re: How to check a value?

if(pInfo[playerid][Admin] == 1) from what I saw in a few Dini admin scripts. I use Y_INI, however.
zDevon is offline   Reply With Quote
Old 07/06/2012, 07:57 PM   #3
JhnzRep
Huge Clucker
 
JhnzRep's Avatar
 
Join Date: Jan 2012
Location: USA/Slovakia
Posts: 426
Reputation: 65
Default Re: How to check a value?

pawn Code:
if(PlayerInfo[playerid][Admin] < 1) return SendClientMessage(Blah blah blah)

The PlayerInfo might be different. For example pInfo.

It should be in the under your enum like this
pawn Code:
PlayerInfo[MAX_PLAYERS][pInfo]
JhnzRep is offline   Reply With Quote
Old 07/06/2012, 07:57 PM   #4
Mikibey
Little Clucker
 
Join Date: May 2012
Posts: 37
Reputation: 0
Default Re: How to check a value?

THANKS i will test both of them now,i hope one of them will work
Mikibey is offline   Reply With Quote
Old 07/06/2012, 08:07 PM   #5
Mikibey
Little Clucker
 
Join Date: May 2012
Posts: 37
Reputation: 0
Default Re: How to check a value?

Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
	new cmd[256];
	new idx;
	cmd = strtok(cmdtext, idx);
	format(file, sizeof(file), USERS_FILE, PlayerName(playerid));

	if(strcmp(cmd, "/givemoney", true) == 0)
    {
		{
		if(PlayerInfo[playerid][Admin] < 1) return SendClientMessage("Blah blah blah");
        new tmp[30];
        tmp = strtok(cmdtext, idx);
        new otherplayer = strval(tmp);

        if(IsPlayerConnected(otherplayer))
        {
            GivePlayerMoney(otherplayer, 50000);
        }
        return 1;
    }
}
so this is my code and i get...

Code:
C:\Users\Mihai\Desktop\Galaxy-Games\gamemodes\galaxygamesreallife.pwn(285) : error 035: argument type mismatch (argument 1)
Pawn compiler 3.2.3664	 	 	Copyright (c) 1997-2006, ITB CompuPhase


1 Error.
what did i do wrong?
Mikibey is offline   Reply With Quote
Old 07/06/2012, 08:10 PM   #6
JhnzRep
Huge Clucker
 
JhnzRep's Avatar
 
Join Date: Jan 2012
Location: USA/Slovakia
Posts: 426
Reputation: 65
Default Re: How to check a value?

Change SendClientMessage(blah blah blah)

with:

pawn Code:
SendClientMessage(playerid, -1, "You are not an admin!");
JhnzRep is offline   Reply With Quote
Old 07/06/2012, 08:15 PM   #7
Mikibey
Little Clucker
 
Join Date: May 2012
Posts: 37
Reputation: 0
Default Re: How to check a value?

thanks now it works
Mikibey is offline   Reply With Quote
Old 07/06/2012, 08:20 PM   #8
JhnzRep
Huge Clucker
 
JhnzRep's Avatar
 
Join Date: Jan 2012
Location: USA/Slovakia
Posts: 426
Reputation: 65
Default Re: How to check a value?

Great! If you need anymore help/explaining PM me!
__________________
[center]Creations:

[Tutorial]
Business System
JhnzRep is offline   Reply With Quote
Old 08/06/2012, 06:07 AM   #9
Mikibey
Little Clucker
 
Join Date: May 2012
Posts: 37
Reputation: 0
Default Re: How to check a value?

But now i have a problem,i have everything set,it compiles with no error,when you register it sets your "Admin" to 0,after that when i set it to 1 in dini,its saved but when i try the command in game it says that i am not an admin...even tho i set in the dini at Admin = 1 why could be wrong?
Mikibey is offline   Reply With Quote
Old 08/06/2012, 06:12 AM   #10
Mikibey
Little Clucker
 
Join Date: May 2012
Posts: 37
Reputation: 0
Default Re: How to check a value?

Here is my full code,maybie it will help at something?

please help me,if i learn this then i am going to a new level..i just need to learn how to insert a new dini value into the users config file,how to check if its set to 1,2,3 etc... and this is it
I never understanded how to add a new value,every time i add one everything goes into a mess...
Code:
// This is a comment
// uncomment the line below if you want to write a filterscript

#include <a_samp>
#include <dini>
#include <Sscanf>

#define RED                	0xF0182DFF
#define GREEN              	0x0FCD18FF
#define WHITE               0xFFFDFDFF
#define ORANGE              0xF6A113FF

#define FORCE_LOGIN         0                       //Force the player to login to spawn? Change to '1' to force login
#define USERS_FILE          "/Users/%s.ini"         //The directory of which the files will be saved
#define MAX_PASS_SIZE       16                      //The maximum password length
#define MIN_PASS_SIZE       4                       //The minimum password length
#define LOGIN_ATTEMPTS      3                       //The maximum allowed false login attempts before being kicked

#define KILLS_DEATHS        1
#define SKIN                1
#define CASH                1
#define SCORE               1
#define POSITION            1
#define WEAPONS             1 //May be slightly bugged
#define HEALTH              1
#define ARMOUR              1
#define DRUNK_LEVEL         1
#define FIGHT_STYLE         1
#define VIRTUAL_WORLD       0
#define PLAYER_TIME         1
#define WANTED_LEVEL        1
#define TEAM                0
#define CLOCK               0
#define ADMIN


#define USE_DIALOGS         1                       //Use dialogs? Change to '1' to use them

#define REGISTER            1
#define LOGIN               2
#define CHANGE_PASS         3
#define SetPlayerAdmin  ////////inca in lucru

enum pInfo
{
	Float:x,
	Float:y,
	Float:z,
	Float:a,
	Wep1,
	Wep2,
	Wep3,
	Wep4,
	Wep5,
	Wep6,
	Wep7,
	Wep8,
	Ammo1,
	Ammo2,
	Ammo3,
	Ammo4,
	Ammo5,
	Ammo6,
	Ammo7,
	Ammo8,
	Hour,
	Min,
	Password[MAX_PASS_SIZE+1],
	Logged,
	FalseLogins,
	Admin,
}

new PlayerInfo[MAX_PLAYERS][pInfo];
new file[128];
new str[256];


main()
{
	print("\n----------------------------------");
	print(" Blank Gamemode by your name here");
	print("----------------------------------\n");
}

public OnGameModeInit()
{
	ShowPlayerMarkers(0);
	return 1;
}

public OnGameModeExit()
{
	return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
    SetPlayerColor(playerid, WHITE);
	SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
	SetSpawnInfo(playerid, 0, 60, 1480.8102, -1758.8420, 17.5313, 342.1488, 0, 0, 0, 0, 0, 0);
	SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
	SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
	return 1;
}

public OnPlayerConnect(playerid)
{
	format(file, sizeof(file), USERS_FILE, PlayerName(playerid));
	if(!dini_Exists(file))
	{
	    #if USE_DIALOGS == 1
	    format(str, sizeof(str), "You do not have a registered account %s!\n\nPlease insert your desired password into the line below and click \"Submit\".\n\n Click \"Cancel\" to cancel registration.", PlayerName(playerid));
	    ShowPlayerDialog(playerid, REGISTER, DIALOG_STYLE_INPUT, "Register An Account", str, "Submit", "Cancel");
	    #elseif USE_DIALOGS == 0
	    SendClientMessage(playerid, WHITE, "Server: You do not have a registered account! Please register. (/register <password>)");
	    #endif
	}
	else
	{
	    #if USE_DIALOGS == 1
	    format(str, sizeof(str), "Welcome back %!Please login to your account.\n\nPlease insert your password into the line below and click \"Submit\". \n\n Click \"Cancel\" to cancel.", PlayerName(playerid));
	    ShowPlayerDialog(playerid, LOGIN, DIALOG_STYLE_INPUT, "Login to Your Account", str, "Submit", "Cancel");
		#elseif USE_DIALOGS == 0
		SendClientMessage(playerid, WHITE, "Server: You have a registered account! Please login or re-connect with a different name. (/login <password>)");
		#endif
	}
	return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
	format(file, sizeof(file), USERS_FILE, PlayerName(playerid));
	if(PlayerInfo[playerid][Logged] == 1)
	{
		#if SKIN == 1
		dini_IntSet(file, "Skin", GetPlayerSkin(playerid));
		#endif
		#if CASH == 1
		dini_IntSet(file, "Cash", GetPlayerMoney(playerid));
		#endif
		#if SCORE == 1
		dini_IntSet(file, "Score", GetPlayerScore(playerid));
		#endif
		#if POSITION == 1
		GetPlayerPos(playerid, PlayerInfo[playerid][x], PlayerInfo[playerid][y], PlayerInfo[playerid][z]);
		GetPlayerFacingAngle(playerid, PlayerInfo[playerid][a]);
		dini_FloatSet(file, "X", PlayerInfo[playerid][x]);
		dini_FloatSet(file, "Y", PlayerInfo[playerid][y]);
		dini_FloatSet(file, "Z", PlayerInfo[playerid][z]);
		dini_FloatSet(file, "A", PlayerInfo[playerid][a]);
		dini_IntSet(file, "Int", GetPlayerInterior(playerid));
		#endif
		#if WEAPONS == 1
		GetPlayerWeaponData(playerid, 0, PlayerInfo[playerid][Wep1], PlayerInfo[playerid][Ammo1]);
		GetPlayerWeaponData(playerid, 1, PlayerInfo[playerid][Wep2], PlayerInfo[playerid][Ammo2]);
		GetPlayerWeaponData(playerid, 2, PlayerInfo[playerid][Wep3], PlayerInfo[playerid][Ammo3]);
		GetPlayerWeaponData(playerid, 3, PlayerInfo[playerid][Wep4], PlayerInfo[playerid][Ammo4]);
		GetPlayerWeaponData(playerid, 4, PlayerInfo[playerid][Wep5], PlayerInfo[playerid][Ammo5]);
		GetPlayerWeaponData(playerid, 5, PlayerInfo[playerid][Wep6], PlayerInfo[playerid][Ammo6]);
		GetPlayerWeaponData(playerid, 6, PlayerInfo[playerid][Wep7], PlayerInfo[playerid][Ammo7]);
		GetPlayerWeaponData(playerid, 7, PlayerInfo[playerid][Wep8], PlayerInfo[playerid][Ammo8]);
		dini_IntSet(file, "Wep1", PlayerInfo[playerid][Wep1]);
		dini_IntSet(file, "Wep2", PlayerInfo[playerid][Wep2]);
		dini_IntSet(file, "Wep3", PlayerInfo[playerid][Wep3]);
		dini_IntSet(file, "Wep4", PlayerInfo[playerid][Wep4]);
		dini_IntSet(file, "Wep5", PlayerInfo[playerid][Wep5]);
		dini_IntSet(file, "Wep6", PlayerInfo[playerid][Wep6]);
		dini_IntSet(file, "Wep7", PlayerInfo[playerid][Wep7]);
		dini_IntSet(file, "Ammo1", PlayerInfo[playerid][Ammo1]);
		dini_IntSet(file, "Ammo2", PlayerInfo[playerid][Ammo2]);
		dini_IntSet(file, "Ammo3", PlayerInfo[playerid][Ammo3]);
		dini_IntSet(file, "Ammo4", PlayerInfo[playerid][Ammo4]);
		dini_IntSet(file, "Ammo5", PlayerInfo[playerid][Ammo5]);
		dini_IntSet(file, "Ammo6", PlayerInfo[playerid][Ammo6]);
		dini_IntSet(file, "Ammo7", PlayerInfo[playerid][Ammo7]);
		#endif
		#if HEALTH == 1
		new Float:health;
		dini_FloatSet(file, "Health", GetPlayerHealth(playerid, health));
		#endif
		#if ARMOUR == 1
		new Float:armour;
		dini_FloatSet(file, "Armour", GetPlayerArmour(playerid, armour));
		#endif
		#if DRUNK_LEVEL == 1
		dini_IntSet(file, "DrunkLevel", GetPlayerDrunkLevel(playerid));
		#endif
		#if FIGHT_STYLE == 1
		dini_IntSet(file, "FightStyle", GetPlayerFightingStyle(playerid));
		#endif
		#if VIRTUAL_WORLD == 1
		dini_IntSet(file, "VirtualWorld", GetPlayerVirtualWorld(playerid));
		#endif
		#if PLAYER_TIME == 1
		GetPlayerTime(playerid, PlayerInfo[playerid][Hour], PlayerInfo[playerid][Min]);
		dini_IntSet(file, "pTime_Hour", PlayerInfo[playerid][Hour]);
		dini_IntSet(file, "pTime_Min", PlayerInfo[playerid][Min]);
		#endif
		#if WANTED_LEVEL == 1
		dini_IntSet(file, "WantedLevel", GetPlayerWantedLevel(playerid));
		#endif
		#if TEAM == 1
		dini_IntSet(file, "Team", GetPlayerTeam(playerid));
		#endif
		#if CLOCK == 1
		dini_IntSet(file, "Clock", 1);
		#elseif CLOCK == 0
		dini_IntSet(file, "Clock", 0);
		#endif
	}
	return 1;
}

public OnPlayerSpawn(playerid)
{
	format(file, sizeof(file), USERS_FILE, PlayerName(playerid));
	if(PlayerInfo[playerid][Logged] == 1)
	{
    	#if POSITION == 1
    	if(dini_Float(file, "X") == 0 && dini_Float(file, "Y") == 0 && dini_Float(file, "Z") == 0) return 1;
		SetPlayerPos(playerid, dini_Float(file, "X"), dini_Float(file, "Y"), dini_Float(file, "Z"));
		SetPlayerFacingAngle(playerid, dini_Float(file, "A"));
		SetPlayerInterior(playerid, dini_Int(file, "Int"));
		#endif
		#if SKIN == 1
		SetPlayerSkin(playerid, dini_Int(file, "Skin"));
		SetPlayerHealth(playerid, 100.0);
		#endif
	}
	return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
	#if KILLS_DEATHS == 1
	if(PlayerInfo[killerid][Logged] == 1)
	{
		format(file, sizeof(file), USERS_FILE, PlayerName(killerid));
		GivePlayerMoney(killerid, 10000);
		SendClientMessage(killerid,RED, "You killed an innocent person!, wanted level has been increased.");
		SendClientMessage(killerid,RED, "You stole $10,000 from your victim.");
		SetPlayerWantedLevel(killerid, GetPlayerWantedLevel(killerid) + 1);
		
	}
	if(PlayerInfo[playerid][Logged] == 1)
	{
		format(file, sizeof(file), USERS_FILE, PlayerName(playerid));
		GivePlayerMoney(playerid, -10000);
		SendClientMessage(playerid,RED, "You were killed by an murderer.");
		SendClientMessage(playerid,RED, "You lost $10,000.");
	}
	#endif
	return 1;
}

public OnVehicleSpawn(vehicleid)
{
	return 1;
}

public OnVehicleDeath(vehicleid, killerid)
{
	return 1;
}

public OnPlayerText(playerid, text[])
{
	return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
	new cmd[256];
	new idx;
	cmd = strtok(cmdtext, idx);
	format(file, sizeof(file), USERS_FILE, PlayerName(playerid));

	if(strcmp(cmd, "/givemoney", true) == 0)
    {
    if(PlayerInfo[playerid][Admin] >= 2)
	{
        new tmp[30];
        tmp = strtok(cmdtext, idx);
        new otherplayer = strval(tmp);

        if(IsPlayerConnected(otherplayer))
        {
            GivePlayerMoney(otherplayer, 50000);
        }
    }
    else
    {
    return SendClientMessage(playerid, -1, "You are not an admin!");
    }
    return 1;
}

	if(strcmp(cmd, "/register", true) == 0)
	{
		#if USE_DIALOGS == 0
		new tmp[256];
		tmp = strtok(cmdtext, idx);
	    if(!strlen(tmp)) return SendClientMessage(playerid, ORANGE, "Usage: /register <password>");
	    if(dini_Exists(file)) return SendClientMessage(playerid, RED, "Error: You are already registered! Please login. (/login <password>)");
	    if(PlayerInfo[playerid][Logged] == 1) return SendClientMessage(playerid, RED, "Error: You are already logged in!");
	    if(strlen(tmp) < MIN_PASS_SIZE || strlen(tmp) > MAX_PASS_SIZE) return format(str, sizeof(str), "Error: Password length must be between %d and %d characters long!", MIN_PASS_SIZE, MAX_PASS_SIZE); SendClientMessage(playerid, RED, str);
		dini_Create(file);
		dini_Set(file, "Password", encrypt(tmp));
		SendClientMessage(playerid, GREEN, "Successfully registered! You have been automatically logged in!");
		PlayerInfo[playerid][Logged] = 1;
		return 1;
		#elseif USE_DIALOGS == 1
		if(dini_Exists(file)) return SendClientMessage(playerid, RED, "Error: You are already registered! Please login. (/login)");
		if(PlayerInfo[playerid][Logged] == 1) return SendClientMessage(playerid, RED, "Error: You are already logged in!");
        format(str, sizeof(str), "You do not have a registered account %s!\n\nPlease insert your desired password into the line below and click \"Submit\".\n\n Click \"Cancel\" to cancel registration.", PlayerName(playerid));
	    ShowPlayerDialog(playerid, REGISTER, DIALOG_STYLE_INPUT, "Register An Account", str, "Submit", "Cancel");
	    return 1;
	    #endif
}

	if(strcmp(cmd, "/login", true) == 0)
	{
		#if USE_DIALOGS == 0
		new tmp[256];
		tmp = strtok(cmdtext, idx);
	    if(!strlen(tmp)) return SendClientMessage(playerid, ORANGE, "Usage: /login <password>");
	    if(!dini_Exists(file)) return SendClientMessage(playerid, RED, "Error: You are not registered! Please register. (/register <password>)");
	    if(PlayerInfo[playerid][Logged] == 1) return SendClientMessage(playerid, RED, "Error: You are already logged in!");
	    new pass_confirm[256];
	    pass_confirm = dini_Get(file, "Password");
	    if(strcmp(encrypt(tmp), pass_confirm, true) == 0)
		{
			PlayerInfo[playerid][Logged] = 1;
			SendClientMessage(playerid, GREEN, "Successfully logged in!");
			#if POSITION == 1
			if(dini_Float(file, "X") == 0 && dini_Float(file, "Y") == 0 && dini_Float(file, "Z") == 0) return 1;
			SetPlayerPos(playerid, dini_Float(file, "X"), dini_Float(file, "Y"), dini_Float(file, "Z"));
			SetPlayerFacingAngle(playerid, dini_Float(file, "A"));
			SetPlayerInterior(playerid, dini_Int(file, "Int"));
			#endif
			#if CASH == 1
			GivePlayerMoney(playerid, dini_Int(file, "Cash"));
			#endif
			#if SKIN == 1
			SetPlayerSkin(playerid, dini_Int(file, "Skin"));
			#endif
			#if SCORE == 1
			SetPlayerScore(playerid, dini_Int(file, "Score"));
			#endif
			#if WEAPONS == 1
			GivePlayerWeapon(playerid, dini_Int(file, "Wep1"), dini_Int(file, "Ammo1"));
			GivePlayerWeapon(playerid, dini_Int(file, "Wep2"), dini_Int(file, "Ammo2"));
			GivePlayerWeapon(playerid, dini_Int(file, "Wep3"), dini_Int(file, "Ammo3"));
			GivePlayerWeapon(playerid, dini_Int(file, "Wep4"), dini_Int(file, "Ammo4"));
			GivePlayerWeapon(playerid, dini_Int(file, "Wep5"), dini_Int(file, "Ammo5"));
			GivePlayerWeapon(playerid, dini_Int(file, "Wep6"), dini_Int(file, "Ammo6"));
			GivePlayerWeapon(playerid, dini_Int(file, "Wep7"), dini_Int(file, "Ammo7"));
			#endif
			#if HEALTH == 1
			SetPlayerHealth(playerid, dini_Float(file, "Health"));
			#endif
			#if ARMOUR == 1
			SetPlayerArmour(playerid, dini_Float(file, "Armour"));
			#endif
			#if DRUNK_LEVEL == 1
			SetPlayerDrunkLevel(playerid, dini_Int(file, "DrunkLevel"));
			#endif
			#if FIGHT_STYLE == 1
			SetPlayerFightingStyle(playerid, dini_Int(file, "FightStyle"));
			#endif
			#if VIRTUAL_WORLD == 1
			SetPlayerVirtualWorld(playerid, dini_Int(file, "VirtualWorld"));
			#endif
			#if PLAYER_TIME == 1
			SetPlayerTime(playerid, dini_Int(file, "pTime_Hour"), dini_Int(file, "pTime_Min"));
			#endif
			#if WANTED_LEVEL == 1
			SetPlayerWantedLevel(playerid, dini_Int(file, "WantedLevel"));
			#endif
			#if TEAM == 1
			SetPlayerTeam(playerid, dini_Int(file, "Team"));
			#endif
			#if CLOCK == 1
			TogglePlayerClock(playerid, dini_Int(file, "Clock"));
			#endif
			#if ADMIN == 1
			SetPlayerAdmin(playerid, dini_Int(file, "Admin"));
			#endif
		}
		else
		{
		    PlayerInfo[playerid][FalseLogins]++;
		    if(PlayerInfo[playerid][FalseLogins] >= LOGIN_ATTEMPTS)
		    {
		        format(str, sizeof(str), "Admin: %s has been kicked. [Reason: %d false login attempts]", PlayerName(playerid), LOGIN_ATTEMPTS);
		        SendClientMessageToAll(RED, str);
		        Kick(playerid);
			}
			else
			{
			    SendClientMessage(playerid, RED, "Error: Incorrect password.");
			}
		}
		#elseif USE_DIALOGS == 1
		if(!dini_Exists(file)) return SendClientMessage(playerid, RED, "Error: You are not registered! Please register. (/register)");
		if(PlayerInfo[playerid][Logged] == 1) return SendClientMessage(playerid, RED, "Error: You are already logged in!");
		format(str, sizeof(str), "Welcome back %!Please login to your account.\n\nPlease insert your password into the line below and click \"Submit\". \n\n Click \"Cancel\" to cancel.", PlayerName(playerid));
	    ShowPlayerDialog(playerid, LOGIN, DIALOG_STYLE_INPUT, "Login to Your Account", str, "Submit", "Cancel");
	    return 1;
	    #endif
	}

	if(strcmp(cmd, "/changepass", true) == 0)
	{
	    if(PlayerInfo[playerid][Logged] == 0) return SendClientMessage(playerid, RED, "Error: You need to be logged in to change your password.");
	    if(!dini_Exists(file)) return SendClientMessage(playerid, RED, "Error: Loading your player file failed. Cannot continue.");
		#if USE_DIALOGS == 0
		new tmp[256];
		tmp = strtok(cmdtext, idx);
		if(!strlen(tmp)) return SendClientMessage(playerid, ORANGE, "Usage: /changepass <password>");
		if(strlen(tmp) < MIN_PASS_SIZE || strlen(tmp) > MAX_PASS_SIZE)
		{
		    format(str, sizeof(str), "Error: Password must be between %d and %d characters long!", MIN_PASS_SIZE, MAX_PASS_SIZE);
		    SendClientMessage(playerid, RED, str);
		    return 1;
		}
		dini_Set(file, "Password", encrypt(tmp));
		SendClientMessage(playerid, GREEN, "Success: Password changed!");
		#elseif USE_DIALOGS == 1
		ShowPlayerDialog(playerid, CHANGE_PASS, DIALOG_STYLE_INPUT, "Change your password..", "Please insert the password you would like and click \"Submit\".\nClick \"Cancel\" to cancel.", "Submit", "Cancel");
		#endif
		return 1;
	}
	return 0;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
	return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
	return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
	return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
	return 1;
}

public OnPlayerLeaveCheckpoint(playerid)
{
	return 1;
}

public OnPlayerEnterRaceCheckpoint(playerid)
{
	return 1;
}

public OnPlayerLeaveRaceCheckpoint(playerid)
{
	return 1;
}

public OnRconCommand(cmd[])
{
	return 1;
}

public OnPlayerRequestSpawn(playerid)
{
	#if FORCE_LOGIN == 1
	if(PlayerInfo[playerid][Logged] == 0) return SendClientMessage(playerid, RED, "Error: Must be logged in to spawn! (/login <password>)");
	#endif
	return 1;
}

public OnObjectMoved(objectid)
{
	return 1;
}

public OnPlayerObjectMoved(playerid, objectid)
{
	return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
	return 1;
}

public OnVehicleMod(playerid, vehicleid, componentid)
{
	return 1;
}

public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
	return 1;
}

public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
	return 1;
}

public OnPlayerSelectedMenuRow(playerid, row)
{
	return 1;
}

public OnPlayerExitedMenu(playerid)
{
	return 1;
}

public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
	return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
	return 1;
}

public OnRconLoginAttempt(ip[], password[], success)
{
	return 1;
}

public OnPlayerUpdate(playerid)
{
	return 1;
}

public OnPlayerStreamIn(playerid, forplayerid)
{
	return 1;
}

public OnPlayerStreamOut(playerid, forplayerid)
{
	return 1;
}

public OnVehicleStreamIn(vehicleid, forplayerid)
{
	return 1;
}

public OnVehicleStreamOut(vehicleid, forplayerid)
{
	return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    format(file, sizeof(file), USERS_FILE, PlayerName(playerid));
	if(dialogid == REGISTER)
	{
	    if(response == 1)
	    {
	        if(strlen(inputtext) < MIN_PASS_SIZE || strlen(inputtext) > MAX_PASS_SIZE)
	        {
	            format(str, sizeof(str), "Error: Password length must be between %d and %d characters long!", MIN_PASS_SIZE, MAX_PASS_SIZE);
	            SendClientMessage(playerid, RED, str);
	            format(str, sizeof(str), "You do not have a registered account %s!\n\nPlease insert your desired password into the line below and click \"Submit\".\n\n Click \"Cancel\" to cancel registration.", PlayerName(playerid));
	    		ShowPlayerDialog(playerid, REGISTER, DIALOG_STYLE_INPUT, "Register An Account", str, "Submit", "Cancel");
	            return 1;
			}
			dini_Create(file);
			dini_Set(file, "Password", encrypt(inputtext));
			dini_IntSet(file, "Admin", 0);
			SendClientMessage(playerid, GREEN, "Successfully registered! You have been automatically logged in!");
			PlayerInfo[playerid][Logged] = 1;
		}
		else
		{
		    SendClientMessage(playerid, RED, "Error: You have cancelled registration!");
		}
	}
	if(dialogid == LOGIN)
	{
	    if(response == 1)
	    {
	        new pass_confirm[256];
	        pass_confirm = dini_Get(file, "Password");
	        if(strcmp(encrypt(inputtext), pass_confirm, true) == 0)
	        {
	            PlayerInfo[playerid][Logged] = 1;
	            SendClientMessage(playerid, GREEN, "Successfully logged in!");
	            #if POSITION == 1
                if(dini_Float(file, "X") == 0 && dini_Float(file, "Y") == 0 && dini_Float(file, "Z") == 0) return 1;
				SetPlayerPos(playerid, dini_Float(file, "X"), dini_Float(file, "Y"), dini_Float(file, "Z"));
				SetPlayerFacingAngle(playerid, dini_Float(file, "A"));
				SetPlayerInterior(playerid, dini_Int(file, "Int"));
				#endif
				#if CASH == 1
				GivePlayerMoney(playerid, dini_Int(file, "Cash"));
				#endif
				#if SKIN == 1
				SetPlayerSkin(playerid, dini_Int(file, "Skin"));
				#endif
				#if SCORE == 1
				SetPlayerScore(playerid, dini_Int(file, "Score"));
				#endif
				#if WEAPONS == 1
				GivePlayerWeapon(playerid, dini_Int(file, "Wep1"), dini_Int(file, "Ammo1"));
				GivePlayerWeapon(playerid, dini_Int(file, "Wep2"), dini_Int(file, "Ammo2"));
				GivePlayerWeapon(playerid, dini_Int(file, "Wep3"), dini_Int(file, "Ammo3"));
				GivePlayerWeapon(playerid, dini_Int(file, "Wep4"), dini_Int(file, "Ammo4"));
				GivePlayerWeapon(playerid, dini_Int(file, "Wep5"), dini_Int(file, "Ammo5"));
				GivePlayerWeapon(playerid, dini_Int(file, "Wep6"), dini_Int(file, "Ammo6"));
				GivePlayerWeapon(playerid, dini_Int(file, "Wep7"), dini_Int(file, "Ammo7"));
				#endif
				#if HEALTH == 1
				SetPlayerHealth(playerid, dini_Float(file, "Health"));
				#endif
				#if ARMOUR == 1
				SetPlayerArmour(playerid, dini_Float(file, "Armour"));
				#endif
				#if DRUNK_LEVEL == 1
				SetPlayerDrunkLevel(playerid, dini_Int(file, "DrunkLevel"));
				#endif
				#if FIGHT_STYLE == 1
				SetPlayerFightingStyle(playerid, dini_Int(file, "FightStyle"));
				#endif
				#if VIRTUAL_WORLD == 1
				SetPlayerVirtualWorld(playerid, dini_Int(file, "VirtualWorld"));
				#endif
				#if PLAYER_TIME == 1
				SetPlayerTime(playerid, dini_Int(file, "pTime_Hour"), dini_Int(file, "pTime_Min"));
				#endif
				#if WANTED_LEVEL == 1
				SetPlayerWantedLevel(playerid, dini_Int(file, "WantedLevel"));
				#endif
				#if TEAM == 1
				SetPlayerTeam(playerid, dini_Int(file, "Team"));
				#endif
				#if CLOCK == 1
				TogglePlayerClock(playerid, dini_Int(file, "Clock"));
				#endif
			}
			else
			{
			    PlayerInfo[playerid][FalseLogins]++;
			    if(PlayerInfo[playerid][FalseLogins] >= LOGIN_ATTEMPTS)
			    {
			        format(str, sizeof(str), "Admin: %s has been kicked. [Reason: %d false login attempts]", PlayerName(playerid), LOGIN_ATTEMPTS);
		        	SendClientMessageToAll(RED, str);
		        	Kick(playerid);
				}
				else
				{
				    SendClientMessage(playerid, RED, "Error: Incorrect password.");
				    format(str, sizeof(str), "Welcome back %!Please login to your account.\n\nPlease insert your password into the line below and click \"Submit\". \n\n Click \"Cancel\" to cancel.", PlayerName(playerid));
	    			ShowPlayerDialog(playerid, LOGIN, DIALOG_STYLE_INPUT, "Login to Your Account", str, "Submit", "Cancel");
				}
			}
		}
		else
		{
  			SendClientMessage(playerid, RED, "Error: You have cancelled!");
		}
	}
	if(dialogid == CHANGE_PASS)
	{
	    if(response == 1)
	    {
	        if(!strlen(inputtext)) return SendClientMessage(playerid, RED, "Error: You didn't enter a password!");
	        if(strlen(inputtext) < MIN_PASS_SIZE || strlen(inputtext) > MAX_PASS_SIZE)
	        {
	            format(str, sizeof(str), "Error: Password must be between %s and %s characters long!", MIN_PASS_SIZE, MAX_PASS_SIZE);
	            SendClientMessage(playerid, RED, str);
				return 1;
			}
			dini_Set(file, "Password", encrypt(inputtext));
			SendClientMessage(playerid, GREEN, "Success: Password changed!");
		}
		else
		{
		    SendClientMessage(playerid, RED, "Error: You have cancelled!");
		}
	}
	return 1;
}

PlayerName(playerid)
{
	new name[MAX_PLAYER_NAME];
	GetPlayerName(playerid, name, MAX_PLAYER_NAME);
	return name;
}

encrypt(pass[])
{
	static charset[] = "qwertyaQWERTYUIOPZXCVBNMLKJHGFDSAsdfghzxcvbnuiopjklm1324657809_";
	static css = 63;
	new target[MAX_PASS_SIZE + 1];
	new	j = strlen(pass);
	new sum = j;
	new	tmpp = 0;
	new	i;
	new	mod;
	for (i = 0; i < MAX_PASS_SIZE || i < j; i++)
	{
		mod = i % MAX_PASS_SIZE;
		tmpp = (i >= j) ? charset[(7 * i) % css] : pass[i];
		sum = (sum + chrfind(tmpp, charset) + 1)		% css;
		target[mod] = charset[(sum + target[mod])	% css];
	}
	target[MAX_PASS_SIZE] = '\0';
	return target;
}

stock chrfind(needle, haystack[], start = 0)
{
	while(haystack[start])
	{
	    if(haystack[start++] == needle)
	    {
	        return start-1;
		}
	}
	return -1;
}

strtok(const st[], &index)
{
	new length = strlen(st);
	while ((index < length) && (st[index] <= ' '))
	{
		index++;
	}

	new offset = index;
	new result[20];
	while ((index < length) && (st[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
	{
		result[index - offset] = st[index];
		index++;
	}
	result[index - offset] = EOS;
	return result;
}

public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
	return 1;
}
Mikibey is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check elvinas02 Server Support 2 06/12/2011 03:25 AM
O_O WTF check this [MKD]Max Help Archive 3 29/06/2011 01:10 PM
Faster :Triple check or check with * RSX Help Archive 6 12/09/2010 04:10 PM
RP name check... help please introzen Help Archive 3 06/07/2010 06:57 PM
How to check NewTorran Help Archive 0 06/06/2010 03:20 PM


All times are GMT. The time now is 08:10 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.