diff --git a/CarryPeople/sv_carry.lua b/CarryPeople/sv_carry.lua index b86e263..408eafd 100644 --- a/CarryPeople/sv_carry.lua +++ b/CarryPeople/sv_carry.lua @@ -6,10 +6,15 @@ local carried = {} RegisterServerEvent("CarryPeople:sync") AddEventHandler("CarryPeople:sync", function(targetSrc) local source = source - - TriggerClientEvent("CarryPeople:syncTarget", targetSrc, source) - carrying[source] = targetSrc - carried[targetSrc] = source + local sourcePed = GetPlayerPed(source) + local sourceCoords = GetEntityCoords(sourcePed) + local targetPed = GetPlayerPed(targetSrc) + local targetCoords = GetEntityCoords(targetPed) + if #(sourceCoords - targetCoords) <= 3.0 then + TriggerClientEvent("CarryPeople:syncTarget", targetSrc, source) + carrying[source] = targetSrc + carried[targetSrc] = source + end end) RegisterServerEvent("CarryPeople:stop") diff --git a/PiggyBack/sv_piggyback.lua b/PiggyBack/sv_piggyback.lua index 856d86b..b39d652 100644 --- a/PiggyBack/sv_piggyback.lua +++ b/PiggyBack/sv_piggyback.lua @@ -6,10 +6,15 @@ local beingPiggybacked = {} RegisterServerEvent("Piggyback:sync") AddEventHandler("Piggyback:sync", function(targetSrc) local source = source - - TriggerClientEvent("Piggyback:syncTarget", targetSrc, source) - piggybacking[source] = targetSrc - beingPiggybacked[targetSrc] = source + local sourcePed = GetPlayerPed(source) + local sourceCoords = GetEntityCoords(sourcePed) + local targetPed = GetPlayerPed(targetSrc) + local targetCoords = GetEntityCoords(targetPed) + if #(sourceCoords - targetCoords) <= 3.0 then + TriggerClientEvent("Piggyback:syncTarget", targetSrc, source) + piggybacking[source] = targetSrc + beingPiggybacked[targetSrc] = source + end end) RegisterServerEvent("Piggyback:stop") @@ -41,4 +46,4 @@ AddEventHandler('playerDropped', function(reason) piggybacking[beingPiggybacked[source]] = nil beingPiggybacked[source] = nil end -end) \ No newline at end of file +end) diff --git a/README.md b/README.md index aaf0227..04d1a8f 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,11 @@ -# FiveM-Scripts -Compilation of my publicly released code +Original Take Hostage Script Made By: rubbertoe98 -Feel free to make improvements with PRs +Edited & Patched By: Vyast#0001 +A few very exploitable server-sided events: 'TakeHostage:sync', 'TakeHostage:releaseHostage', 'TakeHostage:killHostage', which could be manipulated & used by modders in multiple ways to do different things such as take an entire server full of players hostage all at once, kill an entire server of players all at once, and more have been fully patched and protected by adding a distance check from the source player to the target player to further verify legitness. -My personal dev discord -https://discord.gg/dnZTpUh +Minor client sided optimizations & changes. + +Instructions on how to use: +Type /takehostage, a valid weapon is needed(Add or remove weapons in client.lua) +Then press G to release the hostage or H to kill the hostage! diff --git a/TakeHostage/cl_takehostage.lua b/TakeHostage/client.lua similarity index 56% rename from TakeHostage/cl_takehostage.lua rename to TakeHostage/client.lua index 15fb6e0..3a5ff52 100644 --- a/TakeHostage/cl_takehostage.lua +++ b/TakeHostage/client.lua @@ -1,11 +1,11 @@ ------------------------------------------------------------------ ---TakeHostage by Robbster, do not redistrbute without permission-- ------------------------------------------------------------------- +--Original Author: rubbertoe98 +--Edited & Patched By: Vyast local takeHostage = { allowedWeapons = { `WEAPON_PISTOL`, `WEAPON_COMBATPISTOL`, + `WEAPON_APPISTOL`, --etc add guns you want }, InProgress = false, @@ -32,24 +32,27 @@ local function drawNativeNotification(text) DisplayHelpTextFromStringLabel(0, 0, 1, -1) end +local function playerPed() + return PlayerPedId() +end + local function GetClosestPlayer(radius) - local players = GetActivePlayers() - local closestDistance = -1 - local closestPlayer = -1 - local playerPed = PlayerPedId() + local closestDistance, closestPlayer = -1, -1 + local playerPed = playerPed() local playerCoords = GetEntityCoords(playerPed) - for _,playerId in ipairs(players) do - local targetPed = GetPlayerPed(playerId) + for k, v in ipairs(GetActivePlayers()) do + local targetPed = GetPlayerPed(v) if targetPed ~= playerPed then local targetCoords = GetEntityCoords(targetPed) - local distance = #(targetCoords-playerCoords) + local distance = #(targetCoords - playerCoords) if closestDistance == -1 or closestDistance > distance then - closestPlayer = playerId + closestPlayer = v closestDistance = distance end end end + if closestDistance ~= -1 and closestDistance <= radius then return closestPlayer else @@ -73,50 +76,55 @@ local function drawNativeText(str) EndTextCommandPrint(1000, 1) end -RegisterCommand("takehostage",function() +RegisterCommand("takehostage", function() callTakeHostage() end) -RegisterCommand("th",function() +RegisterCommand("th", function() callTakeHostage() end) function callTakeHostage() - ClearPedSecondaryTask(PlayerPedId()) - DetachEntity(PlayerPedId(), true, false) - - local canTakeHostage = false - for i=1, #takeHostage.allowedWeapons do - if HasPedGotWeapon(PlayerPedId(), takeHostage.allowedWeapons[i], false) then - if GetAmmoInPedWeapon(PlayerPedId(), takeHostage.allowedWeapons[i]) > 0 then - canTakeHostage = true - foundWeapon = takeHostage.allowedWeapons[i] - break - end + local ped = playerPed() + if not IsEntityDead(ped) then + ClearPedSecondaryTask(ped) + DetachEntity(ped, true, false) + + local canTakeHostage = false + for i=1, #takeHostage.allowedWeapons do + if HasPedGotWeapon(ped, takeHostage.allowedWeapons[i], false) then + if GetAmmoInPedWeapon(ped, takeHostage.allowedWeapons[i]) > 0 then + canTakeHostage = true + foundWeapon = takeHostage.allowedWeapons[i] + break + end + end end - end - if not canTakeHostage then - drawNativeNotification("You need a pistol with ammo to take a hostage at gunpoint!") - end + if not canTakeHostage then + drawNativeNotification("You need a pistol with ammo to take a hostage at gunpoint!") + end - if not takeHostage.InProgress and canTakeHostage then - local closestPlayer = GetClosestPlayer(3) - if closestPlayer then - local targetSrc = GetPlayerServerId(closestPlayer) - if targetSrc ~= -1 then - SetCurrentPedWeapon(PlayerPedId(), foundWeapon, true) - takeHostage.InProgress = true - takeHostage.targetSrc = targetSrc - TriggerServerEvent("TakeHostage:sync",targetSrc) - ensureAnimDict(takeHostage.agressor.animDict) - takeHostage.type = "agressor" + if not takeHostage.InProgress and canTakeHostage then + local closestPlayer = GetClosestPlayer(3) + if closestPlayer then + local targetSrc = GetPlayerServerId(closestPlayer) + if targetSrc ~= -1 then + SetCurrentPedWeapon(ped, foundWeapon, true) + takeHostage.InProgress = true + takeHostage.targetSrc = targetSrc + TriggerServerEvent("TakeHostage:sync", targetSrc) + ensureAnimDict(takeHostage.agressor.animDict) + takeHostage.type = "agressor" + else + drawNativeNotification("~r~No one nearby to take as hostage!") + end else drawNativeNotification("~r~No one nearby to take as hostage!") end - else - drawNativeNotification("~r~No one nearby to take as hostage!") end + else + drawNativeNotification("~r~You cannot do that while you are dead!") end end @@ -125,70 +133,78 @@ AddEventHandler("TakeHostage:syncTarget", function(target) local targetPed = GetPlayerPed(GetPlayerFromServerId(target)) takeHostage.InProgress = true ensureAnimDict(takeHostage.hostage.animDict) - AttachEntityToEntity(PlayerPedId(), targetPed, 0, takeHostage.hostage.attachX, takeHostage.hostage.attachY, takeHostage.hostage.attachZ, 0.5, 0.5, 0.0, false, false, false, false, 2, false) + AttachEntityToEntity(playerPed(), targetPed, 0, takeHostage.hostage.attachX, takeHostage.hostage.attachY, takeHostage.hostage.attachZ, 0.5, 0.5, 0.0, false, false, false, false, 2, false) takeHostage.type = "hostage" end) RegisterNetEvent("TakeHostage:releaseHostage") AddEventHandler("TakeHostage:releaseHostage", function() + local ped = playerPed() takeHostage.InProgress = false takeHostage.type = "" - DetachEntity(PlayerPedId(), true, false) + DetachEntity(ped, true, false) ensureAnimDict("reaction@shove") - TaskPlayAnim(PlayerPedId(), "reaction@shove", "shoved_back", 8.0, -8.0, -1, 0, 0, false, false, false) - Wait(250) - ClearPedSecondaryTask(PlayerPedId()) + TaskPlayAnim(ped, "reaction@shove", "shoved_back", 8.0, -8.0, -1, 0, 0, false, false, false) + Citizen.Wait(250) + ClearPedSecondaryTask(ped) end) RegisterNetEvent("TakeHostage:killHostage") AddEventHandler("TakeHostage:killHostage", function() + local ped = playerPed() takeHostage.InProgress = false takeHostage.type = "" - SetEntityHealth(PlayerPedId(),0) - DetachEntity(PlayerPedId(), true, false) + SetEntityHealth(ped, 0) + DetachEntity(ped, true, false) ensureAnimDict("anim@gangops@hostage@") - TaskPlayAnim(PlayerPedId(), "anim@gangops@hostage@", "victim_fail", 8.0, -8.0, -1, 168, 0, false, false, false) + TaskPlayAnim(ped, "anim@gangops@hostage@", "victim_fail", 8.0, -8.0, -1, 168, 0, false, false, false) end) RegisterNetEvent("TakeHostage:cl_stop") AddEventHandler("TakeHostage:cl_stop", function() + local ped = playerPed() takeHostage.InProgress = false takeHostage.type = "" - ClearPedSecondaryTask(PlayerPedId()) - DetachEntity(PlayerPedId(), true, false) + ClearPedSecondaryTask(ped) + DetachEntity(ped, true, false) end) Citizen.CreateThread(function() while true do + Citizen.Wait(0) + local ped = playerPed() + if takeHostage.type == "agressor" then - if not IsEntityPlayingAnim(PlayerPedId(), takeHostage.agressor.animDict, takeHostage.agressor.anim, 3) then - TaskPlayAnim(PlayerPedId(), takeHostage.agressor.animDict, takeHostage.agressor.anim, 8.0, -8.0, 100000, takeHostage.agressor.flag, 0, false, false, false) + if not IsEntityPlayingAnim(ped, takeHostage.agressor.animDict, takeHostage.agressor.anim, 3) then + TaskPlayAnim(ped, takeHostage.agressor.animDict, takeHostage.agressor.anim, 8.0, -8.0, 100000, takeHostage.agressor.flag, 0, false, false, false) end elseif takeHostage.type == "hostage" then - if not IsEntityPlayingAnim(PlayerPedId(), takeHostage.hostage.animDict, takeHostage.hostage.anim, 3) then - TaskPlayAnim(PlayerPedId(), takeHostage.hostage.animDict, takeHostage.hostage.anim, 8.0, -8.0, 100000, takeHostage.hostage.flag, 0, false, false, false) + if not IsEntityPlayingAnim(ped, takeHostage.hostage.animDict, takeHostage.hostage.anim, 3) then + TaskPlayAnim(ped, takeHostage.hostage.animDict, takeHostage.hostage.anim, 8.0, -8.0, 100000, takeHostage.hostage.flag, 0, false, false, false) end end - Wait(0) end end) Citizen.CreateThread(function() while true do + Citizen.Wait(0) + local ped = playerPed() + if takeHostage.type == "agressor" then - DisableControlAction(0,24,true) -- disable attack - DisableControlAction(0,25,true) -- disable aim - DisableControlAction(0,47,true) -- disable weapon - DisableControlAction(0,58,true) -- disable weapon - DisableControlAction(0,21,true) -- disable sprint - DisablePlayerFiring(PlayerPedId(),true) + DisableControlAction(0, 24, true) -- disable attack + DisableControlAction(0, 25, true) -- disable aim + DisableControlAction(0, 47, true) -- disable weapon + DisableControlAction(0, 58, true) -- disable weapon + DisableControlAction(0, 21, true) -- disable sprint + DisablePlayerFiring(ped, true) drawNativeText("Press [G] to release, [H] to kill") - if IsEntityDead(PlayerPedId()) then + if IsEntityDead(ped) then takeHostage.type = "" takeHostage.InProgress = false ensureAnimDict("reaction@shove") - TaskPlayAnim(PlayerPedId(), "reaction@shove", "shove_var_a", 8.0, -8.0, -1, 168, 0, false, false, false) + TaskPlayAnim(ped, "reaction@shove", "shove_var_a", 8.0, -8.0, -1, 168, 0, false, false, false) TriggerServerEvent("TakeHostage:releaseHostage", takeHostage.targetSrc) end @@ -196,17 +212,17 @@ Citizen.CreateThread(function() takeHostage.type = "" takeHostage.InProgress = false ensureAnimDict("reaction@shove") - TaskPlayAnim(PlayerPedId(), "reaction@shove", "shove_var_a", 8.0, -8.0, -1, 168, 0, false, false, false) + TaskPlayAnim(ped, "reaction@shove", "shove_var_a", 8.0, -8.0, -1, 168, 0, false, false, false) TriggerServerEvent("TakeHostage:releaseHostage", takeHostage.targetSrc) elseif IsDisabledControlJustPressed(0,74) then --kill takeHostage.type = "" takeHostage.InProgress = false ensureAnimDict("anim@gangops@hostage@") - TaskPlayAnim(PlayerPedId(), "anim@gangops@hostage@", "perp_fail", 8.0, -8.0, -1, 168, 0, false, false, false) + TaskPlayAnim(ped, "anim@gangops@hostage@", "perp_fail", 8.0, -8.0, -1, 168, 0, false, false, false) TriggerServerEvent("TakeHostage:killHostage", takeHostage.targetSrc) TriggerServerEvent("TakeHostage:stop",takeHostage.targetSrc) Wait(100) - SetPedShootsAtCoord(PlayerPedId(), 0.0, 0.0, 0.0, 0) + SetPedShootsAtCoord(ped, 0.0, 0.0, 0.0, 0) end elseif takeHostage.type == "hostage" then DisableControlAction(0,21,true) -- disable sprint @@ -233,6 +249,5 @@ Citizen.CreateThread(function() DisableControlAction(0,35,true) -- disable move right DisableControlAction(0,271,true) end - Wait(0) end end) \ No newline at end of file diff --git a/TakeHostage/config.lua b/TakeHostage/config.lua new file mode 100644 index 0000000..d41061d --- /dev/null +++ b/TakeHostage/config.lua @@ -0,0 +1,2 @@ +Config = {} +Config.WebhookURL = "" -- Webhook Here This will log bad cheaters diff --git a/TakeHostage/fxmanifest.lua b/TakeHostage/fxmanifest.lua index 09eccf3..af1c286 100644 --- a/TakeHostage/fxmanifest.lua +++ b/TakeHostage/fxmanifest.lua @@ -1,10 +1,9 @@ --- Resource Metadata fx_version 'bodacious' -games { 'gta5' } +game 'gta5' -author 'rubbertoe98' -description 'TakeHostage' -version '1.0.0' +client_script "client.lua" -client_script "cl_takehostage.lua" -server_script "sv_takehostage.lua" +server_scripts { +"server.lua", + "config.lua" +} diff --git a/TakeHostage/server.lua b/TakeHostage/server.lua new file mode 100644 index 0000000..c27e19f --- /dev/null +++ b/TakeHostage/server.lua @@ -0,0 +1,143 @@ +--Original Author: rubbertoe98 +--Edited & Patched By: Vyast + +local takingHostage, takenHostage = {}, {} +-- Credits to discord docs for the api ref +function SendToDiscord(name, msg, col) + local embed = { + { + ["color"] = 9109247, -- If you have an issue with the string like this change it to "9109247" + ["title"] = "**"..name.."**", + ["description"] = msg, + ["footer"] = { + ["text"] = "discord.gg/Example" + }, + } + } + PerformHttpRequest(Config.WebhookURL, function(err, text, headers) end, 'POST', json.encode({username = "Exploit Log", embeds = embed, avatar_url = "https://cdn.discordapp.com/attachments/891828087912796190/892186680839254086/fcdev.png"}), {['Content-Type'] = 'application/json'}) +end +-- (Example of discord log) SendToDiscord("Cheater Kicked", "**"..GetPlayerName(source).."** (ID: "..source..") has been Kicked for exploiting.\n**EventName:** 'eventhere'\n**Resource:** "..GetCurrentResourceName()) + + +local function log(info) + print(info) +end + +local function getCoords(player) + local coords = nil + if player ~= nil then + local ped = GetPlayerPed(player) + if ped ~= nil then + coords = GetEntityCoords(ped) + end + end + return coords +end + +local function getName(player) + local name = nil + if player ~= nil then + name = GetPlayerName(player) + end + return name +end + +RegisterServerEvent("TakeHostage:sync") +AddEventHandler("TakeHostage:sync", function(target) + local src = source + if src ~= nil and target ~= nil and target ~= -1 then + local srcName = getName(src) + if srcName ~= nil then + local srcCoords, tgtCoords = getCoords(src), getCoords(target) + if srcCoords ~= nil and tgtCoords ~= nil then + local dist = #(srcCoords - tgtCoords) + if dist <= 5.0 then + TriggerClientEvent("TakeHostage:syncTarget", target, src) + takingHostage[src] = target + takenHostage[target] = src + else + SendToDiscord("Cheater Kicked", "**"..GetPlayerName(source).."** (ID: "..source..") has been Kicked for exploiting.\n**EventName:** 'sync'\n**Resource:** "..GetCurrentResourceName()) + + log('^2TakeHostage: ^1'..srcName..'['..tonumber(src)..']^0 is attempting to exploit the event "sync"! Their distance from the target player is ^1'..dist..'^0.') + end + end + end + end +end) + +RegisterServerEvent("TakeHostage:releaseHostage") +AddEventHandler("TakeHostage:releaseHostage", function(target) + local src = source + if src ~= nil and target ~= nil and target ~= -1 then + local srcName = getName(src) + if srcName ~= nil then + local srcCoords, tgtCoords = getCoords(src), getCoords(target) + if srcCoords ~= nil and tgtCoords ~= nil then + local dist = #(srcCoords - tgtCoords) + if dist <= 5.0 then + TriggerClientEvent("TakeHostage:releaseHostage", target, src) + takingHostage[src] = nil + takenHostage[target] = nil + else + SendToDiscord("Cheater Kicked", "**"..GetPlayerName(source).."** (ID: "..source..") has been Kicked for exploiting.\n**EventName:** 'releaseHostage'\n**Resource:** "..GetCurrentResourceName()) + log('^2TakeHostage: ^1'..srcName..'['..tonumber(src)..']^0 is attempting to exploit the event "releaseHostage"! Their distance from the target player is ^1'..dist..'^0.') + end + end + end + end +end) + +RegisterServerEvent("TakeHostage:killHostage") +AddEventHandler("TakeHostage:killHostage", function(target) + local src = source + if src ~= nil and target ~= nil and target ~= -1 then + local srcName = getName(src) + if srcName ~= nil then + local srcCoords, tgtCoords = getCoords(src), getCoords(target) + if srcCoords ~= nil and tgtCoords ~= nil then + local dist = #(srcCoords - tgtCoords) + if dist <= 5.0 then + TriggerClientEvent("TakeHostage:killHostage", target, src) + takingHostage[src] = nil + takenHostage[target] = nil + else + SendToDiscord("Cheater Kicked", "**"..GetPlayerName(source).."** (ID: "..source..") has been Kicked for exploiting.\n**EventName:** 'killHostage'\n**Resource:** "..GetCurrentResourceName()) + log('^2TakeHostage: ^1'..srcName..'['..tonumber(src)..']^0 is attempting to exploit the event "killHostage"! Their distance from the target player is ^1'..dist..'^0.') + end + end + end + end +end) + +RegisterServerEvent("TakeHostage:stop") +AddEventHandler("TakeHostage:stop", function(target) + local src = source + if src ~= nil and target ~= nil and target ~= -1 then + if takingHostage[src] then + TriggerClientEvent("TakeHostage:cl_stop", target) + takingHostage[src] = nil + takenHostage[target] = nil + elseif takenHostage[src] then + TriggerClientEvent("TakeHostage:cl_stop", target) + takenHostage[src] = nil + takingHostage[target] = nil + end + end +end) + +AddEventHandler('playerDropped', function(reason) + local src = source + if src ~= nil then + if takingHostage[src] then + TriggerClientEvent("TakeHostage:cl_stop", takingHostage[src]) + takenHostage[takingHostage[src]] = nil + takingHostage[src] = nil + end + + if takenHostage[src] then + TriggerClientEvent("TakeHostage:cl_stop", takenHostage[src]) + takingHostage[takenHostage[src]] = nil + takenHostage[src] = nil + end + end +end) diff --git a/TakeHostage/sv_takehostage.lua b/TakeHostage/sv_takehostage.lua deleted file mode 100644 index d89390d..0000000 --- a/TakeHostage/sv_takehostage.lua +++ /dev/null @@ -1,60 +0,0 @@ -local takingHostage = {} ---takingHostage[source] = targetSource, source is takingHostage targetSource -local takenHostage = {} ---takenHostage[targetSource] = source, targetSource is being takenHostage by source - -RegisterServerEvent("TakeHostage:sync") -AddEventHandler("TakeHostage:sync", function(targetSrc) - local source = source - - TriggerClientEvent("TakeHostage:syncTarget", targetSrc, source) - takingHostage[source] = targetSrc - takenHostage[targetSrc] = source -end) - -RegisterServerEvent("TakeHostage:releaseHostage") -AddEventHandler("TakeHostage:releaseHostage", function(targetSrc) - local source = source - TriggerClientEvent("TakeHostage:releaseHostage", targetSrc, source) - takingHostage[source] = nil - takenHostage[targetSrc] = nil -end) - -RegisterServerEvent("TakeHostage:killHostage") -AddEventHandler("TakeHostage:killHostage", function(targetSrc) - local source = source - TriggerClientEvent("TakeHostage:killHostage", targetSrc, source) - takingHostage[source] = nil - takenHostage[targetSrc] = nil -end) - -RegisterServerEvent("TakeHostage:stop") -AddEventHandler("TakeHostage:stop", function(targetSrc) - local source = source - - if takingHostage[source] then - TriggerClientEvent("TakeHostage:cl_stop", targetSrc) - takingHostage[source] = nil - takenHostage[targetSrc] = nil - elseif takenHostage[source] then - TriggerClientEvent("TakeHostage:cl_stop", targetSrc) - takenHostage[source] = nil - takingHostage[targetSrc] = nil - end -end) - -AddEventHandler('playerDropped', function(reason) - local source = source - - if takingHostage[source] then - TriggerClientEvent("TakeHostage:cl_stop", takingHostage[source]) - takenHostage[takingHostage[source]] = nil - takingHostage[source] = nil - end - - if takenHostage[source] then - TriggerClientEvent("TakeHostage:cl_stop", takenHostage[source]) - takingHostage[takenHostage[source]] = nil - takenHostage[source] = nil - end -end) \ No newline at end of file