How to stop it overwriting houses?
#1

I put:

pawn Код:
new houseid = 0;
^ At the top of the script.

I then have this:

pawn Код:
CMD:createhouse(playerid, params[])
{
    new Float:pos[4], string[80];
    if(!IsPlayerLoggedIn(playerid))
    {
        SendClientMessage(playerid, COLOR_RED, "Error"White": You are restricted from using commands until you log in.");
        return 1;
    }
    if(PlayerInfo[playerid][pAdminLevel] < 1)
    {
        SendClientMessage(playerid, COLOR_RED, "Error"White": You do not have the authority to use this command.");
        return 1;
    }
    if(!AdminDuty[playerid])
    {
        SendClientMessage(playerid, COLOR_RED, "Error"White": You are not on duty as an Administrator (/aduty).");
        return 1;
    }
    for(new i = 0; i < MAX_HOUSES; i++)
    {
        if(HouseInfo[i][hHouseID] == houseid)
        {
            houseid++; // I did this so it creates houses that don't exist
        }
    }
    GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
    GetPlayerFacingAngle(playerid, pos[3]);
    CreateHouse(pos[0], pos[1], pos[2], pos[3]);
    format(string, sizeof(string), "%s %s has created house ID %d.", AdminRanks(playerid), Player(playerid), houseid-1);
    SendAdminMessage(string);
    return 1;
}
Then my createhouse stock

pawn Код:
stock CreateHouse(Float:PosX, Float:PosY, Float:PosZ, Float:PosA)
{
    new string[200], query[400];
    HouseInfo[houseid][hHouseID] = houseid;
    HouseInfo[houseid][hEnterPos][0] = PosX;
    HouseInfo[houseid][hEnterPos][1] = PosY;
    HouseInfo[houseid][hEnterPos][2] = PosZ;
    HouseInfo[houseid][hEnterPos][3] = PosA;
    HouseInfo[houseid][hExitPos][0] = 266.9708;
    HouseInfo[houseid][hExitPos][1] = 304.9378;
    HouseInfo[houseid][hExitPos][2] = 999.1484;
    HouseInfo[houseid][hExitPos][3] = 273.4171;
    HouseInfo[houseid][hInterior] = 2;
    HouseInfo[houseid][hVirtualWorld] = houseid+2;
    HouseInfo[houseid][hType] = 1;
    HouseInfo[houseid][hLock] = 0;
    HouseInfo[houseid][hSafe] = -1;
    format(HouseInfo[houseid][hAddress], 32, "1 San Fierro Drive");
    format(HouseInfo[houseid][hOwner], 35, "None");
    HouseInfo[houseid][hPrice] = 120000;

    format(query, sizeof(query), "INSERT INTO `Houses` (`HouseID`, `Address`, `Owner`, `Price`, `EnterX`, `EnterY`, `EnterZ`, `EnterA`, `ExitX`, `ExitY`, `ExitZ`, `ExitA`, `Interior`, `VirtualWorld`, `Type`, `Lock`, `Safe`) VALUES (%d, \'%s\', \'%s\', %d, %f, %f, %f, %f, %f, %f, %f, %f, %d, %d, %d, %d, %d)",
    HouseInfo[houseid][hHouseID],
    HouseInfo[houseid][hAddress],
    HouseInfo[houseid][hOwner],
    HouseInfo[houseid][hPrice],
    HouseInfo[houseid][hEnterPos][0],
    HouseInfo[houseid][hEnterPos][1],
    HouseInfo[houseid][hEnterPos][2],
    HouseInfo[houseid][hEnterPos][3],
    HouseInfo[houseid][hExitPos][0],
    HouseInfo[houseid][hExitPos][1],
    HouseInfo[houseid][hExitPos][2],
    HouseInfo[houseid][hExitPos][3],
    HouseInfo[houseid][hInterior],
    HouseInfo[houseid][hVirtualWorld],
    HouseInfo[houseid][hType],
    HouseInfo[houseid][hLock],
    HouseInfo[houseid][hSafe]
    );

    mysql_function_query(g_Handle, query, false, "", "");

    HouseInfo[houseid][hPickup] = CreateDynamicPickup(1273, 23, PosX, PosY, PosZ, -1, -1, -1, 100.0);
    format(string, sizeof(string), "Type"White": %s\n"Aqua"Address"White": %s\n"Aqua"Owner"White": %s\n"Aqua"Price"White": $%d\n"Aqua"Status"White": Unlocked", HouseType(houseid), HouseInfo[houseid][hAddress], HouseInfo[houseid][hOwner], HouseInfo[houseid][hPrice]);
    HouseInfo[houseid][hText] = CreateDynamic3DTextLabel(string, COLOR_AQUA, PosX, PosY, PosZ, 25, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 1, -1, -1, -1, 100);

    houseid ++;
    return 1;
}
When I delete a house, it recreates the deleted house but then overwrites any houses after the deleted one?
Reply
#2

