Dynamic Object Creating
#1

Hello. When I buy a safe for my house using a dialog it creates the safe and places it inside for me.

pawn Код:
if(dialogid == DIALOG_FURNI)
    {
        new string[128], i = PlayerInfo[playerid][pHouse];
        if(response)
        {
            switch(listitem)
            {
                case 0:
                {
                    if(PlayerInfo[playerid][pCash] < Safe)
                    {
                        SendClientMessage(playerid, COLOR_RED, "Error"White": You don't have enough cash to purchase a house safe.");
                        return 1;
                    }
                    if(HouseInfo[i][hSafe] >= 0)
                    {
                        SendClientMessage(playerid, COLOR_RED, "Error"White": Your house already contains a safe.");
                        return 1;
                    }
                    else
                    {
                        HouseInfo[i][hSafe] = CreateDynamicObject(2332, 273.93460, 304.21188, 998.54669, 356.85840, 0.00000, 270.00000, HouseInfo[i][hVirtualWorld], HouseInfo[i][hInterior], -1, 300.0);
                        format(string, sizeof(string), "Shop Assistant"White": You have purchased a House Safe for "Green"$%d"White". It has been placed in your house automatically!", Safe);
                        SendClientMessage(playerid, COLOR_YELLOW, string);
                        GiveCash(playerid, -Safe);
                        SaveHouse(i);
                        return 1;
                    }
                }
            }
        }
    }
But when I reload the game mode, it loads all other house information but it doesn't create the safe object?

pawn Код:
public HousesLoad()
{
    new temp[400], string[200], rows, fields;
    cache_get_data(rows, fields, g_Handle);

    new id = 0;
    if(rows)
    {
        while(id <= rows-1)
        {
            cache_get_row(id, 0, temp, g_Handle), HouseInfo[id][hHouseID] = strval(temp);
            cache_get_row(id, 1, HouseInfo[id][hAddress], g_Handle, 32);
            cache_get_row(id, 2, HouseInfo[id][hOwner], g_Handle, 35);
            cache_get_row(id, 3, temp, g_Handle), HouseInfo[id][hPrice] = strval(temp);
            cache_get_row(id, 4, temp, g_Handle), HouseInfo[id][hEnterPos][0] = floatstr(temp);
            cache_get_row(id, 5, temp, g_Handle), HouseInfo[id][hEnterPos][1] = floatstr(temp);
            cache_get_row(id, 6, temp, g_Handle), HouseInfo[id][hEnterPos][2] = floatstr(temp);
            cache_get_row(id, 7, temp, g_Handle), HouseInfo[id][hEnterPos][3] = floatstr(temp);
            cache_get_row(id, 8, temp, g_Handle), HouseInfo[id][hExitPos][0] = floatstr(temp);
            cache_get_row(id, 9, temp, g_Handle), HouseInfo[id][hExitPos][1] = floatstr(temp);
            cache_get_row(id, 10, temp, g_Handle), HouseInfo[id][hExitPos][2] = floatstr(temp);
            cache_get_row(id, 11, temp, g_Handle), HouseInfo[id][hExitPos][3] = floatstr(temp);
            cache_get_row(id, 12, temp, g_Handle), HouseInfo[id][hInterior] = strval(temp);
            cache_get_row(id, 13, temp, g_Handle), HouseInfo[id][hVirtualWorld] = strval(temp);
            cache_get_row(id, 14, temp, g_Handle), HouseInfo[id][hType] = strval(temp);
            cache_get_row(id, 15, temp, g_Handle), HouseInfo[id][hLock] = strval(temp);
            cache_get_row(id, 16, temp, g_Handle), HouseInfo[id][hSafe] = strval(temp);

            if(HouseInfo[id][hSafe] != -1)
            {
                HouseInfo[id][hSafe] = CreateDynamicObject(2332, 273.93460, 304.21188, 998.54669, 356.85840, 0.00000, 270.00000, HouseInfo[id][hVirtualWorld], HouseInfo[id][hInterior], -1, 300.0);
                SaveHouse(id);
            }
           
            if(!strcmp("None", HouseInfo[id][hOwner], false))
            {
                HouseInfo[id][hPickup] = CreateDynamicPickup(1273, 23, HouseInfo[id][hEnterPos][0], HouseInfo[id][hEnterPos][1], HouseInfo[id][hEnterPos][2], -1, -1, -1, 100.0);
                format(string, sizeof(string), "Type"White": %s\n"Aqua"Address"White": %s\n"Aqua"Owner"White": None\n"Aqua"Price"White": $%d\n"Aqua"Status"White": Unlocked", HouseType(id), HouseInfo[id][hAddress], HouseInfo[id][hPrice]);
                HouseInfo[id][hText] = CreateDynamic3DTextLabel(string, COLOR_AQUA, HouseInfo[id][hEnterPos][0], HouseInfo[id][hEnterPos][1], HouseInfo[id][hEnterPos][2], 25, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 1, -1, -1, -1, 100);
            }
            else
            {
                HouseInfo[id][hPickup] = CreateDynamicPickup(1273, 23, HouseInfo[id][hEnterPos][0], HouseInfo[id][hEnterPos][1], HouseInfo[id][hEnterPos][2], -1, -1, -1, 100.0);
                format(string, sizeof(string), "Type"White": %s\n"Aqua"Address"White": %s\n"Aqua"Owner"White": %s\n"Aqua"Status"White": %s", HouseType(id), HouseInfo[id][hAddress], HouseInfo[id][hOwner], HouseStatus(id));
                HouseInfo[id][hText] = CreateDynamic3DTextLabel(string, COLOR_AQUA, HouseInfo[id][hEnterPos][0], HouseInfo[id][hEnterPos][1], HouseInfo[id][hEnterPos][2], 25, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 1, -1, -1, -1, 100);
            }
            id ++;
        }
        houseid = rows;
    }
    else
    {
        for(new i = 0; i < MAX_HOUSES; i++)
        {
            HouseInfo[i][hHouseID] = -1;
        }
    }
    return 1;
}
Thanks
Reply
#2

