How to monetize your fivem server

Thank you.

Yeah I did play around with that, but it doesn’t actually allow you to “giveitem” as such if registering a command does it?

For example source being {id}

function giveitem(_, arg)
	local username = arg[1]
	local packageName = arg[2]
	local price = arg[3]
	local id = arg[4]
	print(username…" has just purchased “…packageName…” for "…tostring(price))
	GiveWeaponToPed(GetPlayerPed(id), GetHashKey("WEAPON_WEAPON"), 1, false, false)
end
RegisterCommand("giveitem", giveitem, true)
1 Like

At the bottom of a package just add a command like giveItem {id} 1234 1234 or whatever your command is like.

I for example have addtopriority {id} to add players to queue priority

1 Like

I’m struggling somewhat with the commerce integration with Tebex and you appear to have a better grasp of it than I.

I have tebex sending commands over to the server, and have commands/functions created to do what I need, however it isn’t actually actioning them to a user.

{id} does return the ID generated between tebex and cfx, but the server doesn’t seem to recognise this as a player to be able to allocate anything.

{sid} I have never got this to work.

Does the implementation require checks or data refreshes, above, and beyond what cfx have already added?

function giveitem(_, arg)
	local username = arg[1]
	local packageName = arg[2]
	local price = arg[3]
	local id = arg[4]
	print(username…" has just purchased “…packageName…” for "…tostring(price))
	GiveWeaponToPed(GetPlayerPed(id), GetHashKey("WEAPON_WEAPON"), 1, false, false)
end
RegisterCommand("giveitem", giveitem, true)

Keep in mind that the Tebex commands are somewhat rate limited. I’m not sure if this is a global rate limit on their side or some server limit. Either way, you should see in the payment if a command has been sent or of it’s due to be sent.

Does the print() print anything? That {id} is the same as the fivem: identifier that a player has when they connect their FiveM client to a forum/Cfx account.

I have not noticed it requires any refreshing of some kind on the server. {sid} I’ve never tried personally.

So in other words for this, the {id} is fivem:xxxxxx identifier. So to get their Ped, you will first need to find the Player with that identifier (iterate over the players and their identifiers until you’ve found them). I personally manage my items using a database and once the player come online I “activate” their item(s).

Ok so I’ve just tested the {sid} thingy and it works fine. Here’s how I use it:
1- Go to Webstore > Packages > Select the package you want to edit then click on “edit”
2- Go to the bottom and add this command as testing command:

getrewards {sid}

3- Open settings by clicking on this symbol image
4- Make sure to pick “Only execute the command when the player is online”


5- Make a server side resource and add this to it:

function getrewards(_, arg)
	local player = arg[1]
	print(GetPlayerName(player).." has bought this package!")
end
RegisterCommand("getrewards", getrewards, true)

Here’s how you can get the player ^^

2 Likes

ID brings back a 6 digit number which I assume to be the fivem ID.

It appears you are using a different method to what I am attempting to do. Rather than use a DB to store items and then activate I am trying to implement into our inventory as it works currently by using the tebex command as you would a chat command e.g /giveitem xid yitem

Thank you for this. WIll do some tests now and let you know the results.

UPDATE:

So I appear to have a result by using a modified version of the code from Hassony.

function testing(_, arg)
	local player = arg[1]
    GiveWeaponToPed(GetPlayerPed(player), GetHashKey("weaponname"), 1, false, false)
end
RegisterCommand("testing", testing, true)

This allocated a specific item to a player using {sid} in Tebex with the online option mentioned above.

For some reason for me the command doesn’t get executed at all if using the “require player to be online”. I have double checked that my fivem identifier is present on the server, the correct ID is used in the manual payment. It just never gets sent (it’s shown as “DUE”)

Tried to resend when I was for sure connected as well, no avail. I’ve waited 15 minutes. :frowning:

