Looking for someone to help me out a bit with creating items. I understand how to make the item,
but i’m struggling with adding multiple functions to the items.
I just want the cigars to use the smoking animation & apply body armor.
If I remove the second Entry, in the second paragraph, All cigars work and apply body armor without the smoking animation.
If it’s not obvious, I’m working with qbus at the moment.
QBCore.Functions.CreateUseableItem(“cigars”, function(source, item)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if Player.Functions.RemoveItem(item.name, 1, item.slot) then
TriggerClientEvent(“consumables:client:Usecigars”, src)
end
end)
QBCore.Functions.CreateUseableItem(“cigars”, function(source, item)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if Player.Functions.RemoveItem(item.name, 1, item.slot) then
TriggerClientEvent(“consumables:client:UseJoint”, src)
else
TriggerClientEvent(“consumables:client:Usecigars”, src)
end
end)
QBCore.Functions.CreateUseableItem(“cigars”, function(source, item)
local src = source
TriggerClientEvent(“consumables:client:UseArmor”, src)
end)
Can you show me your “consumables:client:Usecigars” ?
You know you can do stuff like this, right?
QBCore.Functions.CreateUseableItem("cigars", function(source, item)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if Player.Functions.RemoveItem(item.name, 1, item.slot) then
TriggerClientEvent("consumables:client:UseJoint", src)
TriggerClientEvent("consumables:client:UseCigars", src)
TriggerClientEvent("consumables:client:UseArmor", src)
end
end)
But you shouldn’t even need to trigger 3 events for using one item… Just have a single function creating the usable item, then inside that function, trigger the client event of choice that should contain a smoking animation and increases player armor. I don’t know what all these consumables:client:UseX
are, but you only need a single event on the client that contains a smoking animation and increase of armor. Take these from the other events you seem to have an put them into a single event. Easy.
1 Like
Is it possible to have Body Armor & A smoking emote at the same time?
The body armor gives a progress bar of course.
I"ve attachhed the image of the “cigar usage” He only does the progress bar for armor when I include all 3 triggers “UseCigars”,“UseJoint”,“UseArmor”.
Any thoughts ?
I don’t have one for UseCigars. Haven’t edited that code yet. I will do this though. Glad you said something because there aren’t any guides out there that I could find to create custom items. Thank you. Once I add these in, Cigars will have a trigger at that point right ?
I only included 3 triggers inside the CreateUseableItem function as an example of triggering multiple events from a single item use. Since you had 3 different functions. But as mentioned, you should create a new one for the cigar and trigger only that event. Inside that client event, you should have the code from the joint event which triggers an animation, then code from the armor event that adds armor to the player ped.
I don’t need 3 functions. I only want the cigars to “Smoke Emote” and Apply body armor.
I only had 3 because I was testing since I didn’t have a trigger for smoking on “usecigar”
Ok cool, at least you understand you don’t need 3. I thought you were using all 3, not just testing those 3, one at a time. So yeah, create a new client event for cigars, using the code from UseJoint and UseArmor. Then you will have a smoking animation and it adds armor.
So to recap: MY client side code is:
QBCore.Functions.Progressbar("smoke_cigars", "Lighting cigars..", 1500, false, true, {
disableMovement = false,
disableCarMovement = false,
disableMouse = false,
disableCombat = true,
}, {}, {}, {}, function() -- Done
TriggerEvent("inventory:client:ItemBox", QBCore.Shared.Items["joint"], "remove")
if IsPedInAnyVehicle(PlayerPedId(), false) then
TriggerEvent('animations:client:EmoteCommandStart', {"smoke3"})
else
TriggerEvent('animations:client:EmoteCommandStart', {"smokeweed"})
end
TriggerEvent("evidence:client:SetStatus", "weedsmell", 300)
TriggerEvent('animations:client:SmokeWeed')
end)
end)```
Then My server side code is:
```QBCore.Functions.CreateUseableItem("cigars", function(source, item)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if Player.Functions.RemoveItem(item.name, 1, item.slot) then
TriggerClientEvent("consumables:client:Usecigars", src)
TriggerClientEvent("consumables:client:UseArmor", src)
end
end)```
This should work to apply Armor to my "UseCigars" AND use the "SmokeJoint" animation correct? Will it work at the same time? or do I need to alter the client events to:
TriggerClientEvent("consumables:client:Usecigars", src) then
TriggerClientEvent("consumables:client:UseArmor", src)
Or Do i have these backwards & Need to put both usages into Client side instead of server side ?
Can I add a wait time function to one of the sections so that it performs the body armor application first, Then does the Smoke animation? It seems like it will not do both at the same time.
When I change the order in the server side code to “UseArmor” First, And “Usecigars” second, It uses the armor, but will not start the smoking animation. I think because it’s already doing the armor
Edit; Just applied body armor first by using One cigar, Then after that animation was completed I used another Cigar & It did the smoking animation as well.
I think I’m content with that.
Thank you guys for helping me!! I appreciate it!
Here’s a tip: Embed your code with three backticks (```). It is painful for us to try to read code like that with no indentation or syntax highlighting. Your posted code should look like this (colors and indentation):
IsPlayerAllowed = function(source)
local Player = QBCore.Functions.GetPlayer(source)
if Player then
for k,v in ipairs(Config.AllowedJobs) do
if Player.PlayerData.job.name == v then
return true
end
end
end
return false
end
(this is a random code snippet that means nothing)
Where Do I post those three backticks? Before the code? I’m relatively new to these forums, So still figuring it out. I don’t typically Dev or do anything for Fivem, haven’t for like 18 months. Just working on a server for a friend.
Surround your code in three backticks. Right before and right after the code. I’d show an example but Discourse doesn’t allow it.
Thanks mate, sorry for the butcher of the code format lol.
1 Like
Testing: works. Thanks
QBCore.Functions.CreateUseableItem("cigars", function(source, item)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if Player.Functions.RemoveItem(item.name, 1, item.slot) then
TriggerClientEvent("consumables:client:Usecigars", src)
TriggerClientEvent("consumables:client:UseArmor", src)
end
end)
Yes, it would be so much better if you could please do it like this…
```lua
– Code here
```
Also, your code has an error, it tries to remove “joint”, not “cigar”.
And you shouldn’t trigger it like that, one after the other. I keep saying, add the code from the others, to this one.
Please share your “consumables:client:UseArmor” client event and I will do it for you…
I don’t want it on the armor, I want it on the cigars.
RegisterNetEvent('consumables:client:Usecigars', function()
QBCore.Functions.Progressbar("smoke_cigars", "Lighting cigars..", 1500, false, true, {
disableMovement = false,
disableCarMovement = false,
disableMouse = false,
disableCombat = true,
}, {}, {}, {}, function() -- Done
TriggerEvent("inventory:client:ItemBox", QBCore.Shared.Items["cigars"], "remove")
if IsPedInAnyVehicle(PlayerPedId(), false) then
TriggerEvent('animations:client:EmoteCommandStart', {"smoke3"})
else
TriggerEvent('animations:client:EmoteCommandStart', {"smokeweed"})
end
TriggerEvent("evidence:client:SetStatus", "weedsmell", 300)
TriggerEvent('animations:client:SmokeWeed')
end)
end)
but I’m curruntly using “consumables:server:Usecigars”
QBCore.Functions.CreateUseableItem("cigars", function(source, item)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if Player.Functions.RemoveItem(item.name, 1, item.slot) then
TriggerClientEvent("consumables:client:UseArmor", src)
TriggerClientEvent("consumables:client:Usecigars", src)
end
end)
I already knew it had the error, I fixed it already lol
You can use a backslash (\) to escape special characters.
So \`\`\` is how you get ```
1 Like