Y_Ini Save Bug?
#1

I made a map license for my script, if player want to create an object, they must have a map license from the admin.
But the problem is, the map license sometimes gone when player /q, crash/timeout or server restart (not often, it happen randomly).

Main script :
PHP Code:
#include <YSI\y_ini>
#define PATH "MapLicense/%s.ini"
enum PlayerInfo
{
    
maplicense
}
new 
MappingLicense[MAX_PLAYERS][PlayerInfo];
forward LoadMappingLicenseData(playerid,name[],value[]);
public 
LoadMappingLicenseData(playerid,name[],value[])
{
    
INI_Int("Mapping"MappingLicense[playerid][maplicense]);
     return 
1;
}
stock UserMappingLicensePath(playerid)
{
    new 
string[128],playername[MAX_PLAYER_NAME];
    
GetPlayerName(playerid,playername,sizeof(playername));
    
format(string,sizeof(string),PATH,playername);
    return 
string;
}
public 
OnPlayerConnect(playerid)
{
    if(
fexist(UserMappingLicensePath(playerid)))
    {
        
INI_ParseFile(UserMappingLicensePath(playerid), "LoadMappingLicenseData", .bExtra true, .extra playerid);
    }
    else
    {
        new 
INI:ini INI_Open(UserMappingLicensePath(playerid));
         
INI_WriteInt(ini,"MapLicense"0);
          
MappingLicense[playerid][maplicense] = 0;
           
INI_Close(ini);
    }
    return 
1;
}
public 
OnFilterScriptExit()
{
    foreach(new 
Player)
    {
        new 
INI:ini INI_Open(UserMappingLicensePath(i));
        
INI_WriteInt(ini,"MapLicense"MappingLicense[i][maplicense]);
        
INI_Close(ini);
    }
    return 
1;
}
public 
OnPlayerDisconnect(playeridreason)
{
    new 
INI:ini INI_Open(UserMappingLicensePath(playerid));
    
INI_WriteInt(ini,"MapLicense"MappingLicense[playerid][maplicense]);
    
INI_Close(ini);
    return 
1;

I put this on each command (simplified) :

PHP Code:
if(MappingLicense[playerid][maplicense] == 1)
{
    
//object thing
}
else
{
     
//sendclientmessage thingy

Give map license command :

PHP Code:
CMD:givemaplicense(playeridparams[])
{
    if(
IsPlayerAdmin(playerid))
    {
        new 
targetidlicensename[MAX_PLAYER_NAME], string[128 MAX_PLAYER_NAME];
        if(
sscanf(params"ud"targetidlicense))
        {
            return 
SendClientMessage(playerid0xFF0000FF"[Error:] /givemaplicense <id> <0 - 1>");
        }
        if(
license || license 0)
        {
            return 
SendClientMessage(playerid0xFF0000FF"[Error:] The valid number is only 0 and 1!");
        }
        if(
license == MappingLicense[targetid][maplicense])
        {
            return 
SendClientMessage(playerid0xFF0000FF"[Error:] That player already have a mapping license!");
        }
        if(
license MappingLicense[targetid][maplicense])
        {
            
GetPlayerName(targetidnamesizeof(name));
            
format(stringsizeof(string), "[MAP] You have given %s a mapping license!"name);
            
SendClientMessage(playerid0xFFFF00FFstring);
            if(
targetid != playerid)
            {
                
GetPlayerName(playeridnamesizeof(name));
                
format(stringsizeof(string), "[MAP] %s have given you a mapping license!"name);
                
SendClientMessage(targetid0xFFFF00FFstring);
            }
            
MappingLicense[targetid][maplicense] = license;
        }
        else
        {
            
GetPlayerName(targetidnamesizeof(name));
            
format(stringsizeof(string), "[MAP] You have removed %s mapping license!"name);
            
SendClientMessage(playerid0xFFFF00FFstring);
            if(
targetid != playerid)
            {
                
GetPlayerName(playeridnamesizeof(name));
                
format(stringsizeof(string), "[MAP] %s have removed your mapping license!"name);
                
SendClientMessage(targetid0xFFFF00FFstring);
            }
            
MappingLicense[targetid][maplicense] = license;
        }
        new 
INI:ini INI_Open(UserMappingLicensePath(playerid));
         
INI_WriteInt(ini,"MapLicense"license);
          
INI_Close(ini);
    }
    else
    {
         return 
SendClientMessage(playerid0xFF0000FF"[Error:] You are not logged in to RCON!");
    }
    return 
1;

What should I do? Is there anything wrong in the code?

EDIT : I think I found where is the problem, when a player (with a mapping license) connected to the server, and he didn't do any mapping cmd like /createobject, his mapping license will gone after next relog. Any clue how to fix this?
Reply


Messages In This Thread
Y_Ini Save Bug? [SOLVED] - by AfiqIqbal - 17.06.2017, 12:58
Re: Y_Ini Save Bug? - by AfiqIqbal - 17.06.2017, 16:02
Re: Y_Ini Save Bug? - by Meller - 17.06.2017, 17:04
Re: Y_Ini Save Bug? - by Meller - 17.06.2017, 17:24
Re: Y_Ini Save Bug? - by AfiqIqbal - 17.06.2017, 17:56
Re: Y_Ini Save Bug? - by Meller - 17.06.2017, 18:56
Re: Y_Ini Save Bug? - by AfiqIqbal - 17.06.2017, 20:04
Re: Y_Ini Save Bug? - by AfiqIqbal - 18.06.2017, 04:03
Re: Y_Ini Save Bug? - by Sew_Sumi - 18.06.2017, 05:07
Re: Y_Ini Save Bug? - by AfiqIqbal - 18.06.2017, 05:11
Re: Y_Ini Save Bug? - by Kane_ - 18.06.2017, 05:44
Re: Y_Ini Save Bug? - by Sew_Sumi - 18.06.2017, 07:04
Re: Y_Ini Save Bug? - by AfiqIqbal - 18.06.2017, 13:17
Re: Y_Ini Save Bug? - by AfiqIqbal - 18.06.2017, 13:30
Re: Y_Ini Save Bug? - by Uberanwar - 18.06.2017, 13:36
Re: Y_Ini Save Bug? - by AfiqIqbal - 18.06.2017, 19:26

Forum Jump:


Users browsing this thread: 3 Guest(s)