Please make sure that your cfx.re account is linked to your fivem client because sometimes it keeps disconnecting. Quit fivem, go to settings and login with cfx.re (if already connected, disconnect and connect it again).

Second thing, could be that you are entering the wrong username on tebex payments section.

Just to confirm you are connected to tebex using the latest build of FiveM rather than the old stand alone plugin?

If you check your console log it will tell you if it has authenticated or not.

To get the correct username I created a 100% discount voucher, logged into my tebex store via the Cfx portal, then proceeded to buy an item and apply to code. This allowed me to accurately grab my username as it appeared on the Cfx platform for testing purposes.

Just to mention that you don’t have to create a 100% coupon in order to test payments, just go to payments and click on “Create Payment” then enter the username on cfx.re and pick the package then click “create”. This will simulate the process of purchasing. :+1:

Yep authenticated. Authenticated with Tebex: Gun Game V

Manual payment, command is set https://i.imgur.com/UF9GkUg.png

It’s queued

{
    "meta": {
        "execute_offline": false,
        "next_check": 120,
        "more": false
    },
    "players": [
        {
            "id": 98,
            "name": "d0p3t",
            "uuid": "12684"
        }
    ]
}

and (delay doesn’t matter)

{
    "player": {
        "id": "12684",
        "username": "d0p3t",
    },
    "commands": [
        {
            "id": 315336444,
            "command": "hello {sid}",
            "payment": 27451792,
            "package": 3935329,
            "conditions": {
                "delay": 10,
                "slots": 0
            }
        }
    ]
}

FiveM identifier shows up "fivem:12684" (I’m online). Waited the 2 minutes, nothing.

Only thing I can think of is that I am on localhost. Looking at fivem/code/components/citizen-server-impl/src/ServerExtCommerce.cpp at master · citizenfx/fivem · GitHub there’s nothing related to the IP though.

Test command is defined on the client (even on the server doesn’t matter). The command doesn’t get sent anyway by Tebex as it doesn’t detect me as online. Command always “due” https://i.imgur.com/On5sBhU.png

I’m completely out of ideas why it doesn’t work. It literally just does not even send it. Can’t easily debug it either since I don’t have my own FiveM build set up.

Try switching to a live environment rather than local see if that helps.

While testing

function getrewards(_, arg)
	local player = arg[1]
	print(GetPlayerName(player).." has bought this package!")
end
RegisterCommand("getrewards", getrewards, true)

I’m receiving “attempt to concatenate a nil value” when using both {sid} and {id} (as recommended on Tebex website).

after 2 hours or trial and error

While testing

print(player.." has bought this package!")

so SID gives - {sid}

"{sid} has bought this package!"

ID (as recommended by Tebex website) gives 4 digits

"4981 has bought this package!"

My fivem license is “fivem:12345”

After logging and upon checking processed Tebex test payment, my ID is “12345”. So how the hell does this even work? And btw., it doesn’t work for me at all, when I have checked option “only when the player is online”…

I am running into the same issue. I was too busy with other things to contact Tebex about this. My guess is that something is wrong on their side.

I already wrote them, explaining the whole thing.

Have you heard any word back? I am experiencing the exact same issue.
Commands will not fire if the option for player to be logged on is selected.

1 Like

I actually managed to sort it out. There are a few nuances you need to be aware of.

If you aren’t online {hexid} and {sid} will always return {hexid} and {sid}.

Make sure you aren’t using the old plugin anymore. I was.

Turned it off added my secret key to the config and played with it a bit.

I can now sell directly to the store.

I would suggest not interacting with a player directly. Instead storing the items in an inventory the player can then retrieve their goods with a command or with scripted events.

There are many other uses i can brainstorm and will be implementing. Good luck folks. I am here to say tebex is working as intended you just need to work out the logistics.

Don’t use global commands to give item.

I hope these tips help you sort it out.

{id} seems to be replaced on the Tebex backend, so there’s something unusual going on with the use of it in RegisterCommand, perhaps? :confused: