Skip to content

Commit

Permalink
Update v1.2
Browse files Browse the repository at this point in the history
* Added Fee for revive
* Added Discord Webhook
  • Loading branch information
Musiker15 committed Sep 3, 2023
1 parent d814049 commit eeba65f
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 7 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1
1.2
54 changes: 51 additions & 3 deletions client.lua
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -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')
Expand All @@ -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')
Expand Down Expand Up @@ -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)
Expand All @@ -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
7 changes: 7 additions & 0 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
50 changes: 50 additions & 0 deletions server.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local webHookLink = "INSERT DISCORD WEBHOOK LINK HERE"

CreateThread(function()
while true do
local sleep = 10000
Expand All @@ -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
Expand All @@ -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" )
Expand Down
8 changes: 6 additions & 2 deletions translation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
},
}

0 comments on commit eeba65f

Please sign in to comment.