I made something simple for you, play around with it and it should help you to understand
Server:
local bag = {
locations = { --Store your bag locations here
{x = 1547.68, y = -1348.78, z = 329.46}, --Tallest building
{x = 2495.12, y = -1689.36, z = 14.38} --CJs house
}
}
function bag.spawn(x,y,z)
x,y,z = x or 0, y or 0, z or 0
bag.pickup = createPickup( x, y, z, 3, 1550 )
setElementCollisionsEnabled( bag.pickup, false )
end
function bag.init(minutes) --bag.create(int minutes)
if not minutes or isTimer(bag.timer) or isElement(bag.pickup) then return false end --If there is currently a timer, or a bag spawned on the map, then we can't create a new timer/bag
bag.timer = setTimer (function()
local loc = bag.locations
local i = math.random(1,#loc) --Pick a random bag location from bag.locations
bag.spawn(loc[i].x,loc[i].y,loc[i].z) --Spawns the bag. Here we're using a random bag location but you can just define your own x,y,z positions. Random location is optional
end, (60*1000*minutes), 1)
triggerClientEvent(getRootElement(), "createBagTimer", getRootElement(), minutes) --Setup new bag timer for all clients
end
addEvent("onBotWasted",true)
addEventHandler("onBotWasted", root,
function (killer)
if (source == nemesilv) then
destroyElement(BlipNemesislv)
bag.init(20) --Makes a bag spawn after 20 minutes and sets everything up.
end
end)
addEventHandler("onPickupHit", root, --A player picked up the bag
function(player)
destroyElement(bag.pickup) --Destroy bag pickup
local name = getPlayerName(player)
outputChatBox(name.." picked up the bag!")
-- do whatever you want here
end)
Client:
local sX,sY = guiGetScreenSize()
local timerW, timerH = 150,100
local timerX, timerY = (sX / 2) - (timerW / 2), (sY*0.9) - (timerH / 2) --Position of the timer on screen
local bag = {}
function bag.dx()
if not isTimer(bag.timer) then removeEventHandler("onClientRender", root, bag.dx); return end
local clock = convertToClock(bag.timer) --Get the timer remaining in clock format
dxDrawText("Next Bag In: "..clock, timerX, timerY, timerX+timerW, timerY+timerH, tocolor(255,0,0,225), 2, "default-bold", "center", "center")
end
function convertToClock(theTimer) --Returns timer in a clock format (e.g: "19:57"), returns false if timer doesn't exist
if not isTimer(theTimer) then return false end
local remaining = getTimerDetails(theTimer) -- Get the timers remaining (ms)
local s = remaining/1000 --seconds from ms
return string.format("%.2d:%.2d", s/60%60, s%60) --convert to clock format and return
end
function bag.setupTimer(minutes)
bag.timer = setTimer(function()
bag.timer = nil
end, (60*1000*minutes), 1)
addEventHandler("onClientRender", root, bag.dx) --Start drawing the timer on the clients screen
end
addEvent("createBagTimer", true)
addEventHandler("createBagTimer", root, bag.setupTimer)
Any questions, shoot!