[Release] esx_itembytime

esx_itembytime
This script is made it for fivem. basically this give an item to all connected players an a certain amount of time configurable in the files.

INSTALLATION
Drag and drop. You also need to have es_extended.
add to server.cfg
config the item, time and message in the files

Config = {}

local second = 1000
local minute = 60 * second

Config.ItemByTimeInterval     = 60 * minute

Config.Item                   = "ticket"

Config.ItemMessage            = '~g~Has recibido un ticket para ~r~Navidad'

Config.ConsoleNotification    = 'Item by time gived'
4 Likes

Item is given automacilly or you need to type any command?

Good release!

automatically, you just need to set the time in the configuration, the command is only to give the item again when you want

/itembytime

1 Like

This would be good if it was using cron at a time or times every day instead of having to use a command everytime the server is restarted. Nice post though. It has potential.

the command in the server start is not necessary, just start the script with the server and thats all

if u want to use cron just change this

line 5

function AddItemToInventoryByTime()

for this

function AddItemToInventoryByTime(d,h,m)

delete this

function AddItem()
	
	AddItemToInventoryByTime()
	SetTimeout(Config.ItemByTimeInterval, AddItem)
end

AddItem()

and add the cron trigger

TriggerEvent('cron:runAt', 10, 0, AddItemToInventoryByTime)
1 Like

Niceeee

1 Like

I don’t really see the use of this script, it isn’t a certain amount of time since the script itself isn’t removing the item. Basically it is just a giveitem to all poorly written

Heres the code improved but its still one of the most useless scripts I’ve seen

TriggerEvent('es:addGroupCommand', 'itembytime', 'superadmin', function(source, args, user)
    local players = ESX.GetPlayers()
    local item = 'bread' -----------item
    local message = 'hehe xd'  -------------message
    local amount = 1 ------ the amount of the item given

	for i=1, #players, 1 do
		local xPlayer = ESX.GetPlayerFromId(players[i])
		xPlayer.addInventoryItem(item, amount)
		TriggerClientEvent('esx:showNotification', xPlayer.source, message)
	end
end)

this isnt a script to give one specific item to all with a command, this is an script to give that item to all conected players every hour (if you set one hour in the config) its like a first attempt to make a event ticket shop, or in our case, a event for christmas each ticket is a opportunity to win a single unique car

Its a nice online time reward system,but its downside is that it will give you an item every (time set) of the server last restart,that means if we set time cycle to one hour and i login 59 minutes after server restart,i will receive the item despite the fact that i am only 1 minute online,right?
How about change it to a client script that measures time of each player and give him an item with a server trigger every (time set).
Like the afk kick script.
In this way each client will trigger a server event every time and will give the player an item for his/her online time ,not server time.
I will try it and check resource timings in case of lagging.
Thank you for sharing mate.

say i wanted to add this to a society inventory any idea on how i would do that?

ok i can do that, its a good idea

1 Like

add money to this script

config.lua

Config = {}

local second = 1000
local minute = 60 * second

Config.ItemByTimeInterval = 60 * minute

Config.Item = “scratchoff”
Config.money = “1000”

Config.ItemMessage = ‘~g~Has recibido un ticket para ~r~Navidad’

Config.ConsoleNotification = ‘Item by time gived’

server.lua

function AddItemToInventoryByTime(d,h,m)
local players = ESX.GetPlayers()
for i=1, #players, 1 do
local xPlayer = ESX.GetPlayerFromId(players[i])
xPlayer.addInventoryItem(Config.Item, 1)
xPlayer.addMoney(Config.money)
TriggerClientEvent(‘esx:showNotification’, xPlayer.source, Config.ItemMessage)
print(Config.ConsoleNotification)
end
end

1 Like

Is there a way to once a player recieves/finds an item for it start a used by time and then the item is useless. say like it ran out of battery?