diff --git a/VERSION b/VERSION index b123147..ea710ab 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.1 \ No newline at end of file +1.2 \ No newline at end of file diff --git a/client.lua b/client.lua index a642d24..f4e5cde 100644 --- a/client.lua +++ b/client.lua @@ -1,4 +1,4 @@ -local isDead, OnlineMedics, medicCalled, medicOnRoad, triedToRevive = false, 5, false, false, false +local isDead, OnlineMedics, medicCalled, medicOnRoad, triedToRevive, wasRevived = false, 5, false, false, false, false local taskVehicle, taskNPC, taskBlip = nil, nil, nil AddEventHandler('esx:onPlayerDeath', function(data) @@ -10,6 +10,12 @@ AddEventHandler('playerSpawned', function(spawn) isDead = false medicCalled = false medicOnRoad = false + + if wasRevived then + wasRevived = false + TriggerServerEvent('msk_aimedic:removeMoney') + end + leaveTarget() end) @@ -22,11 +28,11 @@ CreateThread(function() while true do local sleep = 500 - if isDead and OnlineMedics <= Config.Jobs.amount then + if isDead and OnlineMedics <= Config.Jobs.amount and hasEnoughMoney() then sleep = 0 if not medicCalled and not triedToRevive then - drawGenericText(Translation[Config.Locale]['input']:format(Config.Hotkey.label)) + drawGenericText(Translation[Config.Locale]['input']:format(Config.Hotkey.label, comma(Config.RevivePrice))) if IsControlJustPressed(0, Config.Hotkey.key) then medicCalled = true @@ -125,6 +131,7 @@ npcToPlayer = function(target, targetCoords, vehicle, vehicleCoords, npc) Wait(Config.ReviveDuration * 1000) if not Config.ReviveChance.enable then + wasRevived = true Config.ReviveTrigger() ClearPedTasks(npc) advancedNotification(Translation[Config.Locale]['was_revived']:format(Config.Medic.npcName), 'Los Santos', 'Medical Department', 'CHAR_CALL911') @@ -133,6 +140,7 @@ npcToPlayer = function(target, targetCoords, vehicle, vehicleCoords, npc) local chance = math.random(100) if chance <= Config.ReviveChance.chance then + wasRevived = true Config.ReviveTrigger() ClearPedTasks(npc) advancedNotification(Translation[Config.Locale]['was_revived']:format(Config.Medic.npcName), 'Los Santos', 'Medical Department', 'CHAR_CALL911') @@ -177,6 +185,13 @@ leaveTarget = function() taskNPC = nil end +refreshOnlineMedics = function() + ESX.TriggerServerCallback('msk_aimedic:getOnlineMedics', function(medics) + OnlineMedics = medics + end) +end +refreshOnlineMedics() + drawGenericText = function(text) SetTextColour(186, 186, 186, 255) SetTextFont(0) @@ -199,4 +214,37 @@ advancedNotification = function(text, title, subtitle, icon, flash, icontype) AddTextComponentString(text) SetNotificationMessage(icon, icon, flash, icontype, title, subtitle) DrawNotification(false, true) +end + +hasEnoughMoney = function() + local cash = getAccount('money').money + local bank = getAccount('bank').money + + return cash >= Config.RevivePrice or bank >= Config.RevivePrice +end + +getAccount = function(account) + local player = ESX.GetPlayerData() + + for k, v in pairs(player.accounts) do + if v.name == account then + return v + end + end + return false +end + +comma = function(int, tag) + if not tag then tag = '.' end + local newInt = int + + while true do + newInt, k = string.gsub(newInt, "^(-?%d+)(%d%d%d)", '%1'..tag..'%2') + + if (k == 0) then + break + end + end + + return newInt end \ No newline at end of file diff --git a/config.lua b/config.lua index 022c3b3..eda8d7c 100644 --- a/config.lua +++ b/config.lua @@ -3,10 +3,17 @@ Config = {} Config.Locale = 'de' Config.VersionChecker = true ---------------------------------------------------------------- +-- Add the Webhook Link in server.lua +Config.DiscordLog = true +Config.botColor = "6205745" -- https://www.mathsisfun.com/hexadecimal-decimal-colors.html +Config.botName = "MSK Scripts" +Config.botAvatar = "https://i.imgur.com/PizJGsh.png" +---------------------------------------------------------------- Config.Hotkey = {key = 38, label = 'E'} Config.SpawnRadius = 150 -- default: 150 meters Config.DrivingStyle = 786475 -- default: 786475 // https://vespura.com/fivem/drivingstyle/ ---------------------------------------------------------------- +Config.RevivePrice = 5000 -- Price to get revived Config.ReviveDuration = 10 -- in seconds // default: 10 seconds Config.ReviveChance = { diff --git a/fxmanifest.lua b/fxmanifest.lua index b979977..67bc5a6 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -4,7 +4,7 @@ games { 'gta5' } author 'Musiker15 - MSK Scripts' name 'msk_aimedic' description 'AI Medic NPC' -version '1.1' +version '1.2' lua54 'yes' diff --git a/server.lua b/server.lua index 0169b7d..4a8c932 100644 --- a/server.lua +++ b/server.lua @@ -1,3 +1,5 @@ +local webHookLink = "INSERT DISCORD WEBHOOK LINK HERE" + CreateThread(function() while true do local sleep = 10000 @@ -16,6 +18,17 @@ CreateThread(function() end end) +RegisterServerEvent('msk_aimedic:removeMoney') +AddEventHandler('msk_aimedic:removeMoney', function() + local src = source + local xPlayer = ESX.GetPlayerFromId(src) + local cash = xPlayer.getAccount('money').money + local account = 'money' + + if cash < Config.RevivePrice then account = 'bank' end + xPlayer.removeAccountMoney(account, Config.RevivePrice) + sendDiscordLog(xPlayer) +end) ESX.RegisterServerCallback('msk_aimedic:getOnlineMedics', function(source, cb) local src = source @@ -40,6 +53,43 @@ isMedic = function(playerJob) return false end +comma = function(int, tag) + if not tag then tag = '.' end + local newInt = int + + while true do + newInt, k = string.gsub(newInt, "^(-?%d+)(%d%d%d)", '%1'..tag..'%2') + + if (k == 0) then + break + end + end + + return newInt +end + +sendDiscordLog = function(xPlayer) + if not Config.DiscordLog then return end + + local content = {{ + ["title"] = "MSK AI Medic", + ["description"] = Translation[Config.Locale]['discord_webhook']:format(xPlayer.name, xPlayer.source), + ["color"] = Config.botColor, + ["footer"] = { + ["text"] = "© MSK Scripts • " .. os.date("%d/%m/%Y %H:%M:%S"), + ["icon_url"] = Config.botAvatar + } + }} + + PerformHttpRequest(webHookLink, function(err, text, headers) end, 'POST', json.encode({ + username = Config.botName, + embeds = content, + avatar_url = Config.botAvatar + }), { + ['Content-Type'] = 'application/json' + }) +end + GithubUpdater = function() GetCurrentVersion = function() return GetResourceMetadata( GetCurrentResourceName(), "version" ) diff --git a/translation.lua b/translation.lua index 5f25408..3c2c0c2 100644 --- a/translation.lua +++ b/translation.lua @@ -2,17 +2,21 @@ Translation = {} ---------------------------------------------------------------- Translation = { ['de'] = { - ['input'] = 'Drücke ~g~%s~s~ um einen AI Medic zu rufen.', + ['input'] = 'Drücke ~g~%s~s~ um einen AI Medic zu rufen. Kosten: ~g~$%s~s~', ['medic_send'] = '~g~%s~s~ ist auf dem Weg zu dir!', ['was_revived'] = 'Du wurdest von ~g~%s~s~ wiederbelebt.', ['revive_fail'] = '~g~%s~s~ konnte dich nicht wiederbeleben.', ['revive_fail_after_x_tries'] = '~g~%s~s~ konnte dich nach %s Versuchen nicht wiederbeleben.', + ['pay_fee'] = 'Du hast die Kosten von ~g~$%s~s~ bezahlt.', + ['discord_webhook'] = 'Der Spieler **%s (ID: %s)** wurde vom AI Medics wiederbelebt.', }, ['en'] = { - ['input'] = 'Press ~g~%s~s~ to call the AI Medic.', + ['input'] = 'Press ~g~%s~s~ to call the AI Medic. Price: ~g~$%s~s~', ['medic_send'] = '~g~%s~s~ is on the way to you!', ['was_revived'] = 'You were revived by ~g~%s~s~.', ['revive_fail'] = '~g~%s~s~ could not revive you.', ['revive_fail_after_x_tries'] = '~g~%s~s~ could not revive you after %s attempts.', + ['pay_fee'] = 'You paid the cost of ~g~$%s~s~.', + ['discord_webhook'] = 'The player **%s (ID: %s)** was revived by AI Medics.', }, } \ No newline at end of file