#1

My gamemode is not inserting the players money,score,skin to the db could someone explain what is wrong with the gm? Its prety basic this but is not working at all..

pawn Код:
#include <a_samp>
#include <mysql>
#include <zcmd>
#include <sscanf2>


main ()
{
    Myfunction();
    Myfunction2();
}

Myfunction()
{
    print(" Miami RP v.1");
}

Myfunction2()
{
    print(" Scritped by Sub Z3ro!!");
}


#define COLOR_PURPLE 0xC2A2DAAA
#define COLOR_YELLOW 0xFFFF00AA
#define COLOR_RED   0xFF303EFF
#define COLOR_BLUE 0x1C10EFFF
#define COLOR_GREEN 0x0FBF15FF


#define MYSQL_HOST  "localhost"
#define MYSQL_USER  "root"
#define MYSQL_PASS  ""
#define MYSQL_DB    "testphp"


enum users()
{
    Name[MAX_PLAYER_NAME],
    Password[32],
    Admin,
    Money,
    Score,
    Skin,
}
new playerinfo[MAX_PLAYERS][users];
new PlayerLogged[MAX_PLAYERS];


stock SaveUsers(playerid)
{
    if(!PlayerLogged[playerid])
        return 0;

    playerinfo[playerid][Score] = GetPlayerScore(playerid);
    playerinfo[playerid][Money] = GetPlayerMoney(playerid);
    playerinfo[playerid][Skin] = GetPlayerSkin(playerid);

    new string[256];
    format(string, sizeof(string), "UPDATE users SET Password='%s',Admin='%d',Money='%d',Score='%d',Skin='d' WHERE Name='%s'", playerinfo[playerid][Password], playerinfo[playerid][Admin], playerinfo[playerid][Money],playerinfo[playerid][Score], playerinfo[playerid][Skin],playerinfo[playerid][Name]);
    mysql_query(string);
    return 1;
}




public OnGameModeInit()
{
    SetGameModeText("PHP BASIC");
    mysql_init();
    mysql_connect(MYSQL_HOST,MYSQL_USER,MYSQL_PASS,MYSQL_DB);
    return 1;
}



public OnGameModeExit()
{
    mysql_close();
    return 1;
}

public OnPlayerConnect(playerid)
{
    playerinfo[playerid][Admin] = 0;
    playerinfo[playerid][Money] = 0;
    playerinfo[playerid][Score] = 0;
    playerinfo[playerid][Skin] = 0;
    GetPlayerName(playerid, playerinfo[playerid][Name], MAX_PLAYER_NAME);
    return 1;
}

public OnPlayerDisconnect(playerid)
{
    SaveUsers(playerid);
    PlayerLogged[playerid] = 0;
    return 1;
}


command(register, playerid, params[])
{
    new string[128];
    new rID;
    if(sscanf(params, "u", rID)) return SendClientMessage(playerid, COLOR_BLUE, "Usage: /regiter ( PASSWORD )");
    if(sscanf(params, "s[32]", playerinfo[playerid][Password])) return SendClientMessage(playerid, COLOR_YELLOW,"Please enter a password to register!");
    if( strlen(playerinfo[playerid][Password]) <= 3 || strlen(playerinfo[playerid][Password]) >= 20 ) return SendClientMessage(playerid,COLOR_YELLOW,"Use 3 or more characters");
    format(string, sizeof(string), "INSERT INTO Users (Name,Password) VALUES ('%s','%s')", playerinfo[playerid][Name],playerinfo[playerid][Password]);
    mysql_query(string);
    SendClientMessage(playerid, COLOR_YELLOW, "[ACCOUNT] Your account has been created, please login now!");
    return 1;
}


