Server Crash cuz of house system
#1

Hi!

I made a house system [MySQL] but it crashes when i load the FS, why?

And please look under the "OnPlayerPickUpPickup" callback i wrote something there, and please look after some mistakes who maybe bug the system :P

Thanks

-Unknown123

Here is the code:
pawn Код:
#include <a_samp>
#include <mysql>
#include <sscanf2>

#define COLOR_RED           0xFF0000FF
#define COLOR_GREEN         0x00AF11FF
#define COLOR_GREY          0x909090FF

#define MySQLhost           "localhost"
#define MySQLuser           "root"
#define MySQLpass           "mypass"
#define MySQLdb             "ServerDataBase"

#define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1

#define MAX_HOUSES 100

new HouseCount = -1;
new PickupID[MAX_HOUSES];

enum HouseInfo
{
    HouseOwner[24],
    HouseName[128],
    HousePrice,
    Float:EnterX,
    Float:EnterY,
    Float:EnterZ,
    Float:ExitX,
    Float:ExitY,
    Float:ExitZ,
    Interior,
    Virtual,
    Owned
}
new HouseData[MAX_HOUSES][HouseInfo];

public OnFilterScriptInit()
{
    for(new h = 0; h < MAX_HOUSES; h++)
    {
        LoadHouses(h);
        print("Houses Loaded");
        return 1;
    }
    return 1;
}

stock LoadHouses(playerid)
{
    new row[512];
    mysql_query("SELECT * FROM `Houses`");
    mysql_store_result();
    while(mysql_fetch_row(row, "|"))
    {
        sscanf(row, "p<|>s[24]s[128]dffffffdd", HouseData[playerid][HouseOwner], HouseData[playerid][HouseName], HouseData[playerid][HousePrice], HouseData[playerid][EnterX], HouseData[playerid][EnterY], HouseData[playerid][EnterZ], HouseData[playerid][ExitX], HouseData[playerid][ExitY], HouseData[playerid][ExitZ], HouseData[playerid][Interior], HouseData[playerid][Virtual]);

        CreateHouse(HouseData[playerid][HouseOwner], HouseData[playerid][HouseName], HouseData[playerid][HousePrice], HouseData[playerid][EnterX], HouseData[playerid][EnterY], HouseData[playerid][EnterZ], HouseData[playerid][ExitX], HouseData[playerid][ExitY], HouseData[playerid][ExitZ], HouseData[playerid][Interior], HouseData[playerid][Virtual]);
    }
    mysql_free_result();
}

stock CreateHouse(hOwner, hName, hPrice, Float:hEnterX, Float:hEnterY, Float:hEnterZ, Float:hExitX, Float:hExitY, Float:hExitZ, hInterior, hVirtual)
{
    new queue[512];
   
    HouseCount ++;
    new ID = HouseCount;
   
    PickupID[ID] = CreatePickup(1273, 23, hEnterX, hEnterY, hEnterZ, -1); //!
   
    format(queue, sizeof(queue), "INSERT INTO `Houses` (HouseOwner, HouseName, HousePrice, EnterX, EnterY, EnterZ, ExitX, ExitY, ExitZ, Interior, Virtual, Owned) VALUES ('%s', '%s', '%d', '%f', '%f', '%f', '%f', '%f', '%f', '%d', '%d', '0')", hOwner, hName, hPrice, hEnterX, hEnterY, hEnterZ, hExitX, hExitY, hExitZ, hInterior, hVirtual+ID);
    mysql_query(queue);
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
    for(new h; h<MAX_HOUSES; h++)
    {
        if(pickupid == PickupID[h])
        {
            /*
            if(!IsPlayerOwner(h) && HouseData[h][Owned] == 0))
            {
                SendClientMessage(h, 0xFF0000FF, "House for sale");
                return 1;
            }
            if(HouseData[h][Owned] == 1))
            {
                new string[64];
                format(string,sizeof(string),"House owner: %s", PlayerData[h][HouseOwner]);
                SendClientMessage(playerid,0xFFFFFFAA,string);
                return 1;
            }
            if(HouseData[h][Owned] == 1 && HouseData[h][HouseOwner]))
            {
                Put player in his house, how? xD
            }
            */

        }
    }
    return 1;
}

//-Commands

public OnPlayerCommandText(playerid, cmdtext[])
{
    dcmd(createhouse, 11, cmdtext);
    return 0;
}

dcmd_createhouse(playerid, params[])
{
    if(IsPlayerAdmin(playerid))
    {
        new owner, name, price;
        if(sscanf(params, "s[24]s[128]d", owner, name, price)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /createhouse (owner name) (house name) (price)");
        {
            new Float:x, Float:y, Float:z;
            GetPlayerPos(playerid, x, y, z);
   
            CreateHouse(owner, name, price, 314.820984, -141.431992, 999.661987, x, y+3, z, 7, 100);
           
            SendClientMessage(playerid, COLOR_GREY, "House Created");
            return 1;
        }
    }
    return 0;
}
Reply
#2

you can try
pawn Код:
stock LoadHouses(playerid)
{
    new row[512];
    mysql_query("SELECT * FROM `Houses`");
    mysql_query(row);
    mysql_store_result();
    if(!mysql_num_rows())
    {
        return 0;
    }
    else
    {
        while(mysql_fetch_row(row, "|"))
        {
            sscanf(row, "p<|>s[24]s[128]dffffffdd", HouseData[playerid][HouseOwner], HouseData[playerid][HouseName], HouseData[playerid][HousePrice], HouseData[playerid][EnterX], HouseData[playerid][EnterY], HouseData[playerid][EnterZ], HouseData[playerid][ExitX], HouseData[playerid][ExitY], HouseData[playerid][ExitZ], HouseData[playerid][Interior], HouseData[playerid][Virtual]);

            CreateHouse(HouseData[playerid][HouseOwner], HouseData[playerid][HouseName], HouseData[playerid][HousePrice], HouseData[playerid][EnterX], HouseData[playerid][EnterY], HouseData[playerid][EnterZ], HouseData[playerid][ExitX], HouseData[playerid][ExitY], HouseData[playerid][ExitZ], HouseData[playerid][Interior], HouseData[playerid][Virtual]);
        }
        mysql_free_result();
    }
    return 1;
}
idk if it works i dont know MySQL
Reply
#3

Still crash
Reply
#4

Why is the function "LoadHouses(PLAYERID);". Also, that query will select EVERY row in the database, so you are basically putting the information for several houses into one variable. And why are you using "playerid" for variables pertaining to houses?

I would suggest a massive re-script of this "housing" system of yours.
Reply
#5

Bump
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)