It's better to have an enum variable that tells the script weather or not the house is available, like so:
pawn Код:
CMD:createhouse(playerid, params[])
{
    if(!IsPlayerLoggedIn(playerid))
    {
        SendClientMessage(playerid, COLOR_RED, "Error"White": You are restricted from using commands until you log in.");
        return 1;
    }
    if(PlayerInfo[playerid][pAdminLevel] < 1)
    {
        SendClientMessage(playerid, COLOR_RED, "Error"White": You do not have the authority to use this command.");
        return 1;
    }
    if(!AdminDuty[playerid])
    {
        SendClientMessage(playerid, COLOR_RED, "Error"White": You are not on duty as an Administrator (/aduty).");
        return 1;
    }

    new houseid, Float:pos[4], string[80];

    GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
    GetPlayerFacingAngle(playerid, pos[3]);

    houseid = CreateHouse(pos[0], pos[1], pos[2], pos[3]);

    if(houseid == -1) {
        SendClientMessage(playerid, COLOR_RED, "Error"White": There are too many houses created.");
        return 1;
    }

    format(string, sizeof(string), "%s %s has created house ID %d.", AdminRanks(playerid), Player(playerid), houseid);
    SendAdminMessage(string);
    return 1;
}

stock CreateHouse(Float:PosX, Float:PosY, Float:PosZ, Float:PosA)
{
    new houseid = -1, string[200], query[400];

    for(new i = 0; i < MAX_HOUSES; i++) {
        if(! HouseInfo[houseid][hIsCreated]) { // If this slot is available.
            houseid = i; // Use it.
            break; // Stop searching.
        }
    }

    if(houseid == -1) { // Too many houses.
        return houseid;
    }

    [B]HouseInfo[houseid][hIsCreated][/B] = true;
    HouseInfo[houseid][hEnterPos][0] = PosX;
    HouseInfo[houseid][hEnterPos][1] = PosY;
    HouseInfo[houseid][hEnterPos][2] = PosZ;
    HouseInfo[houseid][hEnterPos][3] = PosA;
    HouseInfo[houseid][hExitPos][0] = 266.9708;
    HouseInfo[houseid][hExitPos][1] = 304.9378;
    HouseInfo[houseid][hExitPos][2] = 999.1484;
    HouseInfo[houseid][hExitPos][3] = 273.4171;
    HouseInfo[houseid][hInterior] = 2;
    HouseInfo[houseid][hVirtualWorld] = houseid+2;
    HouseInfo[houseid][hType] = 1;
    HouseInfo[houseid][hLock] = 0;
    HouseInfo[houseid][hSafe] = -1;
    format(HouseInfo[houseid][hAddress], 32, "1 San Fierro Drive");
    format(HouseInfo[houseid][hOwner], 35, "None");
    HouseInfo[houseid][hPrice] = 120000;

    format(query, sizeof(query), "INSERT INTO `Houses` (`HouseID`, `Address`, `Owner`, `Price`, `EnterX`, `EnterY`, `EnterZ`, `EnterA`, `ExitX`, `ExitY`, `ExitZ`, `ExitA`, `Interior`, `VirtualWorld`, `Type`, `Lock`, `Safe`) VALUES (%d, \'%s\', \'%s\', %d, %f, %f, %f, %f, %f, %f, %f, %f, %d, %d, %d, %d, %d)",
        houseid,
        HouseInfo[houseid][hAddress],
        HouseInfo[houseid][hOwner],
        HouseInfo[houseid][hPrice],
        HouseInfo[houseid][hEnterPos][0],
        HouseInfo[houseid][hEnterPos][1],
        HouseInfo[houseid][hEnterPos][2],
        HouseInfo[houseid][hEnterPos][3],
        HouseInfo[houseid][hExitPos][0],
        HouseInfo[houseid][hExitPos][1],
        HouseInfo[houseid][hExitPos][2],
        HouseInfo[houseid][hExitPos][3],
        HouseInfo[houseid][hInterior],
        HouseInfo[houseid][hVirtualWorld],
        HouseInfo[houseid][hType],
        HouseInfo[houseid][hLock],
        HouseInfo[houseid][hSafe]
    );

    mysql_function_query(g_Handle, query, false, "", "");

    HouseInfo[houseid][hPickup] = CreateDynamicPickup(1273, 23, PosX, PosY, PosZ, -1, -1, -1, 100.0);
    format(string, sizeof(string), "Type"White": %s\n"Aqua"Address"White": %s\n"Aqua"Owner"White": %s\n"Aqua"Price"White": $%d\n"Aqua"Status"White": Unlocked", HouseType(houseid), HouseInfo[houseid][hAddress], HouseInfo[houseid][hOwner], HouseInfo[houseid][hPrice]);
    HouseInfo[houseid][hText] = CreateDynamic3DTextLabel(string, COLOR_AQUA, PosX, PosY, PosZ, 25, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 1, -1, -1, -1, 100);
    return houseid;
}
Reply
#3

[debug] Run time error 4: "Array index out of bounds"
[debug] Accessing element at negative index -1
[debug] AMX backtrace:
[debug] #0 0003c324 in ?? (0xc5172d9a, 0x428b147b, 0x420c1000, 0x43076e13) from
MySQL.amx
[debug] #1 00035a38 in public cmd_createhouse (0x00000000, 0x000a9434) from MySQ
L.amx
[debug] #2 native CallLocalFunction () [00472ad0] from samp-server.exe
[debug] #3 000005ac in public OnPlayerCommandText (0x00000000, 0x000a9400) from
MySQL.amx
Reply
#4

Means you're using -1 on an array.
If you did what I did, wouldn't happen cause my code prevents that.
Reply
#5

I can do it like this but when I restart the server it overwrites the existing ones.
I need it so if I have house ID's 1, 2, 3 and 4.. If I delete house ID 2 and 3 it will skip 4 cause it already exists and start creating house ID's 5 and onwards even after server restart.
Reply
#6

I'll need the load code to do it for you.
Reply
#7

I've done it an easier way, but need help on one thing in which I explained thoroughly here:

https://sampforum.blast.hk/showthread.php?tid=510108
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)