[Free][ESX/QBCore] Christmas Tree / Gifts

Greetings,

Saw someone selling similar script and it got me triggered so… here I am, releasing this within 24h mark as promised.

What is this?

  • This is a simple script allowing you as server owner to give your players something “fun” to do for some rewards.
  • Basically you place xmas tree props in your server (via config) and let your players claim rewards from them once each restart / script restart.

Features

  • Draw3DText, even more simple if you want to utilize target system. Up 2 u in that case

  • Unlimited locations & rewards

  • Optional reward-logging (You must setup it yourself, it’s implemented on the server file but commented out)

  • Includes default loot table and raredrop table with random chance ( supports items, money and weapons by default )

  • Player can claim each tree only once

  • Config option to limit the amount of gifts trees can hold ( default 10 gifts/claims each tree )

  • Config option to enable/disable blips if you want people to hunt for these trees

  • Currently uses steam name to check if player has already claimed tree, maybe change to something like xPlayer.identifier instead? Up 2 you

  • Trees reset each server restart

  • Randomized drops for players, on both default and rare drop tables.

  • Handles the prop spawning, all you have to do yourself is setup the locations and loot tables

  • Also included some admin command snippets for clearing props / vehicles / peds. Has nothing to do with the script itself but just something I might aswell share should someone need it

  • Easy to modify for your needs. Loot table structure supports multiple drops etc.

Config example

Config = {}

--Every player can only claim one gift each tree
Config.maxGifts = 10 --Max gift amount each tree, put ridiculous amount if you want no restriction.

--Enable or disable blips for trees
Config.EnableBlips = true
Config.BlipName = 'Christmas Presents'

--Setup as many trees as you want
Config.Trees = {
  {pos = vector3(242.05, -879.18, 30.49)},
  {pos = vector3(233.09, -875.96, 30.49)},
}


--Setup your default loots
Config.LootTable = {
  [1] = {
    {itemtype = 'item', item = 'bread', amount = 1},
  },
  [2] = {
    {itemtype = 'money', item = 'money', amount = math.random(1,100)},
  },
  [3] = {
    {itemtype = 'weapon', item = 'WEAPON_PISTOL', amount = 1},
  }, --Amount is for ammo when itemtype == weapon
}



--Setup your rare loots
--Check serverside math.randoms and edit to your likings, i defaulted it to 20% chance. Basic maths

Config.RareLootTable = {
  [1] = {
    {itemtype = 'item', item = 'bread', amount = 1},
  },
  [2] = {
    {itemtype = 'money', item = 'money', amount = math.random(1,100)},
  },
  [3] = {
    {itemtype = 'weapon', item = 'WEAPON_PISTOL', amount = 1},
  }, --Amount is for ammo when itemtype == weapon
}

Requirements

  • ESX
  • Some common sense / basic lua coding skills

Misc

  • No support is given, script is in itself simple and it has been well commented. If errors come up they are most likely something very simple to change (xPlayer natives etc) and you should be capable of yourself to fix those issues

  • Script has not been tested on live environment as of now, so problems may occur regarding prop spawn. I doubt since they are not networked entities and should only spawn locally upon playerload.

Anyways, happy holidays and hopefully ya’ll enjoy this bit.

Preview

Download from Github

QBCore version is not tested at all and most likely will not function properly. Good luck.

  • Does not have notifications so implement them by yourself
  • AddItem functions probably are wrong too. Should be fairly easy to fix for someone who is even a little familiar with QBCore. Doesn’t really use that much framework specific functions.

Download from Github - QBCore

Hotfix for ESX
Paste this into es_extended/client/functions
You might have to rename this function, because most likely you have this function already in your functions.lua

