Saving ban inside account
#1

Hi,

I have problem i dont know how to make when i ban player a ban should be saved into his account so when he relog he will be banned! +REP if helped

NOTE: im using Y_INI saving system

Ban command

Код:
CMD:ban(playerid, params[])
{
 	if(pInfo[playerid][Adminlevel] < 2)
	    return SCM(playerid, red, "[ERROR] You are not allowed to use this command!");

	new player1, string[128], reason[64];

    if(sscanf(params, "us[64]", player1, reason))
		return SCM(playerid, red,"[USAGE]: /ban (ID/Name) (reason)");

	if(player1 == INVALID_PLAYER_ID)
	    return SCM(playerid, red, "[ERROR]: No player!");

	if(player1 == playerid)
	    return SCM(playerid, red, "[ERROR]: You cannot ban yourself.");

	format(string, sizeof(string), "{FFFFFF}%s (ID: %d) has been banned %s %s", pName(player1), player1, pName(playerid), reason);
	SendClientMessageToAll(-1, string);
	
	BanEx(player1, string);
	return 1;
}
Reply
#2

Please u folder directory and are u using Dini or y_ini ._.

MORE INFORMATIONS
Reply
#3

He is using Y_ini. Well it`s easy. First of all, create global player variable in your enum or just classic one. Then place it in load account function, also in save function, I haven`t learned Y_ini but I am telling you just steps how I would do it. So next, when player get banned, you just set variable (ban variable) to 1 and save it inside account txt file, after that when banned player tried to login on your server you just check that ban var, if it`s 1, player is banned and you kick him, if it`s 0 then just continue with code. That`s all.
Reply
#4

Quote:
Originally Posted by Sanady
Посмотреть сообщение
He is using Y_ini. Well it`s easy. First of all, create global player variable in your enum or just classic one. Then place it in load account function, also in save function, I haven`t learned Y_ini but I am telling you just steps how I would do it. So next, when player get banned, you just set variable (ban variable) to 1 and save it inside account txt file, after that when banned player tried to login on your server you just check that ban var, if it`s 1, player is banned and you kick him, if it`s 0 then just continue with code. That`s all.
Ok, Tanks for reply. I will post here if this one will work and +REP you
Reply
#5

Quote:
Originally Posted by Hunud
Посмотреть сообщение
Ok, Tanks for reply. I will post here if this one will work and +REP you
PHP код:
#include <a_samp>
#include <YSI\y_ini>
#define BAN_PATH "/Bans/%s.ini"
BanPath(playerid){
    new
        
str[36],
        
name[MAX_PLAYER_NAME];
    
GetPlayerName(playeridnamesizeof(name));
    
format(strsizeof(str), BAN_PATHname);
    return 
str;
}
enum E_BAN_DATA {
     
Ban,
     
Reason[24]
};
new 
PlayerInfo[MAX_PLAYER_NAME][E_BAN_DATA];
//now go to OnPlayerConnect and past this
    
PlayerInfo[playerid][Ban] = 0;
    new 
name[MAX_PLAYER_NAME];
    
GetPlayerName(playeridnamesizeof(name));
    
TogglePlayerSpectating(playeridtrue);
    if(
fexist(BanData(playerid))) {
             if(
PlayerInfo[playerid][Ban] == 1) {
               
INI_ParseFile(UserPath(playerid), "LoadPlayerData_BanData", .bExtra true, .extra playerid);
               
SendClientMessage(playerid0xFF0000"You are banned from this server");
                   
Kick(playerid);
            }
    }
    
// now right underneath the OnPlayerConnect add this
forward LoadPlayerData_BanData(playeridname[], value []);
public 
LoadPlayerData_BanData(playeridname[], value []) {
    
INI_Int("Ban"PlayerInfo[playerid][Ban]);
        
INI_String("Reason"PlayerInfo[playerid][Reason], 24);
    return 
1;
}
//now change our command to this
CMD:ban(playeridparams[])
{
     if(
pInfo[playerid][Adminlevel] < 2)
        return 
SCM(playeridred"[ERROR] You are not allowed to use this command!");
    new 
player1string[128], reason[64];
       if(
sscanf(params"us"player1reason))
        return 
SCM(playeridred,"[USAGE]: /ban (ID/Name) (reason)");
    if(
player1 == INVALID_PLAYER_ID)
        return 
SCM(playeridred"[ERROR]: No player!");
    if(
player1 == playerid)
        return 
SCM(playeridred"[ERROR]: You cannot ban yourself.");
    
format(stringsizeof(string), "{FFFFFF}%s (ID: %d) has been banned %s %s"pName(player1), player1pName(playerid), reason);
    
SendClientMessageToAll(-1string);
    new 
INI:File INI_Open(BanPath(player1));
        
INI_SetTga(File"BanData");
        
INI_WriteInt(File"Ban"1);
        
INI_WriteString(File"Reason"reason);
        
INI_Close(File);
    
Kick(playeri1);
    return 
1;

if something didn't work, send me the error log
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)