i’m stuck in the same, I wish to add WEAPON_BOTTLE with
GiveWeaponToPed(GetPlayerPed(-1), GetHashKey("WEAPON_BOTTLE"), false, true)
but when it comes to the math, it throw me this error:
Error running system event handling function for resource esx-ecobottles: citizen:/scripting/lua/scheduler.lua:41: Failed to execute thread: @esx-ecobottles/server/main.lua:34: attempt to call a nil value (global 'PlayerPedId')
stack traceback:
@esx-ecobottles/server/main.lua:34: in upvalue 'handler'
citizen:/scripting/lua/scheduler.lua:219: in function <citizen:/scripting/lua/scheduler.lua:218>
stack traceback:
[C]: in function 'error'
citizen:/scripting/lua/scheduler.lua:41: in field 'CreateThreadNow'
citizen:/scripting/lua/scheduler.lua:218: in function <citizen:/scripting/lua/scheduler.lua:182>
This is my client.lua -->
ESX = nil
local cachedBins = {}
Citizen.CreateThread(function ()
while ESX == nil do
TriggerEvent('esx:getSharedObject', function(obj)
ESX = obj
end)
Citizen.Wait(5)
end
end)
Citizen.CreateThread(function()
Citizen.Wait(100)
for locationIndex = 1, #Config.SellBottleLocations do
local locationPos = Config.SellBottleLocations[locationIndex]
local blip = AddBlipForCoord(locationPos)
SetBlipSprite (blip, 409)
SetBlipDisplay(blip, 4)
SetBlipScale (blip, 0.8)
SetBlipColour (blip, 48)
SetBlipAsShortRange(blip, true)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString("Vender Botellas Vacias")
EndTextCommandSetBlipName(blip)
end
while true do
local sleepThread = 500
local ped = PlayerPedId()
local pedCoords = GetEntityCoords(ped)
for locationIndex = 1, #Config.SellBottleLocations do
local locationPos = Config.SellBottleLocations[locationIndex]
local dstCheck = GetDistanceBetweenCoords(pedCoords, locationPos, true)
if dstCheck <= 5.0 then
sleepThread = 5
local text = "Vender Botellas Vacias"
if dstCheck <= 1.5 then
text = "[~g~E~s~] " .. text
if IsControlJustReleased(0, 38) then
TriggerServerEvent("esx-ecobottles:sellBottles")
end
end
ESX.Game.Utils.DrawText3D(locationPos, text, 0.8)
end
end
Citizen.Wait(sleepThread)
end
end)
Citizen.CreateThread(function()
Citizen.Wait(100)
while true do
local playerPed = PlayerPedId()
local playerCoords = GetEntityCoords(playerPed)
local entity, entityDst = ESX.Game.GetClosestObject(Config.BinsAvailable)
local binCoords = GetEntityCoords(entity)
if DoesEntityExist(entity) then
while GetDistanceBetweenCoords(playerCoords,binCoords) <= 2.0 do
binCoords = GetEntityCoords(entity)
playerCoords = GetEntityCoords(playerPed)
ESX.Game.Utils.DrawText3D(binCoords + vector3(0.0, 0.0, 0.5), "[~g~E~s~] Revisar basura", 0.8)
if IsControlJustReleased(0, 38) then
if not cachedBins[entity] then
cachedBins[entity] = true
OpenTrashCan()
else
ESX.ShowNotification("~r~Ya revisaste esta basura!")
end
end
Citizen.Wait(0)
end
end
Citizen.Wait(1000)
end
end)
-- Citizen.CreateThread(function()
-- Citizen.Wait(100)
-- while true do
-- local sleepThread = 1000
-- local entity, entityDst = ESX.Game.GetClosestObject(Config.BinsAvailable)
-- if DoesEntityExist(entity) and entityDst <= 2.0 then
-- sleepThread = 5
-- local binCoords = GetEntityCoords(entity)
-- ESX.Game.Utils.DrawText3D(binCoords + vector3(0.0, 0.0, 0.5), "[~g~E~s~] Revisar basura", 0.8)
-- if IsControlJustReleased(0, 38) then
-- if not cachedBins[entity] then
-- cachedBins[entity] = true
-- OpenTrashCan()
-- else
-- ESX.ShowNotification("Ya revisaste esta basura!")
-- end
-- end
-- end
-- Citizen.Wait(sleepThread)
-- end
-- end)
function OpenTrashCan()
TaskStartScenarioInPlace(PlayerPedId(), "PROP_HUMAN_BUM_BIN", 0, true)
Citizen.Wait(10000)
TriggerServerEvent("esx-ecobottles:retrieveBottle")
ClearPedTasks(PlayerPedId())
end
Server.lua —>
local ESX = nil
TriggerEvent("esx:getSharedObject", function(obj)
ESX = obj
end)
RegisterServerEvent("esx-ecobottles:sellBottles")
AddEventHandler("esx-ecobottles:sellBottles", function()
local player = ESX.GetPlayerFromId(source)
local currentBottles = player.getInventoryItem("bottle")["count"]
if currentBottles > 0 then
math.randomseed(os.time())
local randomMoney = math.random((Config.BottleReward[1] or 10), (Config.BottleReward[2] or 40))
player.removeInventoryItem("bottle", currentBottles)
player.addMoney(randomMoney * currentBottles)
TriggerClientEvent("esx:showNotification", source, ("Entregaste al local %s botellas y recibiste como pago $%s."):format(currentBottles, currentBottles * randomMoney))
else
TriggerClientEvent("esx:showNotification", source, "No tenes botellas vacias para entregarle al local.")
end
end)
RegisterServerEvent("esx-ecobottles:retrieveBottle")
AddEventHandler("esx-ecobottles:retrieveBottle", function()
local player = ESX.GetPlayerFromId(source)
math.randomseed(os.time())
local luck = math.random(0, 100)
local randomBottle = math.random((Config.BottleRecieve[1] or 1), (Config.BottleRecieve[2] or 6))
local randomBandage = math.random((Config.BandageRecieve[1] or 1), (Config.BandageRecieve[2] or 2))--
--local weaponbottle = math.random ((Config.WeaponBottle[1] or 1), (Config.WeaponBottle[1] or 1)) --
if luck >= 0 and luck <= 29 then
TriggerClientEvent("esx:showNotification", source, "No habia nada interesante en la basura.")
end
if luck >= 30 and luck <= 35 then
player.addInventoryItem("bandage", randomBandage)
TriggerClientEvent("esx:showNotification", source, ("Encontraste x%s ~y~Vendaje!"):format(randomBandage))
end
if luck >= 36 and luck <= 42 then
player.addInventoryItem("bandage", randomBandage)
TriggerClientEvent("esx:showNotification", source, ("Encontraste x%s ~y~Vendaje!"):format(randomBandage))
player.addInventoryItem("bottle", randomBottle)
TriggerClientEvent("esx:showNotification", source, ("Encontraste x%s ~g~Botellas vacia"):format(randomBottle))
end
--if luck >= 42 and luck <= 64 then
--local player = GetPlayerPed(-1)
TriggerClientEvent("esx:showNotification", source, "No habia nada interesante en la basura.(BOTELLA ERROR)")
-- TriggerClientEvent("esx:showNotification", source, ("Encontraste x%s ~o~Botella Partida! está afilada!"):format(weaponbottle))
--end
if luck >= 65 and luck <= 100 then
player.addInventoryItem("bottle", randomBottle)
TriggerClientEvent("esx:showNotification", source, ("Encontraste x%s ~g~Botellas vacia"):format(randomBottle))
end
end)