ESX.Game.GetClosestObject = function(filter, coords)
	local objects = ESX.Game.GetObjects()
	local closestDistance, closestObject = -1, -1
	local filter, coords = filter, coords

	if type(filter) == 'string' then
		if filter ~= '' then
			filter = {filter}
		end
	end

	if coords then
		coords = vector3(coords.x, coords.y, coords.z)
	else
		local playerPed = PlayerPedId()
		coords = GetEntityCoords(playerPed)
	end

	for i=1, #objects, 1 do
		local foundObject = false

		if filter == nil or (type(filter) == 'table' and #filter == 0) then
			foundObject = true
		else
			local objectModel = GetEntityModel(objects[i])

			for j=1, #filter, 1 do
				if objectModel == GetHashKey(filter[j]) then
					foundObject = true
					break
				end
			end
		end

		if foundObject then
			local objectCoords = GetEntityCoords(objects[i])
			local distance = #(objectCoords - coords)

			if closestDistance == -1 or closestDistance > distance then
				closestObject = objects[i]
				closestDistance = distance
			end
		end
	end

	return closestObject, closestDistance
end
9 Likes

Make it qbcore

Done, Probably won’t work as I’m not familiar with QB. Also not tested.

1 Like

Cleaned up the client/server side for the QBCore version & made a PR

2 Likes

Our Angel!

Hello @Slerbamonsteri ! its not working for me, SCRIPT ERROR: error object is not a string
problem seems to be at line 61 in cl.lua, but i can’t find it
Can u help please :frowning:


I’ve change nothing in the script exept the postions, but i’ve tried with your position and this is the same problem.

@natix

What’s in your line 61? Also QB or ESX?

forgot to edit a line on the qb ver, made new PR

getting this same error. No text showing up. Using ESX

@Natix
@iamproof

Yeah I think the reason is that i have modified getobject function there.

ESX.Game.GetClosestObject = function(filter, coords)
	local objects = ESX.Game.GetObjects()
	local closestDistance, closestObject = -1, -1
	local filter, coords = filter, coords

	if type(filter) == 'string' then
		if filter ~= '' then
			filter = {filter}
		end
	end

	if coords then
		coords = vector3(coords.x, coords.y, coords.z)
	else
		local playerPed = PlayerPedId()
		coords = GetEntityCoords(playerPed)
	end

	for i=1, #objects, 1 do
		local foundObject = false

		if filter == nil or (type(filter) == 'table' and #filter == 0) then
			foundObject = true
		else
			local objectModel = GetEntityModel(objects[i])

			for j=1, #filter, 1 do
				if objectModel == GetHashKey(filter[j]) then
					foundObject = true
					break
				end
			end
		end

		if foundObject then
			local objectCoords = GetEntityCoords(objects[i])
			local distance = #(objectCoords - coords)

			if closestDistance == -1 or closestDistance > distance then
				closestObject = objects[i]
				closestDistance = distance
			end
		end
	end

	return closestObject, closestDistance
end

You could probably slap this in es_extended/client/functions.
If you do not wish to overwrite the other getclosestobject then rename this as like ESX.Game.GetClosestObject2 and use this name in the script too.

Seems not to be working, trees do spawn but no text to claim gifts. No errors messages.

We have the same problem
ESX

Fix is up there mate

so could i just paste that under this in es_extended/client/funtions here?

also another thing i noticed. they are all floating. if you punch it it falls into place lol.

Well you might have one in there already so rename it or replace it completely.
You might need to play with the PlaceObjectOnGround native.

1 Like

i searched for GetClosestObject in that file and thats the only thing that popped up. Do i replace that one or just add the one you suggested under it? (BTW sorry for being a potato)

thats the only one i have which i showed in the screenshot above. still not working and seems a lot of other people having same error.

also what exactly is there to play with here when trying to get the tree on the ground?

image

Could probably add some wait before placing the object etc. I really don’t know what causes props to appear floating in air. Maybe alter the Z -coord -1.0 or something so it places the prop abit more closer to ground.

You could add the function in this post as ESX.Game.GetClosestObject2 and paste it to es_extended/client/functions right under the original ESX.Game.GetClosestObject function. Then go to the xmas script client and change ESX.Game.GetClosestObject to ESX.Game.GetClosestObject2

Should remove QBCore version not working at all, text won’t show but even if fix that issue then server triggers won’t work. Check if already looted not working will not be able to loot any tree anymore. Errors on AddItem and more.