SA-MP Forums Archive
MySQL saving issue - 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: MySQL saving issue (/showthread.php?tid=455697)



MySQL saving issue - Luke_James - 02.08.2013

I've created a command to suspend somebody from a faction so they're unable to do any of the faction commands, however I do not know how to make it save to SQL, so whenever a person relogs the player variable is set back to 0 and thus they're unsuspended.

I have created a 'suspended' column in my MySQL database under 'accounts' table, but I'm not sure how to make the command save the variable. 0 would be where they're not suspended, and 1 would be suspended.

The commands are as follows;

pawn Код:
YCMD:suspend(playerid, params[], help) {
    if(help) {
        SendClientMessage(playerid, X11_WHITE, "Suspends a person in your faction, they'll be unable to use commands.");
        return 1;
    }
    new user,msg[128];
    if(GetPVarInt(playerid, "Faction") == 0) {
        SendClientMessage(playerid, X11_TOMATO_2, "You aren't in a faction.");
        return 1;
    }
    if(GetPVarInt(playerid, "Rank") < 10) {
        if(GetPVarInt(playerid, "Faction") != 1 || GetPVarInt(playerid, "Rank") < 10) {
            SendClientMessage(playerid, X11_TOMATO_2, "Your rank isn't high enough.");
            return 1;
        }
    }
    new fid = GetPVarInt(playerid, "Faction");
    if(!sscanf(params, "k<playerLookup>", user)) {
        if(!IsPlayerConnectEx(user)) {
            SendClientMessage(playerid, X11_TOMATO_2, "User not found");
            return 1;
        }
        if(GetPVarInt(user, "Faction") != fid) {
            SendClientMessage(playerid, X11_TOMATO_2, "This member is not in your faction");
            return 1;
        }
        format(msg, sizeof(msg), "* %s has been suspended by %s",GetPlayerNameEx(user, ENameType_RPName_NoMask), GetPlayerNameEx(playerid, ENameType_RPName_NoMask));
        SendFactionMessage(fid, COLOR_LIGHTBLUE, msg);
        SetPVarInt(user, "Suspended", 1);
    } else {
        SendClientMessage(playerid, X11_WHITE, "USAGE: /suspend [playerid]");
    }
    return 1;
}
pawn Код:
YCMD:unsuspend(playerid, params[], help) {
    if(help) {
        SendClientMessage(playerid, X11_WHITE, "Lifts a players suspension.");
        return 1;
    }
    new user,msg[128];
    if(GetPVarInt(playerid, "Faction") == 0) {
        SendClientMessage(playerid, X11_TOMATO_2, "You aren't in a faction.");
        return 1;
    }
    if(GetPVarInt(playerid, "Rank") < 10) {
        if(GetPVarInt(playerid, "Faction") != 1 || GetPVarInt(playerid, "Rank") < 10) {
            SendClientMessage(playerid, X11_TOMATO_2, "Your rank isn't high enough.");
            return 1;
        }
    }
    new fid = GetPVarInt(playerid, "Faction");
    if(!sscanf(params, "k<playerLookup>", user)) {
        if(!IsPlayerConnectEx(user)) {
            SendClientMessage(playerid, X11_TOMATO_2, "User not found");
            return 1;
        }
        if(GetPVarInt(user, "Faction") != fid) {
            SendClientMessage(playerid, X11_TOMATO_2, "This member is not in your faction");
            return 1;
        }
        format(msg, sizeof(msg), "* %s has been unsuspended by %s",GetPlayerNameEx(user, ENameType_RPName_NoMask), GetPlayerNameEx(playerid, ENameType_RPName_NoMask));
        SendFactionMessage(fid, COLOR_LIGHTBLUE, msg);
        SetPVarInt(user, "Suspended", 0);
    } else {
        SendClientMessage(playerid, X11_WHITE, "USAGE: /unsuspend [playerid]");
    }
    return 1;
}



Re: MySQL saving issue - CrazyChoco - 02.08.2013

Well, check if anything atleast saves at onplayerdisconnect. And try to check out some tutorials about mysql if you havn't learned it yet