SA-MP Forums Archive
PlayerInfo saving/reading the array problem [+REP] - 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: PlayerInfo saving/reading the array problem [+REP] (/showthread.php?tid=609554)



PlayerInfo saving/reading the array problem [+REP] - Amit1998 - 14.06.2016

So basically I'm trying to set up a unique groups system for my Roleplay server.
Now, there's one big issue with the system. Whenever a player uses /groupcreate when he tries it on the first time, it indeed creates a group in the MySQL Databases, however, In-game, the player is not hooked up with a group and it says he's not in a group when trying to use the features.

From the second attempt and furthur however, it hooks him up with the correct group.

Seems like the first try is bugged, and the rest are not.
Here are the code lines, I have tried so many options such as SetPVarInt however everything failed when a player firstly tries to do so:
PHP Code:
COMMAND:groupcreate(playeridparams[])
{
    if(
PlayerInfo[playerid][pGroup] != 0) return SendClientError(playerid"You are already in a group!");
    new 
iChoice[40];
    if(
sscanf(params"s[40]"iChoice)) return SCP(playerid"[Group-Name]");
    if(
200000 HandMoney(playerid)) return SendClientError(playerid"You need atleast $200,000 in hand to create group");
    
GivePlayerMoneyEx(playerid,-200000);
    
CreateGroup(iChoiceplayerid);
    return 
1;

PHP Code:
stock CreateGroup(groupName[], playerid)
{
    new 
groupid GetUnusedGroup();
    if(
groupid == -1) return printf("[ERROR] - Maximum Groups reached. %d/%d"groupidMAX_GROUPS);
    new 
iFormat[128], iQuery[260];
    
format(iFormatsizeof(iFormat), "%s has created a new group(%s)."PlayerName(playerid), groupName);
    
SetPVarInt(playerid"GroupID"groupid);
    
PlayerInfo[playerid][pGroup] = groupid;
    
mysql_format(MySQLPipelineiQuerysizeof(iQuery), "INSERT INTO `groupinfo` (`ID`, `GroupName`, `Leader`) VALUES (%d, '%e', '%e')"groupidgroupNamePlayerName(playerid));
    
mysql_tquery(MySQLPipelineiQuery);
    
ReloadGroup(groupidfalse);
    return 
1;


+REPing the helpers !


Re: PlayerInfo saving/reading the array problem [+REP] - BornHuman - 14.06.2016

Show GetUnusedGroup please.


Re: PlayerInfo saving/reading the array problem [+REP] - Amit1998 - 14.06.2016

Quote:
Originally Posted by BornHuman
View Post
Show GetUnusedGroup please.
I dont think it's bugged as it works fine when inserting the ID into the SQL databases, however-
PHP Code:
stock GetUnusedGroup()
{
    
GroupLoop(g)
    {
        if(
GroupInfo[g][gActive] != true) return g;
    }
    return -
1;

PHP Code:
enum g_Info
{
    
gName[MAX_FACTION_NAME],
    
gLeader[MAX_PLAYER_NAME],
    
bool:gActive,
}
new 
GroupInfo[MAX_GROUPS][g_Info]; 



Re: PlayerInfo saving/reading the array problem [+REP] - BornHuman - 14.06.2016

Try printing groupid and then restart your server and use it again. Show me what it outputs


Re: PlayerInfo saving/reading the array problem [+REP] - Amit1998 - 14.06.2016

Quote:
Originally Posted by BornHuman
View Post
Try printing groupid and then restart your server and use it again. Show me what it outputs
Works fine, displayed the ID of the correct group. It also creates it in the DB even in the 1st attempt, however it doesnt add the leader to the group :/


Re: PlayerInfo saving/reading the array problem [+REP] - Amit1998 - 14.06.2016

bump