Created houses only load after server restart
#1

So, I've been scratching my head for the past days on this problem: The houses I create on the server appear only after a server restart. The loading code in the command is almost the same as the one ran on startup, however the house still does not appear.
For some reason the indentation gets screwed up when pasting. Also there are no errors/warnings when compiling.
Some help please?

Createhouse command code:
pawn Код:
CMD:createhouse(playerid,params[])
{
    if(drconlogged[playerid] || orconlogged[playerid])
    {
        new price,interior;
        if(sscanf(params,"ii",price,interior)) return SCM(playerid,COLOR_GREY,"INFO: /createhouse [price][interior(1-21)]");
        if(interior<1 || interior>21) return SCM(playerid,COLOR_GREY,"INFO: /createhouse [price][interior(1-21)]");
        new Float:X,Float:Y,Float:Z;
        GetPlayerPos(playerid,X,Y,Z);
        new Float:hEnterX, Float:hEnterY, Float:hEnterZ, hint;
        switch(interior)
        {
            case 1:
            {
                hint=1;
                hEnterX=223.19999694824;
                hEnterY=1287.5;
                hEnterZ=1081.8000488281;
            }
            case 2:
            {
                hint=4;
                hEnterX=261;
                hEnterY=1284.5999755859;
                hEnterZ=1079.9000244141;
            }
            case 3:
            {
                hint=5;
                hEnterX=140.30000305176;
                hEnterY=1366.4000244141;
                hEnterZ=1083.5;
            }
            case 4:
            {
                hint=9;
                hEnterX=83;
                hEnterY=1322.5999755859;
                hEnterZ=1083.5;
            }
            case 5:
            {
                hint=15;
                hEnterX=-283.79998779297;
                hEnterY=1471.0999755859;
                hEnterZ=1084;
            }
            case 6:
            {
                hint=4;
                hEnterX=-260.89999389648;
                hEnterY=1456.6999511719;
                hEnterZ=1084;
            }
            case 7:
            {
                hint=8;
                hEnterX=-42.599998474121;
                hEnterY=1405.6999511719;
                hEnterZ=1084.0999755859;
            }
            case 8:
            {
                hint=6;
                hEnterX=-68.800003051758;
                hEnterY=1351.6999511719;
                hEnterZ=1079.9000244141;
            }
            case 9:
            {
                hint=6;
                hEnterX=2333.1999511719;
                hEnterY=-1076.6999511719;
                hEnterZ=1048.6999511719;
            }
            case 10:
            {
                hint=5;
                hEnterX=2233.6999511719;
                hEnterY=-1115.0999755859;
                hEnterZ=1050.5;
            }
            case 11:
            {
                hint=8;
                hEnterX=2365.1999511719;
                hEnterY=-1135.0999755859;
                hEnterZ=1050.5;
            }
            case 12:
            {
                hint=11;
                hEnterX=2282.8999023438;
                hEnterY=-1140;
                hEnterZ=1050.5;
            }
            case 13:
            {
                hint=6;
                hEnterX=2196.3999023438;
                hEnterY=-1204.4000244141;
                hEnterZ=1048.6999511719;
            }
            case 14:
            {
                hint=10;
                hEnterX=2270.3000488281;
                hEnterY=-1210.4000244141;
                hEnterZ=1047.1999511719;
            }
            case 15:
            {
                hint=6;
                hEnterX=2308.8000488281;
                hEnterY=-1212.8000488281;
                hEnterZ=1048.6999511719;
            }
            case 16:
            {
                hint=1;
                hEnterX=2218.1000976563;
                hEnterY=-1076.0999755859;
                hEnterZ=1050.0999755859;
            }
            case 17:
            {
                hint=2;
                hEnterX=2237.6000976563;
                hEnterY=-1081.4000244141;
                hEnterZ=1048.6999511719;
            }
            case 18:
            {
                hint=9;
                hEnterX=2317.6999511719;
                hEnterY=-1026.6999511719;
                hEnterZ=1049.9000244141;
            }
            case 19:
            {
                hint=7;
                hEnterX=225.68;
                hEnterY=1021.45;
                hEnterZ=1084.02;
            }
            case 20:
            {
                hint=12;
                hEnterX=2324.3999023438;
                hEnterY=-1149.4;
                hEnterZ=1050.3000244141;
            }
            case 21:
            {
                hint=5;
                hEnterX=1260.6999511719;
                hEnterY=-785.40002441406;
                hEnterZ=1091.4999755859;
            }
        }
        new owner[24]="No-One";
        new query[512];
        format(query,sizeof(query),"INSERT INTO `houses` (`Owner`,`Price`,`ExitX`,`ExitY`,`ExitZ`,`Locked`,`EnterX`,`EnterY`,`EnterZ`,`Interior`) VALUES ('%s','%d','%f','%f','%f','1','%f','%f','%f','%d')",owner,price,X,Y,Z,hEnterX,hEnterY,hEnterZ,hint);
        mysql_query(query);
        new txtstring[256];
        new hid=mysql_insert_id();
        hInfo[hid][ID]=hid;
        hInfo[hid][Price]=price;
        hInfo[hid][ExitX]=X;
        hInfo[hid][ExitY]=Y;
        hInfo[hid][ExitZ]=Z;
        hInfo[hid][EnterX]=hEnterX;
        hInfo[hid][EnterY]=hEnterY;
        hInfo[hid][EnterZ]=hEnterZ;
        hInfo[hid][Locked]=1;
        hInfo[hid][Interior]=hint;
        strmid(hInfo[hid][Owner], owner, false, strlen(owner), MAX_PLAYER_NAME);
        hInfo[hid][PickupID]=CreatePickup(1272,1,hInfo[hid][ExitX],hInfo[hid][ExitY],hInfo[hid][ExitZ],-1);
        format(txtstring,sizeof(txtstring),"This house is for sale\n{10F441}Price: %d$ ID: %d\n{10F441}Use {FF8600}/buyhouse {10F441}to buy this house",hInfo[hid][Price],hid);
        hInfo[hid][TextID]=Create3DTextLabel(txtstring,COLOR_LIME,hInfo[hid][ExitX],hInfo[hid][ExitY],hInfo[hid][ExitZ],15,0,1);
    }
    else return 0;
    return 1;
}
And this is the code ran on startup:
pawn Код:
for(new i=0; i<MAX_HOUSES; i++)
    {
        new hid=i;
        new query[512];
        format(query,sizeof(query),"SELECT * FROM `houses` WHERE `ID`='%d'",i);
        mysql_query(query);
        mysql_store_result();
        if(mysql_num_rows())
        {
            new row[128];
            new field[15][161];
            mysql_fetch_row_format(row, "|");
            explode(row, field, "|");
            hInfo[hid][ID]=strval(field[0]);
            strmid(hInfo[hid][Owner], field[1], false, strlen(field[1]), MAX_PLAYER_NAME);
            hInfo[hid][Price]=strval(field[2]);
            hInfo[hid][ExitX]=strval(field[3]);
            hInfo[hid][ExitY]=strval(field[4]);
            hInfo[hid][ExitZ]=strval(field[5]);
            hInfo[hid][Locked]=strval(field[6]);
            hInfo[hid][EnterX]=strval(field[7]);
            hInfo[hid][EnterY]=strval(field[8]);
            hInfo[hid][EnterZ]=strval(field[9]);
            hInfo[hid][Interior]=strval(field[10]);
            if(hInfo[hid][Price]==-1)
                hInfo[hid][PickupID]=CreatePickup(1273,1,hInfo[hid][ExitX],hInfo[hid][ExitY],hInfo[hid][ExitZ],-1);
            else
                hInfo[hid][PickupID]=CreatePickup(1272,1,hInfo[hid][ExitX],hInfo[hid][ExitY],hInfo[hid][ExitZ],-1);
            new txtstring[256];
            if(hInfo[hid][Price]==-1)
                format(txtstring,sizeof(txtstring),"This house is owned by {FF0000}%s\n{{FFFFFF}ID: %d\n{FFFFFF}Type {FF8600}/house {10F441}for more info.",hInfo[hid][Owner],hid);
            else
                format(txtstring,sizeof(txtstring),"This house is for sale\n{10F441}Price: %d$ ID: %d\n{10F441}Use {FF8600}/buyhouse {10F441}to buy this house",hInfo[hid][Price],hid);
            hInfo[hid][TextID]=Create3DTextLabel(txtstring,COLOR_LIME,hInfo[hid][ExitX],hInfo[hid][ExitY],hInfo[hid][ExitZ],15,0,1);
        }
        mysql_free_result();
    }
Reply
#2

Код:
hInfo[hid][PickupID]=CreatePickup(1272,1,hInfo[hid][ExitX],hInfo[hid][ExitY],hInfo[hid][ExitZ],-1);
1272 != 1273
Reply
#3

Quote:
Originally Posted by Yashas
Посмотреть сообщение
Код:
hInfo[hid][PickupID]=CreatePickup(1272,1,hInfo[hid][ExitX],hInfo[hid][ExitY],hInfo[hid][ExitZ],-1);
1272 != 1273
Thank you for the reply and sorry for my late response. I intentionally put 1272 and 1273, as one of the pickups is a blue house and the other one green, so it's easier to find out if a house is owned or not.
I did eventually figure out the problem and it was nothing to do with the script but rather with the database, as I accidentally set the Owner to be an integer and not a string. After fixing that, for some reason, the houses started loading just like they should, without restarting the server.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)