From c2f5efb8977493b2f09be55031e790d684fca1ac Mon Sep 17 00:00:00 2001 From: "Niklas B." <68842909+justSalkin@users.noreply.github.com> Date: Sun, 6 Oct 2024 19:57:21 +0200 Subject: [PATCH] update V1.5 --- config.lua | 57 ++++++++---- fxmanifest.lua | 5 +- main.lua | 234 ++++++++++++++++++++++++++++++++++++++----------- server.lua | 203 ++++++++++++++++++++++++++---------------- 4 files changed, 356 insertions(+), 143 deletions(-) diff --git a/config.lua b/config.lua index 60198e1..b953067 100644 --- a/config.lua +++ b/config.lua @@ -1,14 +1,20 @@ Config = {} -Config.DiscordWebHook = "" -Config.DiscordBotName= "juSa NPC Rewards" +Config.Debug = true --enables input commands and some consol-prints | for details check out github or discord + +Config.DiscordWebhook = "" --put your webhook here +Config.DiscordBotName = "juSa NPC Rewards" +Config.DiscordAvatar = "https://i.postimg.cc/TYm9DdHT/jusa-scripts.png" Config.useRightNotify = false --if true use right notify, if false use notify on the left +Config.generalCooldown = false --turn on/off cooldown for every NPC | after one interaction with any NPC the player gets new cooldown for EVERY NPC +Config.Cooldown = 0 --in sec +Config.talkingTime = 7 --sec how long you can interact with one NPC until he is not longer responding to you and you have to "talk" to the NPC again ----------------------------- NPC Settings ------------------------------------- --- NPC Types: "give" = NPC gives player items and/or money +--NPC Types: "give" = NPC gives player items -- "sell" = NPC takes items and pays amount of $ back --- "exchange" = NPC takes item and/or money and gives money and/or items back +-- "exchange" = NPC takes item or money and gives money or another item back -- "nointeraction" = just an NPC, you can't interact with them -------------------------------------------------------------------------------- @@ -23,11 +29,14 @@ Config.NPCs = { heading = 189.77, radius = 4.0, --interaction radius scenario = false, -- set to false to use no scenario | find some here: https://github.com/femga/rdr3_discoveries/blob/master/animations/scenarios/scenario_types_with_conditional_anims.lua - anim = { animDict = false, animName = "" }, -- set to false to not use animations | find more here: https://raw.githubusercontent.com/femga/rdr3_discoveries/master/animations/ingameanims/ingameanims_list.luas + anim = { animDict = false, animName = '' }, -- set to false to not use animations | find more here: https://raw.githubusercontent.com/femga/rdr3_discoveries/master/animations/ingameanims/ingameanims_list.lua + cooldown = 20, --set individual cooldown | in sec + joblocked = {{name = "SheriffV", grade = 2}, {name = "DoctorV", grade = 3}}, --set nil if you want every job to use this NPC taskbar = 3000, --duration of the interaction usewebhook = true, --set true, if you want to get discord notification when interact with npc type = "give", -- see NPC Settings for more informations giveitem = {{ item = "apple", label = "apple", amount = 2 } , { item = "peach", label = "peach", amount = 1 }}, -- when interact -> gives player 2 apple and 1 peach + giveweapon = {{weaponname = "WEAPON_MELEE_KNIFE", label = "knife"}, {weaponname = "WEAPON_REVOLVER_CATTLEMAN", label = "Cattleman Revolver"}}, givemoney = 5, -- also gives player 5$ }, @@ -36,10 +45,12 @@ Config.NPCs = { npcmodel = "CS_MP_TRAVELLINGSALESWOMAN", coords = vector3(2681.41, -1399.55, 45.38), heading = -108.46, - radius = 4.0, - scenario = "WORLD_HUMAN_WRITE_NOTEBOOK", - anim = { animDict = false, animName = "" }, - taskbar = 6000, + radius = 4.0, + scenario = false, + anim = { animDict = false, animName = '' }, + cooldown = 20, + joblocked = nil, + taskbar = 3000, usewebhook = true, type = "sell", takeitem = {{ item = "apple", label = "apple", amount = 2 } , { item = "peach", label = "peach", amount = 1 }}, -- takes items from player @@ -48,17 +59,20 @@ Config.NPCs = { { npc_name = "Exchange-NPC", blip = 214435071, - npcmodel = "CS_MP_TRAVELLINGSALESWOMAN", + npcmodel = "mp_u_m_m_nat_farmer_04", coords = vector3(2698.74, -1407.68, 45.65), heading = -108.46, - radius = 4.0, - scenario = false, - anim = { animDict = false, animName = "" }, + radius = 4.0, + scenario = false, + anim = { animDict = false, animName = '' }, + cooldown = 20, + joblocked = nil, taskbar = 3000, usewebhook = true, type = "exchange", giveitem = {{ item = "peach", label = "peach", amount = 1 }}, takeitem = {{ item = "apple", label = "apple", amount = 2 }}, + giveweapon = nil, givemoney = 0, takemoney = 5, }, @@ -66,11 +80,13 @@ Config.NPCs = { ----------------------------- TRANSLATE HERE ------------------------------------- Config.Language = { - --Prompts + --prompts talk = "Talk to NPC", press = "press ", noLabel = "NO", yesLabel = "YES", + onCooldown = "I'm busy. Come back later ...", + wrongJob = "I think you've come to the wrong place ...", sellinfo = "Do you want to sell %s for %d$ ?", seeUlater = "Ok, see you later then.", exchangeinfo = "Do you want to exchange %s and %d$ against %s and %d$ ?", @@ -88,14 +104,23 @@ Config.Language = { title_exchanged = "You have exchanged: ", payed = "You payed: ", title_payed = "You payed: ", + lowgrade = "Your job grade is too low.", + wrongjob = "You don't have the right job for this.", --discord discord_title_give = "NPC GIVE", discord_title_sell = "NPC SELL", - discord_title_exchange = "NPC EXCHANGE" + discord_title_exchange = "NPC EXCHANGE", + webhook_got = "Got ", + webhook_from = " from ", + webhook_sold = "Sold ", + webhook_to = " to ", + webhook_for = " for ", + webhook_exchanged = "Exchanged: ", + webhook_with = " with " } ------------------- PROMPT ----------------- Config.keys = { G = 0x760A9C6F, -- talk/interact UP = 0x6319DB71, --yes DOWN = 0x05CA7C52 , --no -} +} \ No newline at end of file diff --git a/fxmanifest.lua b/fxmanifest.lua index d36e9e2..e7d16dd 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -4,7 +4,7 @@ rdr3_warning 'I acknowledge that this is a prerelease build of RedM, and I am aw author 'justSalkin' description 'Script for rewards from NPCs' -version '1.4.0' +version '1.5.0' client_script { 'main.lua', @@ -18,10 +18,11 @@ shared_scripts { 'config.lua', } +dependency 'vorp_core' dependencies { 'vorp_core', 'vorp_inventory', 'vorp_progressbar' } --- for support and/or more scripts join: https://discord.gg/DUax6SsEt2 +-- for more infos or if you found a bug join the juSa script discord: https://discord.com/invite/bxJ3d2j4dH \ No newline at end of file diff --git a/main.lua b/main.lua index f2dbea6..94a86e1 100644 --- a/main.lua +++ b/main.lua @@ -3,6 +3,12 @@ local talktoprompt = GetRandomIntInRange(0, 0xffffff) local decision = GetRandomIntInRange(0, 0xffffff) local progressbar = exports.vorp_progressbar:initiate() +local generalCooldown = Config.Cooldown +local npcCooldowns = {} --table for every NPC if generalCooldown = false +local jobs = {} +local hasjob = false +local talking = false +local talkingTime = Config.talkingTime --sec how long you are "talkin" TriggerEvent("getCore",function(core) VORPcore = core @@ -14,9 +20,10 @@ StartNPCs() end) function StartNPCs() --start function after user selected the character + Citizen.Wait(1000) for i, v in ipairs(Config.NPCs) do local x, y, z = table.unpack(v.coords) - local hashModel = GetHashKey(v.npcmodel) -- Loading Model + local hashModel = GetHashKey(v.npcmodel) -- loading NPC skin if IsModelValid(hashModel) then RequestModel(hashModel) while not HasModelLoaded(hashModel) do @@ -25,25 +32,40 @@ function StartNPCs() --start function after user selected the character else print(v.npcmodel .. " is not valid") end - local npc = CreatePed(hashModel, x, y, z, v.heading, false, true, true, true) -- Spawn NPC Ped + local npc = CreatePed(hashModel, x, y, z, v.heading, false, true, true, true) -- spawn NPC Citizen.InvokeNative(0x283978A15512B2FE, npc, true) -- SetRandomOutfitVariation SetEntityNoCollisionEntity(PlayerPedId(), npc, false) - SetEntityCanBeDamaged(npc, false) --npc can't be damaged + SetEntityCanBeDamaged(npc, false) --NPC can't be damaged SetEntityInvincible(npc, true) Wait(1000) FreezeEntityPosition(npc, true) -- NPC can't escape SetBlockingOfNonTemporaryEvents(npc, true) -- NPC can't be scared + if not Config.generalCooldown then -- set cooldown for every NPC + if v.cooldown ~= nil then + npcCooldowns[i] = v.cooldown + else + npcCooldowns[i] = 0 + end + if Config.Debug then --if debug = true print cooldowns on start + print("Loading NPC:", v.npc_name, "Cooldown:", v.cooldown) + end + else + npcCooldowns[i] = Config.Cooldown + if Config.Debug then + print("Loading NPC:", v.npc_name, "Cooldown = general Cooldown") + end + end if v.blip ~= 0 then --create blip local blip = Citizen.InvokeNative(0x554D9D53F696D002, 1664425300, x, y, z) SetBlipSprite(blip, v.blip, true) Citizen.InvokeNative(0x9CB1A1623062F402, blip, v.npc_name) end - if v.scenario then --load scenario in loop + if v.scenario then --start scenario in place and loop it TaskStartScenarioInPlace(npc, GetHashKey(v.scenario), 0, true, false, false, false) end - if v.anim.animDict and v.anim.animName then --loads animation looped + if v.anim.animDict and v.anim.animName then --play animation in loop RequestAnimDict(v.anim.animDict) - while not HasAnimDictLoaded(v.anim.animDict) do --get animation + while not HasAnimDictLoaded(v.anim.animDict) do Citizen.Wait(100) end TaskPlayAnim(npc, v.anim.animDict, v.anim.animName, 1.0, -1.0, -1, 1, 0, true, 0, false, 0, false) @@ -87,37 +109,71 @@ Citizen.CreateThread(function() --creating npc interaction prompts PromptRegisterEnd(yesPrompt) end) -local talking = false Citizen.CreateThread(function() while true do local sleep = true local _source = source - for i, v in ipairs(Config.NPCs) do --check every npc + for i, v in ipairs(Config.NPCs) do --check every NPC local playerCoords = GetEntityCoords(PlayerPedId()) - if Vdist(playerCoords, v.coords) <= v.radius and not talking then -- Checking distance between player and npc + if Vdist(playerCoords, v.coords) <= v.radius and not talking then -- checking distance between player and NPC if v.type ~= "nointeraction" then sleep = false local label = CreateVarString(10, 'LITERAL_STRING', Config.Language.talk) PromptSetActiveGroupThisFrame(talktoprompt, label) --loads talktoNPC prompt if Citizen.InvokeNative(0xC92AC953F0A982AE, talktonpc) then --when button is pressed - local playerPed = PlayerPedId() - talking = true + if (generalCooldown > 0 and Config.generalCooldown) or (npcCooldowns[i] > 0 and v.cooldown ~= nil) then + PromptRemoveGroup(talktoprompt) + VORPcore.NotifyBottomRight(Config.Language.onCooldown, 4000) + Wait(4000) + else + talking = true + talkingTime = Config.talkingTime + end + if v.joblocked and #v.joblocked > 0 then --if joblocked has at least 1 entry then + jobs = v.joblocked + TriggerServerEvent("juSa_npc_rewards:jobcheck", jobs) --check the jobs + while hasjob == nil do + Wait(10) + end + if Config.Debug then + print("You need: ") + for i, job in ipairs(jobs) do + if job and job.name then + print("Job " .. i .. ": " .. job.name .. ", Grade: " .. tostring(job.grade)) + else + print("Job " .. i .. " is nil or has no valid job name.") + end + end + end + Wait(100) + if not hasjob then --wait for results and if player has not correct job he can not talk to NPC + talking = false + PromptRemoveGroup(talktoprompt) + VORPcore.NotifyBottomRight(Config.Language.wrongJob, 4000) + Wait(4000) + end + elseif v.joblocked == nil then --if no job required + hasjob = true + end end end - elseif Vdist(playerCoords, v.coords) <= v.radius and talking then --if talking to a npc, show decision + elseif Vdist(playerCoords, v.coords) <= v.radius and talking and hasjob then --if talking to a NPC, show decision if v.type == "give" then sleep = false + local playerPed = PlayerPedId() FreezeEntityPosition(playerPed,true) --player cant move while performing animation - TaskStartScenarioInPlace(playerPed, GetHashKey("WORLD_HUMAN_CROUCH_INSPECT"), Config.taskbar, true, false, false, false) --Taskbar-Animation (change the text in "" if u want to have another animation instead) - progressbar.start(Config.Language.getting_item, Config.taskbar, nil, linear) - Citizen.Wait(Config.taskbar) - TriggerServerEvent("juSa_npc_rewards:give", v.giveitem, v.givemoney) -- give item/money - if v.usewebhook then - local type = "give" - Citizen.Wait(500) - TriggerServerEvent("juSa_npc_rewards:discord", type, v.giveitem, v.givemoney) --webhook trigger + TaskStartScenarioInPlace(playerPed, GetHashKey("WORLD_HUMAN_BADASS"), v.taskbar, true, false, false, false) --Taskbar-Animation (change the text in "" if u want to have another animation instead) + progressbar.start(Config.Language.getting_item, v.taskbar, nil, linear) + Citizen.Wait(v.taskbar) + TriggerServerEvent("juSa_npc_rewards:give", v.giveitem, v.givemoney, v.giveweapon, v.usewebhook, v.npc_name) -- give item/money + ClearPedTasks(playerPed) + FreezeEntityPosition(playerPed,false) + Reset() + if Config.generalCooldown then + NewCooldowns() + else + npcCooldowns[i] = v.cooldown or 0 end - talking = false elseif v.type == "sell" then sleep = false local itemInfo = "" @@ -126,19 +182,23 @@ Citizen.CreateThread(function() end itemInfo = string.sub(itemInfo, 1, -3) -- removes trailing comma and space local info = string.format(Config.Language.sellinfo, itemInfo, v.givemoney) - local label = CreateVarString(10, 'LITERAL_STRING', info) PromptRemoveGroup(talktoprompt) --unload talktonpc prompt PromptSetActiveGroupThisFrame(decision, label) --loads decision prompt if Citizen.InvokeNative(0xC92AC953F0A982AE, yesPrompt) then - TriggerServerEvent("juSa_npc_rewards:infosell", v.takeitem, v.givemoney, v.taskbar, v.usewebhook) + TriggerServerEvent("juSa_npc_rewards:infosell", v.takeitem, v.givemoney, v.taskbar, v.usewebhook, v.npc_name) Wait(v.taskbar) - talking = false + Reset() + if Config.generalCooldown then + NewCooldowns() + else + npcCooldowns[i] = v.cooldown or 0 + end elseif Citizen.InvokeNative(0xC92AC953F0A982AE, noPrompt) then PromptRemoveGroup(decision) VORPcore.NotifyBottomRight(Config.Language.seeUlater,4000) Wait(4000) - talking = false + Reset() end elseif v.type == "exchange" then sleep = false @@ -146,30 +206,37 @@ Citizen.CreateThread(function() for _, item in ipairs(v.takeitem) do takeItemInfo = takeItemInfo .. tostring(item.amount) .. "x " .. item.label .. ", " end - takeItemInfo = string.sub(takeItemInfo, 1, -3) -- Remove the trailing comma and space - + takeItemInfo = string.sub(takeItemInfo, 1, -3) -- remove the trailing comma and space local giveItemInfo = "" for _, item in ipairs(v.giveitem) do giveItemInfo = giveItemInfo .. tostring(item.amount) .. "x " .. item.label .. ", " end - giveItemInfo = string.sub(giveItemInfo, 1, -3) -- Remove the trailing comma and space + if not v.giveweapon == nil then -- check if giveweapon has items + for _, weapon in ipairs(v.giveweapon) do + giveItemInfo = giveItemInfo .. "1x " .. weapon.label .. ", " + end + end + giveItemInfo = string.sub(giveItemInfo, 1, -3) local info = string.format(Config.Language.exchangeinfo, takeItemInfo, v.takemoney, giveItemInfo, v.givemoney) local label = CreateVarString(10, 'LITERAL_STRING', info) PromptRemoveGroup(talktoprompt) --unload talktonpc prompt PromptSetActiveGroupThisFrame(decision, label) --loads decision prompt if Citizen.InvokeNative(0xC92AC953F0A982AE, yesPrompt) then - TriggerServerEvent("juSa_npc_rewards:infoexchange", v.giveitem, v.takeitem, v.givemoney, v.takemoney, v.taskbar, v.usewebhook) + TriggerServerEvent("juSa_npc_rewards:infoexchange", v.giveitem, v.takeitem, v.giveweapon, v.givemoney, v.takemoney, v.taskbar, v.usewebhook, v.npc_name) Wait(v.taskbar) - talking = false + Reset() + if Config.generalCooldown then + NewCooldowns() + else + npcCooldowns[i] = v.cooldown or 0 + end elseif Citizen.InvokeNative(0xC92AC953F0A982AE, noPrompt) then PromptRemoveGroup(decision) - VORPcore.NotifyBottomRight(Config.Language.seeUlater,4000) + VORPcore.NotifyBottomRight(Config.Language.seeUlater, 4000) Wait(4000) - talking = false - end + Reset() + end end - ClearPedTasks(playerPed) - FreezeEntityPosition(playerPed,false) PromptRemoveGroup(talktoprompt) PromptRemoveGroup(decision) end @@ -182,27 +249,94 @@ Citizen.CreateThread(function() end) RegisterNetEvent("juSa_npc_rewards:infosellsend") -AddEventHandler("juSa_npc_rewards:infosellsend", function( takeitem, givemoney, taskbar, usewebhook) +AddEventHandler("juSa_npc_rewards:infosellsend", function( takeitem, givemoney, taskbar, usewebhook, npc_name) + local playerPed = PlayerPedId() FreezeEntityPosition(playerPed,true) - TaskStartScenarioInPlace(playerPed, GetHashKey("WORLD_HUMAN_CROUCH_INSPECT"), taskbar, true, false, false, false) + TaskStartScenarioInPlace(playerPed, GetHashKey("WORLD_HUMAN_BADASS"), taskbar, true, false, false, false) progressbar.start(Config.Language.selling_item, taskbar, nil, linear) Citizen.Wait(taskbar) - TriggerServerEvent("juSa_npc_rewards:sell", takeitem, givemoney) - if usewebhook then - local type = "sell" - TriggerServerEvent("juSa_npc_rewards:discord", type, takeitem, givemoney) - end + TriggerServerEvent("juSa_npc_rewards:sell", takeitem, givemoney, usewebhook, npc_name) + ClearPedTasks(playerPed) + FreezeEntityPosition(playerPed,false) end) RegisterNetEvent("juSa_npc_rewards:infoexchangesend") -AddEventHandler("juSa_npc_rewards:infoexchangesend", function(takeitem, giveitem, givemoney, takemoney, taskbar, usewebhook) +AddEventHandler("juSa_npc_rewards:infoexchangesend", function(takeitem, giveitem, giveweapon, givemoney, takemoney, taskbar, usewebhook, npc_name) + local playerPed = PlayerPedId() FreezeEntityPosition(playerPed,true) - TaskStartScenarioInPlace(playerPed, GetHashKey("WORLD_HUMAN_CROUCH_INSPECT"), Config.taskbar, true, false, false, false) - progressbar.start(Config.Language.exchanging_item, Config.taskbar, nil, linear) - Citizen.Wait(Config.taskbar) - TriggerServerEvent("juSa_npc_rewards:exchange", giveitem, takeitem, givemoney, takemoney) - if usewebhook then - local type = "exchange" - TriggerServerEvent("juSa_npc_rewards:discord", type, giveitem, takeitem, givemoney, takemoney) + TaskStartScenarioInPlace(playerPed, GetHashKey("WORLD_HUMAN_BADASS"), taskbar, true, false, false, false) + progressbar.start(Config.Language.exchanging_item, taskbar, nil, linear) + Citizen.Wait(taskbar) + TriggerServerEvent("juSa_npc_rewards:exchange", giveitem, takeitem, giveweapon, givemoney, takemoney, usewebhook, npc_name) + ClearPedTasks(playerPed) + FreezeEntityPosition(playerPed,false) +end) + +RegisterNetEvent("juSa_npc_rewards:jobchecked") +AddEventHandler("juSa_npc_rewards:jobchecked", function(result) + hasjob = result +end) + +function NewCooldowns() --set new cooldowns + generalCooldown = Config.Cooldown + for i, v in ipairs(Config.NPCs) do + if Config.generalCooldown then -- set new cooldown for every NPC + if v.cooldown ~= nil then + npcCooldowns[i] = generalCooldown + else + npcCooldowns[i] = 0 + end + end + end +end + +function Reset() --resets vars + hasjob = false + talking = false +end + +Citizen.CreateThread(function() --handeling cooldown counting + while true do + Citizen.Wait(1000) + if generalCooldown > 0 then + generalCooldown = generalCooldown - 1 + end + for i, cooldown in ipairs(npcCooldowns) do + if cooldown > 0 then + npcCooldowns[i] = cooldown - 1 + end + end + if talkingTime > 0 then + talkingTime = talkingTime -1 + else + Reset() + end end end) + +---- Debug commands ---- + +RegisterCommand("printCd", function() + if Config.Debug then --command if debug = true to print every cooldown + PrintCooldowns() + end +end, false) + +RegisterCommand('resetCd', function() --set all cooldowns to 0 + if Config.Debug then + for i, v in ipairs(Config.NPCs) do + v.cooldown = 0 + print("NPC name:", v.npc_name, "Cooldown was set to 0") + end + generalCooldown = 0 + end +end, false) + +function PrintCooldowns() --prints cooldowns for every NPC + print("General Cooldown:", generalCooldown) + for i, v in ipairs(Config.NPCs) do + local npcName = v.npc_name or "Unknown NPC" + local cooldown = npcCooldowns[i] or 0 + print("NPC Name:", npcName, "Cooldown:", cooldown) + end +end diff --git a/server.lua b/server.lua index 1ab8bc8..a6cd0b4 100644 --- a/server.lua +++ b/server.lua @@ -1,6 +1,6 @@ local VORPcore = exports.vorp_core:GetCore() local VORPInv = exports.vorp_inventory:vorp_inventoryApi() - +-- find more notify blips here: https://github.com/femga/rdr3_discoveries/tree/master/useful_info_from_rpfs/textures/blips local giveitem = {} local takeitem = {} @@ -8,29 +8,99 @@ TriggerEvent("getCore",function(core) VORPcore = core end) +RegisterServerEvent("juSa_npc_rewards:jobcheck") +AddEventHandler("juSa_npc_rewards:jobcheck", function(jobs) + local _source = source + local Character = VORPcore.getUser(_source).getUsedCharacter + local hasJob = false + local hasRequiredGrade = false + local result = nil + for i, v in ipairs(jobs) do --check list of jobs + if v.name == Character.job then --checks for job + hasJob = true + if v.grade <= Character.jobGrade then + hasRequiredGrade = true + break --stops when player has a correct job and grade + end + end + end + if hasJob and hasRequiredGrade then + result = true + TriggerClientEvent("juSa_npc_rewards:jobchecked", _source, result) + elseif hasJob and not hasRequiredGrade then + result = false + TriggerClientEvent("vorp:TipRight", _source, Config.Language.lowgrade, 5000) + TriggerClientEvent("juSa_npc_rewards:jobchecked", _source, result) + else + result = false + TriggerClientEvent("vorp:TipRight", _source, Config.Language.wrongjob, 5000) + TriggerClientEvent("juSa_npc_rewards:jobchecked", _source, result) + end +end) + RegisterServerEvent("juSa_npc_rewards:give") -AddEventHandler("juSa_npc_rewards:give", function(giveitem, givemoney) +AddEventHandler("juSa_npc_rewards:give", function(giveitem, givemoney, giveweapon, usewebhook, npc_name) local _source = source local Character = VORPcore.getUser(_source).getUsedCharacter + local firstname = Character.firstname + local lastname = Character.lastname + local rewardText = "" for k,v in ipairs(giveitem) do VORPInv.addItem(_source, v.item, v.amount) + rewardText = rewardText .. v.amount .. "x " .. v.label .. ", " + if Config.Debug then + print(v.amount.."x "..v.label.." was given to "..firstname.." "..lastname) + end + end + if not giveweapon == nil then + for k,v in ipairs(giveweapon) do + exports.vorp_inventory:canCarryWeapons(_source, #giveweapon, function(canCarry) + if canCarry then + if v.weaponname then + exports.vorp_inventory:createWeapon(_source, v.weaponname, {["ammo"] = 0}, {}) + rewardText = rewardText .. v.label .. ", " + if Config.Debug then + print(v.label.." was given to "..firstname.." "..lastname) + end + else + print("Weapon name is nil for entry "..k) + end + else + print("Cannot carry more weapons") + VORPcore.NotifyRightTip(_source, "Can't carry more weapons.", 4000) + end + end, v.weaponname) + end end Character.addCurrency(0, givemoney) + rewardText = rewardText .. givemoney .. " $" + if Config.Debug then + print(givemoney.."$ was given to "..firstname.." "..lastname) + end if Config.useRightNotify then --notify for k,v in ipairs(giveitem) do VORPcore.NotifyRightTip(_source, Config.Language.got..v.amount.."x "..v.label,4000) end + for k,v in ipairs(giveweapon) do + VORPcore.NotifyRightTip(_source, Config.Language.got.."1x "..v.label,4000) + end VORPcore.NotifyRightTip(_source, Config.Language.got..givemoney.." $",4000) else for k,v in ipairs(giveitem) do VORPcore.NotifyLeft(_source, Config.Language.title_got, v.amount .. "x " .. v.label, "BLIPS", "blip_chest", 4000, "COLOR_GREEN") end + for k,v in ipairs(giveweapon) do + VORPcore.NotifyLeft(_source, Config.Language.title_got, "1x " .. v.label, "BLIPS", "blip_weapon", 4000, "COLOR_GREEN") + end VORPcore.NotifyLeft(_source, Config.Language.title_got, givemoney .. " $","BLIPS", "blip_cash_bag", 4000, "COLOR_GREEN") end + if usewebhook then + VORPcore.AddWebhook(firstname.." "..lastname, Config.DiscordWebhook, Config.Language.webhook_got .. rewardText .. Config.Language.webhook_from .. npc_name, 1, Config.DiscordBotName, "", "", Config.DiscordAvatar) + end end) RegisterServerEvent("juSa_npc_rewards:infosell") -AddEventHandler("juSa_npc_rewards:infosell", function(takeitem, givemoney, taskbar, usewebhook) +AddEventHandler("juSa_npc_rewards:infosell", function(takeitem, givemoney, taskbar, usewebhook, npc_name) local _source = source local Character = VORPcore.getUser(_source).getUsedCharacter local checked = true @@ -42,33 +112,42 @@ AddEventHandler("juSa_npc_rewards:infosell", function(takeitem, givemoney, taskb end end if checked == true then - TriggerClientEvent("juSa_npc_rewards:infosellsend", _source, takeitem, givemoney, taskbar, usewebhook) + TriggerClientEvent("juSa_npc_rewards:infosellsend", _source, takeitem, givemoney, taskbar, usewebhook, npc_name) end end) RegisterServerEvent("juSa_npc_rewards:sell") -AddEventHandler("juSa_npc_rewards:sell", function(takeitem, givemoney) +AddEventHandler("juSa_npc_rewards:sell", function(takeitem, givemoney, usewebhook, npc_name) local _source = source local Character = VORPcore.getUser(_source).getUsedCharacter + local firstname = Character.firstname + local lastname = Character.lastname + local rewardText = "" for k,v in ipairs(takeitem) do exports.vorp_inventory:subItem(_source, v.item, v.amount) + rewardText = rewardText .. v.amount .. "x " .. v.label .. ", " end + rewardText = rewardText .. Config.Language.webhook_for Character.addCurrency(0, givemoney) + rewardText = rewardText .. givemoney .. " $" if Config.useRightNotify then --notify for k,v in ipairs(takeitem) do VORPcore.NotifyRightTip(_source, Config.Language.sold..v.amount.."x "..v.label,4000) end - VORPcore.NotifyRightTip(_source, Config.Language.got..givemoney.." $",4000) + VORPcore.NotifyRightTip(_source, Config.Language.got..addCurrency.amount.."$ ",4000) else for k,v in ipairs(takeitem) do VORPcore.NotifyLeft(_source, Config.Language.title_sold, v.amount .. "x " .. v.label, "BLIPS", "blip_chest", 4000, "COLOR_RED") end - VORPcore.NotifyLeft(_source, Config.Language.title_got, givemoney .. " $","BLIPS", "blip_cash_bag", 4000, "COLOR_GREEN") + VORPcore.NotifyLeft(_source, Config.Language.title_got, givemoney .. "$ ","BLIPS", "blip_cash_bag", 4000, "COLOR_GREEN") + end + if usewebhook then + VORPcore.AddWebhook(firstname.." "..lastname, Config.DiscordWebhook, Config.Language.webhook_sold .. rewardText .. Config.Language.webhook_to .. npc_name, 1, Config.DiscordBotName, "", "", Config.DiscordAvatar) end end) RegisterServerEvent("juSa_npc_rewards:infoexchange") -AddEventHandler("juSa_npc_rewards:infoexchange", function(giveitem, takeitem, givemoney, takemoney, taskbar, usewebhook) +AddEventHandler("juSa_npc_rewards:infoexchange", function(giveitem, takeitem, giveweapon, givemoney, takemoney, taskbar, usewebhook, npc_name) local _source = source local Character = VORPcore.getUser(_source).getUsedCharacter local checked = true @@ -80,22 +159,52 @@ AddEventHandler("juSa_npc_rewards:infoexchange", function(giveitem, takeitem, gi end end if checked == true then - TriggerClientEvent("juSa_npc_rewards:infoexchangesend", _source, takeitem, giveitem, givemoney, takemoney, taskbar, usewebhook) + TriggerClientEvent("juSa_npc_rewards:infoexchangesend", _source, takeitem, giveitem, giveweapon, givemoney, takemoney, taskbar, usewebhook, npc_name) end end) RegisterServerEvent("juSa_npc_rewards:exchange") -AddEventHandler("juSa_npc_rewards:exchange", function(giveitem, takeitem, givemoney, takemoney) +AddEventHandler("juSa_npc_rewards:exchange", function(giveitem, takeitem, giveweapon, givemoney, takemoney, usewebhook, npc_name) local _source = source local Character = VORPcore.getUser(_source).getUsedCharacter + local firstname = Character.firstname + local lastname = Character.lastname + local rewardText = "" + -- order for webhook first give for k,v in pairs(giveitem) do VORPInv.addItem(_source, v.item, v.amount) + rewardText = rewardText .. v.amount .. "x " .. v.label .. ", " + end + if not giveweapon == nil then + for k,v in ipairs(giveweapon) do + exports.vorp_inventory:canCarryWeapons(_source, #giveweapon, function(canCarry) + if canCarry then + if v.weaponname then + exports.vorp_inventory:createWeapon(_source, v.weaponname, {["ammo"] = 0}, {}) + rewardText = rewardText .. "1x " .. v.label .. ", " + if Config.Debug then + print(v.label.." was given to "..firstname.." "..lastname) + end + else + print("Weapon name is nil for entry "..k) + end + else + print("Cannot carry more weapons") + VORPcore.NotifyRightTip(_source, "Can't carry more weapons.", 4000) + end + end, v.weaponname) + end end + Character.addCurrency(0, givemoney) + rewardText = rewardText .. givemoney .. " $ " + rewardText = rewardText .. Config.Language.webhook_for + -- then take items -> rewardText for k,v in pairs(takeitem) do VORPInv.subItem(_source, v.item, v.amount) + rewardText = rewardText .. v.amount .. "x " .. v.label .. ", " end - Character.addCurrency(0, givemoney) Character.removeCurrency(0, takemoney) + rewardText = rewardText .. takemoney .. " $ " if Config.useRightNotify then --notify for k,v in ipairs(giveitem) do VORPcore.NotifyRightTip(_source, Config.Language.got..v.amount.."x "..v.label,4000) @@ -103,6 +212,9 @@ AddEventHandler("juSa_npc_rewards:exchange", function(giveitem, takeitem, givemo for k,v in ipairs(takeitem) do VORPcore.NotifyRightTip(_source, Config.Language.exchanged..v.amount.."x "..v.label,4000) end + for k,v in ipairs(giveweapon) do + VORPcore.NotifyRightTip(_source, Config.Language.got.."1x "..v.label,4000) + end VORPcore.NotifyRightTip(_source, Config.Language.got..givemoney.." $",4000) VORPcore.NotifyRightTip(_source, Config.Language.payed..takemoney.." $",4000) else @@ -112,72 +224,13 @@ AddEventHandler("juSa_npc_rewards:exchange", function(giveitem, takeitem, givemo for k,v in ipairs(takeitem) do VORPcore.NotifyLeft(_source, Config.Language.title_exchanged, v.amount .. "x " .. v.label, "BLIPS", "blip_chest", 4000, "COLOR_RED") end + for k,v in ipairs(giveweapon) do + VORPcore.NotifyLeft(_source, Config.Language.title_got, "1x " .. v.label, "BLIPS", "blip_weapon", 4000, "COLOR_GREEN") + end VORPcore.NotifyLeft(_source, Config.Language.title_got, givemoney .. " $","BLIPS", "blip_cash_bag", 4000, "COLOR_GREEN") VORPcore.NotifyLeft(_source, Config.Language.title_payed, takemoney .. " $","BLIPS", "blip_cash_bag", 4000, "COLOR_RED") end -end) - -RegisterServerEvent('juSa_npc_rewards:discord') -AddEventHandler("juSa_npc_rewards:discord", function(type, giveitem, takemoney, givemoney, takeitem) - local _source = source - local User = VORPcore.getUser(_source) - local Character = User.getUsedCharacter - local CharName - if Character ~= nil then - if Character.lastname ~= nil then - CharName = Character.firstname .. ' ' .. Character.lastname - else - CharName = Character.firstname - end - end - - local DiscordWebhook = Config.DiscordWebHook - local Content = { - username = Config.DiscordBotName, - } - if type == "give" then - local itemsDescription = "" - for _, item in ipairs(giveitem) do - itemsDescription = itemsDescription .. tostring(giveitem[1].amount) .. "x " .. giveitem[1].item .. ", " - end - Content.embeds = {{ - title = Config.Language.discord_title_give, - description = CharName .. " got " .. string.sub(itemsDescription, 1, -3) .. " and " .. tostring(givemoney or 0) .. " $", - color = 65280 -- embed color green - }} - elseif type == "sell" then - local itemsDescription = "" - for _, item in ipairs(takeitem) do - itemsDescription = itemsDescription .. tostring(item.amount) .. "x " .. item.item .. ", " - end - Content.embeds = {{ - title = Config.Language.discord_title_sell, - description = CharName .. " sold " .. string.sub(itemsDescription, 1, -3) .. " for " .. tostring(givemoney or 0) .. " $", - color = 16711680 -- embed color red - }} - elseif type == "exchange" then - local takeItemsDescription = "" - for _, item in ipairs(takeitem) do - takeItemsDescription = takeItemsDescription .. tostring(item.amount) .. "x " .. item.item .. ", " - end - local giveItemsDescription = "" - for _, item in ipairs(giveitem) do - giveItemsDescription = giveItemsDescription .. tostring(item.amount) .. "x " .. item.item .. ", " - end - Content.embeds = {{ - title = Config.Language.discord_title_exchange, - description = CharName .. " exchanged " .. string.sub(takeItemsDescription, 1, -3) .. " and " .. tostring(takemoney or 0) .. " for " .. string.sub(giveItemsDescription, 1, -3) .. " and " .. tostring(givemoney or 0) .. " $", - color = 255 -- embed color blue - }} + if usewebhook then + VORPcore.AddWebhook(firstname.." "..lastname, Config.DiscordWebhook, Config.Language.webhook_exchanged .. rewardText .. Config.Language.webhook_with .. npc_name, 1, Config.DiscordBotName, "", "", Config.DiscordAvatar) end - - PerformHttpRequest(DiscordWebhook, function(err, text, headers) - if err == 200 then - print("message send: " .. text) - elseif err == 204 then - --send without return - else - print("error trying to send message: " .. err) - end - end, "POST", json.encode(Content), {["Content-Type"] = "application/json"}) end) \ No newline at end of file