Quantcast
Channel: SA-MP Forums
Viewing all articles
Browse latest Browse all 18226

Cant save anything on disconnect SQLITE

$
0
0
Hello, I'm trying to save the players position, health and armour on disconnect but even the skin is not saving. What is wrong here? I can't seem to get it to work.

Code:

enum USER_DATA
{
    USER_ID,
    USER_NAME[MAX_PLAYER_NAME],
    USER_PASSWORD[129],
    USER_IP,
   
    USER_TEAM,
   
    USER_NEW,
    USER_ADMIN,
    USER_HELPER,
    USER_VIP,
   
    USER_AGE,
        USER_SEX,
        USER_ORIGIN,
   
    USER_SCORE,
   
    USER_FACTION,
    USER_LEADER,
   
    USER_HUNGER,
    USER_THIRST,
    USER_ENERGY,
    USER_SLEEP,
   
    Float:USER_LASTX,
    Float:USER_LASTY,
    Float:USER_LASTZ,
    USER_INTERIOR,

    USER_HEALTH,
    USER_ARMOR,
        USER_SKIN,
        USER_FIGHTSTYLE,

    bool: USER_LOGGED_IN
};

Code:

//on player disconnect
if(User[playerid][USER_LOGGED_IN] == true)
    {
            new Float:health, Float:armour;
            User[playerid][USER_HEALTH] = GetPlayerHealth(playerid, health);
        User[playerid][USER_ARMOR] = GetPlayerArmour(playerid, armour);

            GetPlayerPos(playerid, User[playerid][USER_LASTX], User[playerid][USER_LASTY], User[playerid][USER_LASTZ]);
                User[playerid][USER_INTERIOR] = GetPlayerInterior(playerid);

                  User[playerid][USER_SCORE] = GetPlayerScore(playerid);
        User[playerid][USER_FIGHTSTYLE] = GetPlayerFightingStyle(playerid);
        User[playerid][USER_SKIN] = GetPlayerSkin(playerid);
   
                new Query[2000];
                format(Query, sizeof(Query), "UPDATE users SET ip = %d, team = %d, new = %d, admin = %d, helper = %d, vip = %d, age = %d, sex = %d, origin = %s, score = %d, faction = %d, leader = %d, hunger = %d, thirst = %d, energy = %d, sleep = %d, lastx = %f, lasty = %f, lastz = %f, interior = %d, health = %d, armor = %d, skin = %d, fightstyle = %d WHERE username = '%s'", User[playerid][USER_IP], User[playerid][USER_TEAM], User[playerid][USER_NEW], User[playerid][USER_ADMIN], User[playerid][USER_HELPER], User[playerid][USER_VIP], User[playerid][USER_AGE], User[playerid][USER_SEX], User[playerid][USER_ORIGIN], User[playerid][USER_SCORE], User[playerid][USER_FACTION], User[playerid][USER_LEADER], User[playerid][USER_HUNGER], User[playerid][USER_THIRST], User[playerid][USER_ENERGY], User[playerid][USER_SLEEP], User[playerid][USER_LASTX], User[playerid][USER_LASTY], User[playerid][USER_LASTZ], User[playerid][USER_INTERIOR], User[playerid][USER_HEALTH], User[playerid][USER_ARMOR], User[playerid][USER_SKIN], User[playerid][USER_FIGHTSTYLE], DB_Escape(User[playerid][USER_NAME]));
                db_query(Database, Query);
               
                SaveInventory(playerid);
        }
    for(new i; i < _: USER_DATA; ++i) User[playerid][USER_DATA: i] = 0;
return 1;
}

Code:

public OnPlayerSpawn(playerid)
{

               
                if(User[playerid][USER_NEW] == 0)
                {
                        SendClientMessage(playerid, -1, "[DE-BUG] You are not a new player");
                       
                        if(User[playerid][USER_HEALTH] == 0)
                        {
                SendClientMessage(playerid, -1, "[DE-BUG] You have 0 HP");
                        }
                        else
                        {
                                SetPlayerHealth(playerid, User[playerid][USER_HEALTH]);
                                SendClientMessage(playerid, -1, "[DE-BUG] You have health");
                        }
                       
                        if(User[playerid][USER_ARMOR] == 0)
                        {
                    SendClientMessage(playerid, -1, "[DE-BUG] You have 0 armor");
                        }
                        else
                        {
                            SetPlayerArmour(playerid, User[playerid][USER_ARMOR]);
                            SendClientMessage(playerid, -1, "[DE-BUG] You have armor");
                        }

                    SetPlayerScore(playerid, User[playerid][USER_SCORE]);
                    SetPlayerFightingStyle(playerid, User[playerid][USER_FIGHTSTYLE]);
                    SetPlayerSkin(playerid, User[playerid][USER_SKIN]);
                   
                    SetPlayerPos(playerid, User[playerid][USER_LASTX], User[playerid][USER_LASTY], User[playerid][USER_LASTZ]);
                    SetPlayerInterior(playerid, User[playerid][USER_INTERIOR]);
                    //SetPlayerPos(playerid, 684.789611, -442.097717, 17.060895);

                }
    return 1;
}

Code:

stock GameMode()
{
        Database = db_open("server.db");
        db_query(Database, "CREATE TABLE IF NOT EXISTS users (userid INTEGER PRIMARY KEY AUTOINCREMENT, username VARCHAR(24) COLLATE NOCASE, password VARCHAR(129), ip INTEGER DEFAULT 0 NOT NULL, team INTEGER DEFAULT 0 NOT NULL, new INTEGER DEFAULT 0 NOT NULL, admin INTEGER DEFAULT 0 NOT NULL, helper INTEGER DEFAULT 0 NOT NULL, vip INTEGER DEFAULT 0 NOT NULL, age INTEGER DEFAULT 0 NOT NULL, sex INTEGER DEFAULT 0 NOT NULL, origin INTEGER DEFAULT 0 NOT NULL, score INTEGER DEFAULT 0 NOT NULL, faction INTEGER DEFAULT 0 NOT NULL, leader INTEGER DEFAULT 0 NOT NULL, hunger INTEGER DEFAULT 0 NOT NULL, thirst INTEGER DEFAULT 0 NOT NULL, energy INTEGER DEFAULT 0 NOT NULL, sleep INTEGER DEFAULT 0 NOT NULL, lastx INTEGER DEFAULT 0 NOT NULL, lasty INTEGER DEFAULT 0 NOT NULL, lastz INTEGER DEFAULT 0 NOT NULL, interior INTEGER DEFAULT 0 NOT NULL, health INTEGER DEFAULT 0 NOT NULL, armor INTEGER DEFAULT 0 NOT NULL, skin INTEGER DEFAULT 0 NOT NULL, fightstyle INTEGER DEFAULT 0 NOT NULL)");
        return 1;
}


Viewing all articles
Browse latest Browse all 18226

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>