Project-Sloth / ps-housing

Advanced housing system for QBCore.
https://discord.gg/projectsloth
Other
343 stars 110 forks source link

Property.Get(id) returns nil, causing failure to locate existing property ID #258

Closed Jerrys-C closed 1 week ago

Jerrys-C commented 1 week ago

Describe the bug When using the Property.Get(id) function, it returns nil even though the specified property_id exists in the PropertiesTable. Debugging suggests that this is caused by inconsistent key types in PropertiesTable.

To Reproduce resources[ps]\ps-housing\server\server.lua

function Property.Get(property_id)
    local id = tostring(property_id)
    local property = PropertiesTable[id]

    if not property then
        print("Error: Property not found for ID " .. id)
        for k, v in pairs(PropertiesTable) do
            print("Existing Property Key:", k, "Data:", v)
        end
    end

    return property
end

resources[ps]\ps-housing\server\sv_property.lua

        local src = player.PlayerData.source
        local property_index = PropertiesTable[id]
        print('Property with index', property_index)
        local property = Property.Get(id)
        print('Property with Get', property)
        print(json.encode(PropertiesTable))

        if not property then
            print("Error: Property not found for ID " .. id)
            return
        end

Server console output

17:31:57 [   script:ps-housing] Creating new apartment for Jerry in Morningwood Blvd
17:31:57 [   script:ps-housing] Property with index     table: 0000020DC39209C0
17:31:57 [   script:ps-housing] Error: Property not found for ID 7
17:31:57 [   script:ps-housing] Existing Property Key:  7       Data:   table: 0000020DC39209C0
17:31:57 [   script:ps-housing] Existing Property Key:  5       Data:   table: 0000020DC38AB400
17:31:57 [   script:ps-housing] Existing Property Key:  6       Data:   table: 0000020DC38AB6C0
17:31:57 [   script:ps-housing] Property with Get       nil
17:31:57 [   script:ps-housing] {"7":{"playersDoorbell":[],"playersInside":[],"playersInGarden":[],"property_id":"7","propertyData":{"description":"This is Jerry 4's apartment in Morningwood Blvd","for_sale":0,"furnitures":[],"extra_imgs":[],"shell":"Apartment Furnished","property_id":7,"apartment":"Morningwood Blvd","zone_data":[],"garage_data":[],"door_data":[],"has_access":[],"owner":"MU9G97J2"}},"5":{"playersDoorbell":[],"playersInside":[],"playersInGarden":[],"property_id":"5","propertyData":{"description":"This is Jerry 1's apartment in Tinsel Towers","for_sale":false,"furnitures":[],"owner":"P9T4VQM0","shell":"Apartment Furnished","zone_data":"[]","garage_data":[],"apartment":"Tinsel Towers","extra_imgs":[],"price":0,"door_data":[],"property_id":"5","has_access":[]}},"6":{"playersDoorbell":[],"playersInside":[],"playersInGarden":[],"property_id":"6","propertyData":{"description":"This is Jerry 2's apartment in Fantastic Plaza","for_sale":false,"furnitures":[],"owner":"L9V55317","shell":"Apartment Furnished","zone_data":"[]","garage_data":[],"apartment":"Fantastic Plaza","extra_imgs":[],"price":0,"door_data":[],"property_id":"6","has_access":[]}}}
Jerrys-C commented 1 week ago

251 This change appears to affect how the property_id keys are matched in PropertiesTable, which is causing Property.Get(id) to return nil for certain IDs