Skip to content

Commit

Permalink
Merge pull request #507 from bitpredator/develop
Browse files Browse the repository at this point in the history
refactor:  Improved code formatting + fixed many issues
  • Loading branch information
bitpredator authored Sep 8, 2023
2 parents 0b01a0a + 35ba6c0 commit 688f605
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 94 deletions.
10 changes: 4 additions & 6 deletions server-data/resources/[esx_addons]/BOBsHunt/client/functions.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
drawText3D = function(x, y, z, text)
local onScreen,_x,_y=World3dToScreen2d(x,y,z)
local px,py,pz=table.unpack(GetGameplayCamCoords())

local onScreen, _x, _y = World3dToScreen2d(x,y,z)
local _, _, _ = table.unpack(GetGameplayCamCoords())
local scale = 0.30

if onScreen then
SetTextScale(scale, scale)
SetTextFont(4)
Expand All @@ -14,7 +13,6 @@ drawText3D = function(x, y, z, text)
SetTextCentre(1)
AddTextComponentString(text)
DrawText(_x,_y)
local factor = (string.len(text)) / 650
--DrawRect(_x, _y + 0.0120, 0.030 + factor , 0.030, 66, 66, 66, 100)
local _ = (string.len(text)) / 650
end
end
152 changes: 75 additions & 77 deletions server-data/resources/[esx_addons]/BOBsHunt/client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,19 @@ ESX = nil
CreateThread(function()
while ESX == nil do
Wait(5)
ESX = exports["es_extended"]:getSharedObject(), function(library)
ESX = library
end
ESX = exports["es_extended"]:getSharedObject()
end
if ESX.IsPlayerLoaded() then
ESX.PlayerData = ESX.GetPlayerData()
end
end)

local oPlayer = false
local InVehicle = false
local playerpos = false

