Project-Sloth / ps-housing

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

error in consolle when trying to sell a house. #196

Closed Bigfudge87 closed 3 months ago

Bigfudge87 commented 7 months ago

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior:

  1. make a house/property
  2. try to buy the property
  3. nothing happens ingame
  4. error i get in consolle is this

[ script:ps-housing] SCRIPT ERROR: @ps-housing/server/sv_property.lua:256: attempt to index a nil value (local 'targetPlayer') [ script:ps-housing] > handler (@ps-realtor/server/server.lua:17)

Expected behavior i want to buy and sell houses

Screenshots If applicable, add screenshots to help explain your problem.

Additional context i have followed the install guide to the point pluss watched the video on youtube. also tried to ask on the discord. but no answers.

i get the realtor screen where i can list property, the property show up in the sql table. but can`t sell it.

bert1475 commented 7 months ago

Hi BigFudge87 i have solved your problem

if you go in to ps-housing/server/ sv_property.lua and locate:

function Property:UpdateOwner(data)
    local targetSrc = data.targetSrc
    local realtorSrc = data.realtorSrc

    if not realtorSrc then Debug("No Realtor Src found") return end
    if not targetSrc then Debug("No Target Src found") return end

    local previousOwner = self.propertyData.owner

    local targetPlayer  = QBCore.Functions.GetPlayer(tonumber(targetSrc))

    local PlayerData = targetPlayer.PlayerData
    local bank = PlayerData.money.bank
    local citizenid = PlayerData.citizenid

    if self.propertyData.owner == citizenid then
        Framework[Config.Notify].Notify(targetSrc, "You already own this property", "error")
        Framework[Config.Notify].Notify(realtorSrc, "Client already owns this property", "error")
        return
    end

this code will need to be replaced by this code

function Property:UpdateOwner(data)
    local targetSrc = data.targetSrc
    local realtorSrc = data.realtorSrc

    if not realtorSrc then 
        Debug("No Realtor Src found") 
        return 
    end

    if not targetSrc then 
        Debug("No Target Src found") 
        return 
    end

    local targetPlayer  = QBCore.Functions.GetPlayer(tonumber(targetSrc))

    if not targetPlayer then
        Debug("Failed to retrieve target player data")
        return
    end

    local PlayerData = targetPlayer.PlayerData
    local bank = PlayerData.money.bank
    local citizenid = PlayerData.citizenid

    if self.propertyData.owner == citizenid then
        Framework[Config.Notify].Notify(targetSrc, "You already own this property", "error")
        Framework[Config.Notify].Notify(realtorSrc, "Client already owns this property", "error")
        return
    end

then it should work, just to be shure, You should not use the citizen id, but the server id like 1 or 55 and not something like this QKH11580

hope it works :)

Bigfudge87 commented 7 months ago

Thank you so much. seems to work like it should now. only thing missing is pictures of the shells. but everything else works :D

bert1475 commented 7 months ago

The shells is beacause the discord alle the images were located on is deleted, if you want to have stock images, you have to make them yourself and put them in the config.lua

MonkeyWhisper commented 7 months ago

Hi BigFudge87 i have solved your problem

if you go in to ps-housing/server/ sv_property.lua and locate:

function Property:UpdateOwner(data)
    local targetSrc = data.targetSrc
    local realtorSrc = data.realtorSrc

    if not realtorSrc then Debug("No Realtor Src found") return end
    if not targetSrc then Debug("No Target Src found") return end

    local previousOwner = self.propertyData.owner

    local targetPlayer  = QBCore.Functions.GetPlayer(tonumber(targetSrc))

    local PlayerData = targetPlayer.PlayerData
    local bank = PlayerData.money.bank
    local citizenid = PlayerData.citizenid

    if self.propertyData.owner == citizenid then
        Framework[Config.Notify].Notify(targetSrc, "You already own this property", "error")
        Framework[Config.Notify].Notify(realtorSrc, "Client already owns this property", "error")
        return
    end

this code will need to be replaced by this code

function Property:UpdateOwner(data)
    local targetSrc = data.targetSrc
    local realtorSrc = data.realtorSrc

    if not realtorSrc then 
        Debug("No Realtor Src found") 
        return 
    end

    if not targetSrc then 
        Debug("No Target Src found") 
        return 
    end

    local targetPlayer  = QBCore.Functions.GetPlayer(tonumber(targetSrc))

    if not targetPlayer then
        Debug("Failed to retrieve target player data")
        return
    end

    local PlayerData = targetPlayer.PlayerData
    local bank = PlayerData.money.bank
    local citizenid = PlayerData.citizenid

    if self.propertyData.owner == citizenid then
        Framework[Config.Notify].Notify(targetSrc, "You already own this property", "error")
        Framework[Config.Notify].Notify(realtorSrc, "Client already owns this property", "error")
        return
    end

then it should work, just to be shure, You should not use the citizen id, but the server id like 1 or 55 and not something like this QKH11580

hope it works :)

Hello,

Please submit a PR for this so we can credit you