SA-MP Forums Archive
Server Crash cuz of house system - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Server Crash cuz of house system (/showthread.php?tid=239642)



Server Crash cuz of house system - Unknown123 - 14.03.2011

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;
}



Re: Server Crash cuz of house system - Larsey123IsMe - 15.03.2011

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


Re: Server Crash cuz of house system - Unknown123 - 15.03.2011

Still crash


Re: Server Crash cuz of house system - elcid7772 - 15.03.2011

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.


Re: Server Crash cuz of house system - Unknown123 - 16.03.2011

Bump