SA-MP Forums Archive
Y_Ini Save Bug? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Y_Ini Save Bug? (/showthread.php?tid=635975)



Y_Ini Save Bug? [SOLVED] - AfiqIqbal - 17.06.2017

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?


Re: Y_Ini Save Bug? - AfiqIqbal - 17.06.2017

BUMP


Re: Y_Ini Save Bug? - Meller - 17.06.2017

Honestly, you don't need to use y_ini for this at all, let me code you a similar system in a sec. Hold on.


Re: Y_Ini Save Bug? - Meller - 17.06.2017

PHP Code:
#include <a_samp>
#include <command_proccessor> // zcmd for me
#include <sscanf2>

public OnPlayerConnect(playerid) {
    
    new 
path[64], name[MAX_PLAYER_NAME];
    
GetPlayerName(playeridnameMAX_PLAYER_NAME);
    
format(path64"maplicenses/%s"name);
    if(
fexist(path))
        
SetPVarInt(playerid"mapping_license"1);
    else 
SetPVarInt(playerid"mapping_license"0);
    return 
1;
}

CMD:setmaplicense(playeridparams[]) {
    if(
IsPlayerAdmin(playerid)) {
        new 
targetidlicense;
        if(!
sscanf(params"ui"targetidlicense)) {
            
//always check for the first param first btw
            
if(IsPlayerConnected(targetid)) {
                if((
license == 1) || (license == 0)) {
                    if(
license != GetPVarInt(targetid"mapping_license")) {
                        new 
name[MAX_PLAYER_NAME], message[144], path[64];
                        
GetPlayerName(targetidnameMAX_PLAYER_NAME);
                        if(
license == 0) {
                            
GetPlayerName(playeridnameMAX_PLAYER_NAME);
                            
format(path64"maplicenses/%s"name);
                            if(
fexist(path))
                                
fremove(path);
                            
format(message144"[MAP] You have removed %s mapping license!"name);
                            
SendClientMessage(playerid0xFFFF00FFmessage);
                            if(
targetid != playerid) {
                                
GetPlayerName(playeridnameMAX_PLAYER_NAME);
                                
format(message144"[MAP] %s have removed your mapping license!"name);
                                
SendClientMessage(targetid0xFFFF00FFmessage);
                            }
                            
SetPVarInt(targetid"mapping_license"0);
                        }
                        else {
                            
GetPlayerName(playeridnameMAX_PLAYER_NAME);
                            
format(path64"maplicenses/%s"name);
                            if(!
fexist(path)) {
                                new 
File:file fopen(pathio_write);
                                
fclose(file);
                            }
                            
format(message144"[MAP] You have given %s a mapping license!"name);
                            
SendClientMessage(playerid0xFFFF00FFmessage);
                            if(
targetid != playerid) {
                                
GetPlayerName(playeridnameMAX_PLAYER_NAME);
                                
format(message144"[MAP] %s have given you a mapping license!"name);
                                
SendClientMessage(targetid0xFFFF00FFmessage);
                            }
                            
SetPVarInt(targetid"mapping_license"1);
                        }
                    }
                    else 
SendClientMessage(playerid0xFF0000FF"[Error:] That player already have their mapping license set at that!");
                }
                else 
SendClientMessage(playerid0xFF0000FF"[Error:] The valid number is only 0 and 1!");
            }
            else 
SendClientMessage(playerid0xFF0000FF"[Error:] That player is not connected!");
        }
        else 
SendClientMessage(playerid0xFF0000FF"[Error:] /givemaplicense <id> <0 - 1>");
    }
    else 
SendClientMessage(playerid0xFF0000FF"[Error:] You are not logged in to RCON!");
    return 
1;

There you go bud'.

To check if he's got a map license simply type:
PHP Code:
if(GetPVarInt(targetid"mapping_license") == 1) { } 



Re: Y_Ini Save Bug? - AfiqIqbal - 17.06.2017

Quote:
Originally Posted by Meller
View Post
PHP Code:
#include <a_samp>
#include <command_proccessor> // zcmd for me
#include <sscanf2>
public OnPlayerConnect(playerid) {
    
    new 
path[64], name[MAX_PLAYER_NAME];
    
GetPlayerName(playeridnameMAX_PLAYER_NAME);
    
format(path64"maplicenses/%s"name);
    if(
fexist(path))
        
SetPVarInt(playerid"mapping_license"1);
    else 
SetPVarInt(playerid"mapping_license"0);
    return 
1;
}
CMD:setmaplicense(playeridparams[]) {
    if(
IsPlayerAdmin(playerid)) {
        new 
targetidlicense;
        if(!
sscanf(params"ui"targetidlicense)) {
            
//always check for the first param first btw
            
if(IsPlayerConnected(targetid)) {
                if((
license == 1) || (license == 0)) {
                    if(
license != GetPVarInt(targetid"mapping_license")) {
                        new 
name[MAX_PLAYER_NAME], message[144], path[64];
                        
GetPlayerName(targetidnameMAX_PLAYER_NAME);
                        if(
license == 0) {
                            
GetPlayerName(playeridnameMAX_PLAYER_NAME);
                            
format(path64"maplicenses/%s"name);
                            if(
fexist(path))
                                
fremove(path);
                            
format(message144"[MAP] You have removed %s mapping license!"name);
                            
SendClientMessage(playerid0xFFFF00FFmessage);
                            if(
targetid != playerid) {
                                
GetPlayerName(playeridnameMAX_PLAYER_NAME);
                                
format(message144"[MAP] %s have removed your mapping license!"name);
                                
SendClientMessage(targetid0xFFFF00FFmessage);
                            }
                            
SetPVarInt(targetid"mapping_license"0);
                        }
                        else {
                            
GetPlayerName(playeridnameMAX_PLAYER_NAME);
                            
format(path64"maplicenses/%s"name);
                            if(!
fexist(path)) {
                                new 
File:file fopen(pathio_write);
                                
fclose(file);
                            }
                            
format(message144"[MAP] You have given %s a mapping license!"name);
                            
SendClientMessage(playerid0xFFFF00FFmessage);
                            if(
targetid != playerid) {
                                
GetPlayerName(playeridnameMAX_PLAYER_NAME);
                                
format(message144"[MAP] %s have given you a mapping license!"name);
                                
SendClientMessage(targetid0xFFFF00FFmessage);
                            }
                            
SetPVarInt(targetid"mapping_license"1);
                        }
                    }
                    else 
SendClientMessage(playerid0xFF0000FF"[Error:] That player already have their mapping license set at that!");
                }
                else 
SendClientMessage(playerid0xFF0000FF"[Error:] The valid number is only 0 and 1!");
            }
            else 
SendClientMessage(playerid0xFF0000FF"[Error:] That player is not connected!");
        }
        else 
SendClientMessage(playerid0xFF0000FF"[Error:] /givemaplicense <id> <0 - 1>");
    }
    else 
SendClientMessage(playerid0xFF0000FF"[Error:] You are not logged in to RCON!");
    return 
1;

There you go bud'.

To check if he's got a map license simply type:
PHP Code:
if(GetPVarInt(targetid"mapping_license") == 1) { } 
So, if I use your method will it fix my problem or you just showing me the simple way to do this?


Re: Y_Ini Save Bug? - Meller - 17.06.2017

Quote:
Originally Posted by AfiqIqbal
View Post
So, if I use your method will it fix my problem or you just showing me the simple way to do this?
That code works just like you wanted yours to work. So it'll work if you replace it with your current.


Re: Y_Ini Save Bug? - AfiqIqbal - 17.06.2017

Thanks for your help, appreciate it. REP +

EDIT : I thought it worked .. but nope it's not working, somebody please help me...


Re: Y_Ini Save Bug? - AfiqIqbal - 18.06.2017

BUMP


Re: Y_Ini Save Bug? - Sew_Sumi - 18.06.2017

24 hour bumps only.

Say how it's not working, not just that it isn't working...


Re: Y_Ini Save Bug? - AfiqIqbal - 18.06.2017

I don't know, sometimes when player relog their license is gone, and sometimes not, man it just confusing!


Re: Y_Ini Save Bug? - Kane - 18.06.2017

Are you resetting player variables on connect?


Re: Y_Ini Save Bug? - Sew_Sumi - 18.06.2017

If it\'s sporadic, then it could be something else interfering with it.


Re: Y_Ini Save Bug? - AfiqIqbal - 18.06.2017

Quote:
Originally Posted by Arthur Kane
View Post
Are you resetting player variables on connect?
No, I didn\'t


Re: Y_Ini Save Bug? - AfiqIqbal - 18.06.2017

Quote:
Originally Posted by Sew_Sumi
View Post
If it\'s sporadic, then it could be something else interfering with it.
Maybe I have to reset the map license variable to 0, in OnPlayerDisconnect? Let me try ..


Re: Y_Ini Save Bug? - Uberanwar - 18.06.2017

You have to reset all your variables when the user connect and after that you continue with the login/register process which will initialize the correct values for all your variables.


Re: Y_Ini Save Bug? - AfiqIqbal - 18.06.2017

Thanks for all the help, I fixed it.