CreateThread(function()
while(true) do
oPlayer = PlayerPedId()
InVehicle = IsPedInAnyVehicle(oPlayer, true)
playerpos = GetEntityCoords(oPlayer)
Wait(500)
end
Expand All @@ -34,86 +30,88 @@ CreateThread(function()
local pos = GetEntityCoords(ped)
local distance = GetDistanceBetweenCoords(pos.x, pos.y, pos.z, playerpos.x, playerpos.y, playerpos.z, true)
if distance < 2 and CanSlaughterPed(ped) then
drawText3D(pos.x, pos.y, pos.z + 0.6, '⚙️')
while IsControlPressed(0, 38) do
drawText3D(pos.x, pos.y, pos.z + 0.5, '[H] ~b~Skin Animal~s~')
break
end
if IsControlJustPressed(1,74) then
if GetSelectedPedWeapon(PlayerPedId()) == GetHashKey('WEAPON_KNIFE') then
oldped = ped
SetEntityHeading(ped,GetHeadingFromVector_2d(pos.x-playerpos.x,pos.y-playerpos.y)+180)
SetEntityHeading(oPlayer,GetHeadingFromVector_2d(pos.x-playerpos.x,pos.y-playerpos.y))
exports.rprogress:Custom({
Async = true,
x = 0.5,
y = 0.5,
From = 0,
To = 100,
Duration = 5000,
Radius = 60,
Stroke = 10,
MaxAngle = 360,
Rotation = 0,
Easing = "easeLinear",
Label = "SKINNING",
LabelPosition = "right",
Color = "rgba(255, 255, 255, 1.0)",
BGColor = "rgba(107, 109, 110, 0.95)",
Animation = {
--scenario = "CODE_HUMAN_MEDIC_TEND_TO_DEAD", -- https://pastebin.com/6mrYTdQv
animationDictionary = "anim@heists@narcotics@funding@gang_idle", -- https://alexguirre.github.io/animations-list/
animationName = "gang_chatting_idle01",
},
DisableControls = {
Mouse = false,
Player = true,
Vehicle = true
},
})
Wait(5000)
ClearPedTasks(PlayerPedId())
if GetEntityModel(ped) == GetHashKey("a_c_boar") then
local item = 'boar_meat'
local p_name = 'boar meat'
TriggerServerEvent('esx_bobhunt:getPelt', item, p_name)
elseif GetEntityModel(ped) == GetHashKey("a_c_mtlion") then
local item = 'pelt_mtnlion'
local p_name = 'Mountain Lion pelt'
TriggerServerEvent('esx_bobhunt:getPelt', item, p_name)
elseif GetEntityModel(ped) == GetHashKey("a_c_deer") then
local item = 'deer_meat'
local p_name = 'deer_meat'
TriggerServerEvent('esx_bobhunt:getPelt', item, p_name)
elseif GetEntityModel(ped) == GetHashKey("a_c_coyote") then
local item = 'pelt_coyote'
local p_name = 'Coyote pelt'
TriggerServerEvent('esx_bobhunt:getPelt', item, p_name)
elseif GetEntityModel(ped) == GetHashKey("a_c_rabbit_01") then
local item = 'rabbit_meat'
local p_name = 'Rabbit meat'
TriggerServerEvent('esx_bobhunt:getPelt', item, p_name)
end

Wait(10)
SetPedAsNoLongerNeeded(oldped)
if DoesEntityExist(ped) then
DeleteEntity(ped)
end
Wait(1000)
break
else
ESX.showNotification(_U('knife_uses'))
drawText3D(pos.x, pos.y, pos.z + 0.6, '⚙️ [H] ~b~Skin Animal~s~')
while IsControlPressed(0, 38) do
break
end
if IsControlJustPressed(1,74) then
if GetSelectedPedWeapon(PlayerPedId()) == GetHashKey('WEAPON_KNIFE') then
local oldped = ped
SetEntityHeading(ped,GetHeadingFromVector_2d(pos.x-playerpos.x,pos.y-playerpos.y)+180)
SetEntityHeading(oPlayer,GetHeadingFromVector_2d(pos.x-playerpos.x,pos.y-playerpos.y))
exports.rprogress:Custom({
Async = true,
x = 0.5,
y = 0.5,
From = 0,
To = 100,
Duration = 5000,
Radius = 60,
Stroke = 10,
MaxAngle = 360,
Rotation = 0,
Easing = "easeLinear",
Label = "SKINNING",
LabelPosition = "right",
Color = "rgba(255, 255, 255, 1.0)",
BGColor = "rgba(107, 109, 110, 0.95)",
Animation = {
--scenario = "CODE_HUMAN_MEDIC_TEND_TO_DEAD", -- https://pastebin.com/6mrYTdQv
animationDictionary = "anim@heists@narcotics@funding@gang_idle", -- https://alexguirre.github.io/animations-list/
animationName = "gang_chatting_idle01",
},

DisableControls = {
Mouse = false,
Player = true,
Vehicle = true
},
})
Wait(5000)

ClearPedTasks(PlayerPedId())
if GetEntityModel(ped) == GetHashKey("a_c_boar") then
local item = 'boar_meat'
local p_name = 'boar meat'
TriggerServerEvent('esx_bobhunt:getPelt', item, p_name)
elseif GetEntityModel(ped) == GetHashKey("a_c_mtlion") then
local item = 'pelt_mtnlion'
local p_name = 'Mountain Lion pelt'
TriggerServerEvent('esx_bobhunt:getPelt', item, p_name)
elseif GetEntityModel(ped) == GetHashKey("a_c_deer") then
local item = 'deer_meat'
local p_name = 'deer meat'
TriggerServerEvent('esx_bobhunt:getPelt', item, p_name)
elseif GetEntityModel(ped) == GetHashKey("a_c_coyote") then
local item = 'pelt_coyote'
local p_name = 'Coyote pelt'
TriggerServerEvent('esx_bobhunt:getPelt', item, p_name)
elseif GetEntityModel(ped) == GetHashKey("a_c_rabbit_01") then
local item = 'rabbit_meat'
local p_name = 'Rabbit meat'
TriggerServerEvent('esx_bobhunt:getPelt', item, p_name)
end

Wait(10)
SetPedAsNoLongerNeeded(oldped)
if DoesEntityExist(ped) then
DeleteEntity(ped)
end
end
Wait(1000)
break
else
ESX.showNotification(_U('knife_uses'))
end
end
end
until not success
EndFindPed(handle)
end
end)

local oldped
function CanSlaughterPed(ped)
if not IsPedAPlayer(ped) and not IsPedInAnyVehicle(ped,false) and not IsPedHuman(ped) and IsEntityDead(ped) and ped ~= oldped and GetEntityModel(ped) == GetHashKey("a_c_boar") or GetEntityModel(ped) == GetHashKey("a_c_coyote") or GetEntityModel(ped) == GetHashKey("a_c_deer") or GetEntityModel(ped) == GetHashKey("a_c_mtlion") or GetEntityModel(ped) == GetHashKey("a_c_rabbit_01") then
if not IsPedAPlayer(ped) and not IsPedInAnyVehicle(ped,false) and not IsPedHuman(ped) and IsEntityDead(ped) and ped ~= oldped and GetEntityModel(ped) == GetHashKey("a_c_boar") or GetEntityModel(ped) == GetHashKey("a_c_coyote") or GetEntityModel(ped) == GetHashKey("a_c_deer") or GetEntityModel(ped) == GetHashKey("a_c_mtlion") or GetEntityModel(ped) == GetHashKey("a_c_rabbit_01") then
return true
end
return false
Expand Down
4 changes: 1 addition & 3 deletions server-data/resources/[esx_addons]/BOBsHunt/items-legacy.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@


INSERT INTO `items` (`name`, `label`, `weight`, `rare`, `can_remove`) VALUES
('pelt_boar', 'Boar Pelt', 1, 0, 1),
('pelt_mtnlion', 'Mountain Lion Pelt', 1, 0, 1),
('pelt_deer', 'Deer Pelt', 1, 0, 1),
('pelt_coyote', 'Coyote Pelt', 1, 0, 1),
('pelt_rabbit', 'Rabbit Pelt', 1, 0, 1);
('pelt_rabbit', 'Rabbit Pelt', 1, 0, 1);
4 changes: 1 addition & 3 deletions server-data/resources/[esx_addons]/BOBsHunt/items.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@


INSERT INTO `items` (`name`, `label`, `limit`, `rare`, `can_remove`) VALUES
('pelt_boar', 'Boar Pelt', 10, 0, 1),
('pelt_mtnlion', 'Mountain Lion Pelt', 10, 0, 1),
('pelt_deer', 'Deer Pelt', 10, 0, 1),
('pelt_coyote', 'Coyote Pelt', 10, 0, 1),
('pelt_rabbit', 'Rabbit Pelt', 10, 0, 1);
('pelt_rabbit', 'Rabbit Pelt', 10, 0, 1);
1 change: 1 addition & 0 deletions server-data/resources/[esx_addons]/BOBsHunt/locales/it.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Locales['en'] = {
['knife_uses'] = 'Devi usare un coltello',
['you_collected'] = 'Hai raccolto un',
['deer_meat'] = 'Deer meat',
}
7 changes: 2 additions & 5 deletions server-data/resources/[esx_addons]/BOBsHunt/server/main.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
ESX = nil

ESX = exports["es_extended"]:getSharedObject(), function(response)
ESX = response
end
ESX = exports["es_extended"]:getSharedObject()

RegisterServerEvent('esx_bobhunt:getPelt')
AddEventHandler('esx_bobhunt:getPelt', function(item, p_name)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
xPlayer.addInventoryItem(item, 10)
TriggerClientEvent('esx:showNotification', source, _U('you_collected') .. p_name)
end)
end)

0 comments on commit 688f605

Please sign in to comment.