How to monetize your fivem server

Right. It appears {identifier} and {id} tokens have been (incorrectly) using a Tebex-internal identifier due to a slight oversight in reading somewhat outdated documentation on Tebex’s end.

A new server version will be pushed in a few minutes fixing this, alternately you can use {uuid} as a workaround to refer to the user’s fivem:* identifier - but we generally would suggest using {identifier} in the end in case non-Cfx.re accounts get supported in the future.

2 Likes

Do you mean new artifacts? The newest one still seems to be week old. Or am I missing something?

2744 2020-07-21 17:48:55

I see the list got updated. For some reason, only 2744 was visible to me. Now I see also newer versions. Thank you for the update! Now it works like a charm!

I am using es_extended and wanted to make a tebex store for my server so player could donate for in-game money. I have tried a couple of thing, but still get no result from it. If anyone is willing to help me it would be great appreciated. Thank :slight_smile:

Did you succeed to get Tebex to execute a command on your server at least?

So, I’m trying to make this script, that will allow to add money (callback from database) on top of otherwise standard paycheck.

But I’m unsure, how to correctly execute it. Maybe you could take a look at it? I basically took IRL jail time jailer script and edited it a bit, to demonstrate what I’m trying to make here. This idea is actually based on a suggestion of my players, as they are not happy about just adding money to account. This money boost should encourage players to still actually play and work for their reward (but to also make their life easier for exchange). If @Jager_Bom could help out as well on this, since he made that perfect Jail script, working on similar principle, that would be awesome!

Here’s roughly what I’m after. Excuse the mess, this is simply too complex task for me. Hopefully, you will get the idea from looking at it

ESX = nil

TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)

--[[
CREATE TABLE IF NOT EXISTS `tebex_rewards` (
  `identifier` varchar(100) NOT NULL,
  `No1` varchar(100) DEFAULT '50',
  `No1_time` int(11) unsigned DEFAULT NULL,
  `No2` int(11) DEFAULT '20',
  `No2_time` int(11) unsigned DEFAULT NULL,
  `No3` int(11) DEFAULT '10',
  `No3_time` int(11) unsigned DEFAULT NULL,
  `No4` int(11) DEFAULT '5',
  `No4_time` int(11) unsigned DEFAULT NULL,
  PRIMARY KEY (`identifier`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
]]

RegisterCommand("ActivatingBoostNo1", ActivatingBoostNo1, true) -- comming from tebex

function ActivatingBoostNo1(_, arg)
	
	local identifier = arg[1] 	--identifier = "fivem:111111" -- example of identifier passed by from Tebex
	local ThisBoostTimeValue = 864000	-- equivalent to 10 days for perk boost
	currenttime = os.time(os.date("!*t"))
	print(currenttime)
	-- let's check, if there is already printed record in DB
	MySQL.Async.fetchAll("SELECT * FROM tebex_rewards WHERE identifier=@identifier VALUES (@identifier,@No1_time)" {
	['@identifier'] = identifier
	}, function(result)
		if result[1] ~= nil and result[1] > currenttime then -- checking if record is already there? And also, if the already written value is still higher than current time - we want to add timelimit, not to cut it down by new order
			MySQL.Async.execute("INSERT INTO tebex_rewards (No1_time) VALUES (@No1_time) ON DUPLICATE KEY UPDATE No1_time=@No1_time", {
				['@No1_time'] = result[1] + ThisBoostTimeValue
				}
			)
		else -- normal record, alternatively, rewrite of the previous, old one
			MySQL.Async.execute("INSERT INTO tebex_rewards (identifier,No1_time) VALUES (@identifier,@No1_time) ON DUPLICATE KEY UPDATE identifier=@identifier,No1_time=@No1_time", {
			['@identifier'] = identifier,
			['@No1_time'] = currenttime + ThisBoostTimeValue
				}
			)
		end
	end)
end


-- callback being called from any job related script that operates payouts, to be able to add to value due to perks being active
ESX.RegisterServerCallback('tebex-rewards:ReadAvailableRewards', function(source, cb)
	MySQL.Async.fetchAll("SELECT * FROM tebex_rewards WHERE identifier=@identifier", {['@identifier'] = identifier}, function(result)	

	--[[
	
	-- how to check available individual rewards via timestamp limit from SQL?
	-- No1_time, No2_time, No3_time, No4_time -> if those are still active (ahead of actual time) or not?
	-- and how to get correctly result of time difference/availability of those perks?
	-- 
	
	]]
	
	cb(result)	--	if no result (no perks have been found), then cb(false) - somehow
	end)
end)

I will really appreciate any help on this. And I guess there will be more people that could benefit from this as well :slight_smile:

Not sure what this has to do with the OP?

That’s a really good idea!! Good job

You can specify this server side.

StandardPackage (identifier)
   local xPlayer = ESX.GetPlayerFromId(identifier)
   xPlayer.addInventoryItem(currency, amount)	
end

Okok I’ll try! Thank you Moravian!

1 Like

How does a command execution permission work? I created the command, but any player can execute it if they know the command!

The third argument in RegisterCommand sets the command restricted to only those who have permissions to it. In your case, only the console.

Hey,

How do you get the fivem id given by tebex directly into play?

Use {sid} in tebex command.

yes but how do I use it on the server side because I can’t compare it with an existing value

1 Like

{sid} is that users game id at the time they are online

I was thinking that a good solution would be to handle the callback differently based on whether the player is online or not (instead of requiring the player to be online). Loop through all players, if one player has the same license identifier as the id returned by the callback, then give him the stuff directly (and make sure you have a system that saves it), otherwise if the player is not online, add the stuff to the DB, so that when he logs in next time it’s loaded.

Some news about this topic ?

What sort of news?

Is it possible to disable tebex FiveM? he does not want to use this function, but receives a post-examination with a non-complex function.

Thanks for your help if anyone can help