Skip to content

Commit

Permalink
Furniture fixed (#10)
Browse files Browse the repository at this point in the history
* furnFixed

* versbump
  • Loading branch information
jakeyboi1 authored Jul 28, 2023
1 parent bb4b563 commit d04f8d7
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 35 deletions.
1 change: 0 additions & 1 deletion client/MainHousing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ CreateThread(function() --Devmode area
TriggerServerEvent("bcc-housing:getPlayersInfo", player) --credit vorp_admin
TriggerServerEvent('bcc-housing:AdminCheck')
TriggerServerEvent('bcc-housing:HotelDbRegistry')

TriggerServerEvent('bcc-housing:CheckIfHasHouse')
end)
end
Expand Down
13 changes: 12 additions & 1 deletion client/MenuSetup/furnitureMenu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,9 @@ function PlaceFurnitureIntoWorldMenu(model, cost, displayName, sellPrice)
SetEntityCollision(createdObject, true, true)
FreezeEntityPosition(createdObject)
local co = GetEntityCoords(createdObject)
local coords = { x = co.x, y = co.y, z = co.z, h = GetEntityHeading(createdObject) }
local cr = GetEntityRotation(createdObject)
local furnitureCreatedTable = { model = model, coords = co, rotation = cr, displayName = displayName, sellprice = sellPrice }
local furnitureCreatedTable = { model = model, coords = coords, rotation = cr, displayName = displayName, sellprice = sellPrice }
local entId = NetworkGetNetworkIdFromEntity(createdObject)
furnObj = createdObject
TriggerServerEvent('bcc-housing:BuyFurn', cost, entId, furnitureCreatedTable)
Expand Down Expand Up @@ -319,6 +320,16 @@ RegisterNetEvent('bcc-housing:SellOwnedFurnMenu', function(furnTable)
_G[data.trigger]()
end
if data.current.value then
for k, v in pairs(CreatedFurniture) do
local storedFurnCoord = GetEntityCoords(v)
local firstVec = vector3(tonumber(storedFurnCoord.x), tonumber(storedFurnCoord.y), tonumber(storedFurnCoord.z))
local secondVec = vector3(tonumber(data.current.info.coords.x), tonumber(data.current.info.coords.y), tonumber(data.current.info.coords.z))
local dist = #(firstVec - secondVec)
if dist < 0.5 then --used as a way to check if the loop is on the correct piece of furniture
table.remove(CreatedFurniture, k)
DeleteEntity(v)
end
end
TriggerServerEvent('bcc-housing:FurnSoldRemoveFromTable', data.current.info, HouseId, furnTable, data.current.info2)
end
end)
Expand Down
1 change: 1 addition & 0 deletions client/furnitureSpawning.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ RegisterNetEvent('bcc-housing:SpawnFurnitureEvent', function(furnTable)
for k, v in pairs(furnTable) do
local model = joaat(v.model)
local createdObject = CreateObject(model, v.coords.x, v.coords.y, v.coords.z, true, true)
SetEntityHeading(v.coords.h)
FreezeEntityPosition(createdObject, true)
table.insert(CreatedFurniture, createdObject)
local entId = NetworkGetNetworkIdFromEntity(createdObject)
Expand Down
1 change: 0 additions & 1 deletion config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ Config.Furniture = {
{ propModel = 'p_couch05x', displayName = 'Leathersofa', costToBuy = 80, sellFor = 60 },
},
Beds = {
{ propModel = 'p_bedlog01x', displayName = 'bed frame', costToBuy = 80, sellFor = 60 },
{ propModel = 'p_bed04x', displayName = 'wooden bed', costToBuy = 80, sellFor = 60 },
{ propModel = 'p_bed05x', displayName = 'wooden bed 2', costToBuy = 80, sellFor = 60 },
{ propModel = 'p_bed17x', displayName = 'wooden bed 3', costToBuy = 80, sellFor = 60 },
Expand Down
2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ dependency {
'bcc-doorlocks'
}

version '1.0.2'
version '1.0.3'
48 changes: 17 additions & 31 deletions server/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,13 @@ RegisterServerEvent('bcc-housing:FurniturePlacedCheck', function(houseid, deleti
end)

RegisterServerEvent('bcc-housing:StoreFurnForDeletion', function(entId, houseid) --this is used to store the entity id of each piece of furniture in the table for when it is deleted
if storedFurn[source] == nil then
storedFurn[source] = {}
local param = { ['houseid'] = houseid, ['source'] = tostring(source) }
local _source = source
if storedFurn[_source] == nil then
storedFurn[_source] = {}
local param = { ['houseid'] = houseid, ['source'] = tostring(_source) }
exports.oxmysql:execute("UPDATE bcchousing SET player_source_spawnedfurn=@source", param)
end
table.insert(storedFurn[source], entId)
table.insert(storedFurn[_source], entId)
end)

AddEventHandler('playerDropped', function() --when you leave checks if you had furn spawned in and if so it deletes it
Expand Down Expand Up @@ -281,35 +282,20 @@ end)
RegisterServerEvent('bcc-housing:FurnSoldRemoveFromTable', function(furnTable, houseid, wholeFurnTable, wholeFurnTableKey) --selling furn handler
local _source = source
local character = VORPcore.getUser(_source).getUsedCharacter
local param = { ['houseid'] = houseid, ['source'] = tostring(_source) }
local result = MySQL.query.await("SELECT * FROM bcchousing WHERE houseid=@houseid", param)

for k, v in pairs(storedFurn[tonumber(result[1].player_source_spawnedfurn)]) do
local netEntId = NetworkGetEntityFromNetworkId(v)
local storedFurnCoord = GetEntityCoords(netEntId)
local firstVec = vector3(tonumber(storedFurnCoord.x), tonumber(storedFurnCoord.y), tonumber(storedFurnCoord.z))
local secondVec = vector3(tonumber(furnTable.coords.x), tonumber(furnTable.coords.y), tonumber(furnTable.coords.z))
local dist = #(firstVec - secondVec)

if dist < 0.5 then --used as a way to check if the loop is on the correct piece of furniture
table.remove(storedFurn[tonumber(result[1].player_source_spawnedfurn)], k)
table.remove(wholeFurnTable, tonumber(wholeFurnTableKey))
DeleteEntity(netEntId)

local newDbTable
if #wholeFurnTable > 0 then
newDbTable = json.encode(wholeFurnTable)
else
newDbTable = 'none'
end
local newParam = { ['houseid'] = houseid, ['newFurnTable'] = newDbTable }
exports.oxmysql:execute("UPDATE bcchousing SET furniture=@newFurnTable WHERE houseid=@houseid", newParam)
VORPcore.NotifyRightTip(_source, _U("furnSold"), 4000)
character.addCurrency(0, tonumber(furnTable.sellprice))
discord:sendMessage(_U("furnWebHookSold") .. character.charIdentifier, _U("furnWebHookSoldModel") .. tostring(furnTable.model) .. _U("furnWebHookSoldPrice") .. tostring(furnTable.sellprice))
TriggerClientEvent('bcc-housing:ClientCloseAllMenus', _source) break
end
table.remove(wholeFurnTable, tonumber(wholeFurnTableKey))
local newDbTable
if #wholeFurnTable > 0 then
newDbTable = json.encode(wholeFurnTable)
else
newDbTable = 'none'
end
local newParam = { ['houseid'] = houseid, ['newFurnTable'] = newDbTable }
exports.oxmysql:execute("UPDATE bcchousing SET furniture=@newFurnTable WHERE houseid=@houseid", newParam)
VORPcore.NotifyRightTip(_source, _U("furnSold"), 4000)
character.addCurrency(0, tonumber(furnTable.sellprice))
discord:sendMessage(_U("furnWebHookSold") .. character.charIdentifier, _U("furnWebHookSoldModel") .. tostring(furnTable.model) .. _U("furnWebHookSoldPrice") .. tostring(furnTable.sellprice))
TriggerClientEvent('bcc-housing:ClientCloseAllMenus', _source)
end)

CreateThread(function() --Tax handling
Expand Down

0 comments on commit d04f8d7

Please sign in to comment.