Try:
if(HouseInfo[id][hSafe] != INVALID_OBJECT_ID)

Instead of:
if(HouseInfo[id][hSafe] != -1)

Also show the SaveHouse code, if you're saving GameObjectID, I suggest not doing so because it won't always be the same.
Reply
#3

Quote:
Originally Posted by SkittlesAreFalling
Посмотреть сообщение
Try:
if(HouseInfo[id][hSafe] != INVALID_OBJECT_ID)

Instead of:
if(HouseInfo[id][hSafe] != -1)

Also show the SaveHouse code, if you're saving GameObjectID, I suggest not doing so because it won't always be the same.
Almost had it working but realised it then recreates the safe when I restart the game mode.
Seems like -1 is not an invalid object id..
Reply
#4

Oh I'm not using MAX_OBJECTS, just realised.
I do it like this:

pawn Код:
HouseInfo[id][hSafe] = CreateDynamicObject(2332, 273.93460, 304.21188, 998.54669, 356.85840, 0.00000, 270.00000, HouseInfo[id][hVirtualWorld], HouseInfo[id][hInterior], -1, 300.0);
Reply
#5

No it is not.

What you're doing is saving the Game Object ID into column 0 in the "houses" (I'm assuming) table.

The solution is to instead save a 1-bit number like 0 and 1, 0 will mean the house doesn't have a safe, and 1 will mean it does have a safe.
To detect if the house has a safe or not, when saving make it see if the game object != invalid game object id
- if it does have a safe make it save as 1
- if not save as 0
Then when loading to check if the house has a safe or not, check if the number is 0 if it's not 0 create the safe.
Reply
#6

Wow, this works now:

pawn Код:
public HousesLoad()
{
    new temp[400], string[200], rows, fields;
    cache_get_data(rows, fields, g_Handle);

    new id = 0;
    if(rows)
    {
        while(id <= rows-1)
        {
            cache_get_row(id, 0, temp, g_Handle), HouseInfo[id][hHouseID] = strval(temp);
            cache_get_row(id, 1, HouseInfo[id][hAddress], g_Handle, 32);
            cache_get_row(id, 2, HouseInfo[id][hOwner], g_Handle, 35);
            cache_get_row(id, 3, temp, g_Handle), HouseInfo[id][hPrice] = strval(temp);
            cache_get_row(id, 4, temp, g_Handle), HouseInfo[id][hEnterPos][0] = floatstr(temp);
            cache_get_row(id, 5, temp, g_Handle), HouseInfo[id][hEnterPos][1] = floatstr(temp);
            cache_get_row(id, 6, temp, g_Handle), HouseInfo[id][hEnterPos][2] = floatstr(temp);
            cache_get_row(id, 7, temp, g_Handle), HouseInfo[id][hEnterPos][3] = floatstr(temp);
            cache_get_row(id, 8, temp, g_Handle), HouseInfo[id][hExitPos][0] = floatstr(temp);
            cache_get_row(id, 9, temp, g_Handle), HouseInfo[id][hExitPos][1] = floatstr(temp);
            cache_get_row(id, 10, temp, g_Handle), HouseInfo[id][hExitPos][2] = floatstr(temp);
            cache_get_row(id, 11, temp, g_Handle), HouseInfo[id][hExitPos][3] = floatstr(temp);
            cache_get_row(id, 12, temp, g_Handle), HouseInfo[id][hInterior] = strval(temp);
            cache_get_row(id, 13, temp, g_Handle), HouseInfo[id][hVirtualWorld] = strval(temp);
            cache_get_row(id, 14, temp, g_Handle), HouseInfo[id][hType] = strval(temp);
            cache_get_row(id, 15, temp, g_Handle), HouseInfo[id][hLock] = strval(temp);
            cache_get_row(id, 16, temp, g_Handle), HouseInfo[id][hSafe] = strval(temp);
           
            if(!strcmp("None", HouseInfo[id][hOwner], false))
            {
                HouseInfo[id][hPickup] = CreateDynamicPickup(1273, 23, HouseInfo[id][hEnterPos][0], HouseInfo[id][hEnterPos][1], HouseInfo[id][hEnterPos][2], -1, -1, -1, 100.0);
                format(string, sizeof(string), "Type"White": %s\n"Aqua"Address"White": %s\n"Aqua"Owner"White": None\n"Aqua"Price"White": $%d\n"Aqua"Status"White": Unlocked", HouseType(id), HouseInfo[id][hAddress], HouseInfo[id][hPrice]);
                HouseInfo[id][hText] = CreateDynamic3DTextLabel(string, COLOR_AQUA, HouseInfo[id][hEnterPos][0], HouseInfo[id][hEnterPos][1], HouseInfo[id][hEnterPos][2], 25, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 1, -1, -1, -1, 100);
            }
            else
            {
                HouseInfo[id][hPickup] = CreateDynamicPickup(1273, 23, HouseInfo[id][hEnterPos][0], HouseInfo[id][hEnterPos][1], HouseInfo[id][hEnterPos][2], -1, -1, -1, 100.0);
                format(string, sizeof(string), "Type"White": %s\n"Aqua"Address"White": %s\n"Aqua"Owner"White": %s\n"Aqua"Status"White": %s", HouseType(id), HouseInfo[id][hAddress], HouseInfo[id][hOwner], HouseStatus(id));
                HouseInfo[id][hText] = CreateDynamic3DTextLabel(string, COLOR_AQUA, HouseInfo[id][hEnterPos][0], HouseInfo[id][hEnterPos][1], HouseInfo[id][hEnterPos][2], 25, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 1, -1, -1, -1, 100);
            }
            if(HouseInfo[id][hSafe] > 0)
            {
                HouseInfo[id][hSafe] = CreateDynamicObject(2332, 273.93460, 304.21188, 998.54669, 356.85840, 0.00000, 270.00000, HouseInfo[id][hVirtualWorld], HouseInfo[id][hInterior], -1, 300.0);
                SaveHouse(id);
            }
            id ++;
        }
        houseid = rows;
    }
    else
    {
        for(new i = 0; i < MAX_HOUSES; i++)
        {
            HouseInfo[i][hHouseID] = -1;
        }
    }
    return 1;
}
Don't understand what the difference is but there we go ha. Thanks
Reply
#7

That won't work if the house doesn't have a safe.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)