command(login, playerid, params[])
{
    new string[128];
    if(sscanf(params, "s[32]", playerinfo[playerid][Password])) return SendClientMessage(playerid, COLOR_YELLOW,"Enter the password!");
    format(string, sizeof(string), "SELECT * FROM Users WHERE Name = '%s' AND Password = '%s'", playerinfo[playerid][Name], playerinfo[playerid][Password]);
    mysql_query(string);
    mysql_store_result();
    if(mysql_num_rows())
    {
   
        new row[128];
        new field[6][32];
        mysql_fetch_row(row, "|");
        explode(row, field, "|");
        mysql_free_result();
        format(playerinfo[playerid][Password], 32, "%s", field[1]);
        playerinfo[playerid][Admin] = strval(field[2]);
        playerinfo[playerid][Money] = strval(field[3]);
        playerinfo[playerid][Score] = strval(field[4]);
        playerinfo[playerid][Skin] = strval(field[5]);
       
        GivePlayerMoney(playerid, playerinfo[playerid][Money]);
        SetPlayerScore(playerid, playerinfo[playerid][Score]);
        SetPlayerSkin(playerid, playerinfo[playerid][Skin]);
        PlayerLogged[playerid] = 1;
        format(string, sizeof(string), "[ACCOUNT] Welcome to Miami RP %s", playerinfo[playerid][Name]);
        SendClientMessage(playerid, COLOR_YELLOW, string);
    }
    else
    {
        SendClientMessage(playerid, COLOR_RED,"Invalid Password");
    }
    return 1;
}
   
command(cash, playerid, params[])
{
    GivePlayerMoney(playerid,50000);
    return 1;
}

command(score, playerid, params[])
{
    SetPlayerScore(playerid,50);
    return 1;
}

command(stuck, playerid, params[])
{
    TogglePlayerControllable(playerid,0);
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    new string[256];
    new sendername[MAX_PLAYER_NAME];
    new cmd[256], idx;
    cmd = strtok(cmdtext, idx);
   
   
    if(strcmp(cmd, "/me", true) == 0)
    {
        GetPlayerName(playerid, sendername, sizeof(sendername));
        new length = strlen(cmdtext);
        while ((idx < length) && (cmdtext[idx] <= ' '))
        {
            idx++;
        }
        new offset = idx;
        new result[64];
        while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
        {
            result[idx - offset] = cmdtext[idx];
            idx++;
        }
        result[idx - offset] = EOS;
        if(!strlen(result))
        {
            SendClientMessage(playerid, COLOR_GREEN, "USAGE: /me [action]");
            return 1;
        }
        format(string, sizeof(string), "* %s %s", sendername, result);
        printf("%s", string);
        SendClientMessageToAll(COLOR_PURPLE,string);
        return 1;
    }
   
   
   
    return 1;
}


explode(const sSource[], aExplode[][], const sDelimiter[] = " ", iVertices = sizeof aExplode, iLength = sizeof aExplode[]) // Created by Westie
{
    new
        iNode,
        iPointer,
        iPrevious = -1,
        iDelimiter = strlen(sDelimiter);

    while(iNode < iVertices)
    {
        iPointer = strfind(sSource, sDelimiter, false, iPointer);

        if(iPointer == -1)
        {
            strmid(aExplode[iNode], sSource, iPrevious, strlen(sSource), iLength);
            break;
        }
        else
        {
            strmid(aExplode[iNode], sSource, iPrevious, iPointer, iLength);
        }

        iPrevious = (iPointer += iDelimiter);
        ++iNode;
    }
    return iPrevious;
}

strtok(const string[], &index)
{
    new length = strlen(string);
    while ((index < length) && (string[index] <= ' '))
    {
        index++;
    }

    new offset = index;
    new result[20];
    while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
    {
        result[index - offset] = string[index];
        index++;
    }
    result[index - offset] = EOS;
    return result;
}
Reply
#2

Do you get any errors when compiling? If so, please list.
Reply
#3

should be
PHP код:
stock SaveUsers(playerid)
{
    if(!
PlayerLogged[playerid])
        return 
0;
    
playerinfo[playerid][Score] = GetPlayerScore(playerid);
    
playerinfo[playerid][Money] = GetPlayerMoney(playerid);
    
playerinfo[playerid][Skin] = GetPlayerSkin(playerid);
    new 
string[256];
    
format(stringsizeof(string), "UPDATE users SET Password='%s',Admin='%d',Money='%d',Score='%d',Skin='%d' WHERE Name='%s'"playerinfo[playerid][Password], playerinfo[playerid][Admin], playerinfo[playerid][Money],playerinfo[playerid][Score], playerinfo[playerid][Skin],playerinfo[playerid][Name]);
    
mysql_query(string);
    return 
1;

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)