forked from Simnation/Main
296 lines
12 KiB
Lua
296 lines
12 KiB
Lua
-----------------For support, scripts, and more----------------
|
||
--------------- https://discord.gg/wasabiscripts -------------
|
||
---------------------------------------------------------------
|
||
|
||
-- Definiere Strings direkt in der client.lua, falls sie nicht geladen wurden
|
||
if not Strings then
|
||
Strings = {
|
||
intro_instruction = 'Drücke ~INPUT_ATTACK~ zum Auswerfen, ~INPUT_FRONTEND_RRIGHT~ zum Abbrechen.',
|
||
rope_broke = 'Kaputt.',
|
||
rope_broke_desc = 'Oha, zu fest gezogen! Das Seil ist gerissen.',
|
||
cannot_perform = 'Nope.',
|
||
cannot_perform_desc = 'Das geht gerade nicht – hier kannst du nicht magnet-fischen.',
|
||
failed = 'Oops, das war nix.',
|
||
failed_find = 'Nichts gefunden – der Magnet hat nichts angezogen.',
|
||
no_water = 'Error 404: Wasser nicht gefunden.',
|
||
no_water_desc = 'Dein Magnet braucht Wasser, um effektiv zu sein.',
|
||
no_magnet = 'Kein Magnet.',
|
||
no_magnet_desc = 'Ohne Magnet kannst du nichts anziehen.',
|
||
magnet_lost = 'Magnet verloren.',
|
||
magnet_lost_desc = 'Dein Magnet hat sich vom Seil gelöst.',
|
||
find_success = 'Fund gesichert!',
|
||
find_success_desc = 'Du hast eine/n %s gefunden!',
|
||
sell_shop_blip = 'Schrotthändler',
|
||
sell_finds = '[E] - Funde verkaufen',
|
||
kicked = "Du kannst's versuchen, aber das klappt hier nicht.",
|
||
sold_for = 'Fund verkauft.',
|
||
sold_for_desc = 'Du hast %sx %s für $%s verkauft.',
|
||
got_pull = 'Achtung, da zieht was!',
|
||
got_pull_desc = 'Der Magnet hat etwas gefunden, zieh ihn hoch!',
|
||
waiting_find = 'Geduld, der Magnet sucht noch.',
|
||
waiting_find_desc = 'Ein bisschen Geduld – gleich findest du etwas.',
|
||
cannot_carry = 'Kein Platz!',
|
||
cannot_carry_desc = 'Du schleppst schon genug – mehr passt nicht rein!'
|
||
}
|
||
end
|
||
|
||
local magnetFishing = false
|
||
local lastDispatchTime = 0
|
||
|
||
-- Funktion für Polizeimeldungen
|
||
local function SendPoliceAlert(coords, itemName)
|
||
if not Config.policeAlert.enabled then return end
|
||
|
||
-- Prüfe Cooldown
|
||
local currentTime = GetGameTimer()
|
||
if (currentTime - lastDispatchTime) < Config.policeAlert.cooldown then
|
||
return
|
||
end
|
||
|
||
-- Bestimme die Chance basierend auf dem Item
|
||
local alertChance = Config.policeAlert.chance
|
||
if Config.suspiciousItems[itemName] then
|
||
alertChance = Config.suspiciousItems[itemName]
|
||
end
|
||
|
||
-- Zufallschance für Meldung
|
||
if math.random(1, 100) > alertChance then
|
||
return
|
||
end
|
||
|
||
-- Setze Cooldown-Timer
|
||
lastDispatchTime = currentTime
|
||
|
||
-- Sende Meldung über ps-dispatch
|
||
local streetName = GetStreetNameFromHashKey(GetStreetNameAtCoord(coords.x, coords.y, coords.z))
|
||
|
||
exports['ps-dispatch']:MagnetFishing({
|
||
coords = coords,
|
||
streetName = streetName,
|
||
gender = IsPedMale(cache.ped) and 'männlich' or 'weiblich',
|
||
model = GetEntityModel(cache.ped),
|
||
itemName = itemName
|
||
})
|
||
end
|
||
|
||
if Config.sellShop.enabled then
|
||
CreateThread(function()
|
||
local ped, textUI
|
||
--CreateBlip(Config.sellShop.coords, 356, 1, Strings.sell_shop_blip, 0.80)
|
||
local point = lib.points.new({
|
||
coords = Config.sellShop.coords,
|
||
distance = 30
|
||
})
|
||
|
||
function point:nearby()
|
||
if self.currentDistance < self.distance then
|
||
if not ped then
|
||
lib.requestAnimDict('mini@strip_club@idles@bouncer@base', 100)
|
||
lib.requestModel(Config.sellShop.ped, 100)
|
||
ped = CreatePed(28, Config.sellShop.ped, Config.sellShop.coords.x, Config.sellShop.coords.y, Config.sellShop.coords.z, Config.sellShop.heading, false, false)
|
||
FreezeEntityPosition(ped, true)
|
||
SetEntityInvincible(ped, true)
|
||
SetBlockingOfNonTemporaryEvents(ped, true)
|
||
TaskPlayAnim(ped, 'mini@strip_club@idles@bouncer@base', 'base', 8.0, 0.0, -1, 1, 0, 0, 0, 0)
|
||
end
|
||
if self.currentDistance <= 1.8 then
|
||
if not textUI then
|
||
lib.showTextUI(Strings.sell_finds)
|
||
textUI = true
|
||
end
|
||
if IsControlJustReleased(0, 38) then
|
||
MagnetSellItems()
|
||
end
|
||
elseif self.currentDistance >= 1.9 and textUI then
|
||
lib.hideTextUI()
|
||
textUI = nil
|
||
end
|
||
end
|
||
end
|
||
|
||
function point:onExit()
|
||
if ped then
|
||
local model = GetEntityModel(ped)
|
||
SetModelAsNoLongerNeeded(model)
|
||
DeletePed(ped)
|
||
SetPedAsNoLongerNeeded(ped)
|
||
RemoveAnimDict('mini@strip_club@idles@bouncer@base')
|
||
ped = nil
|
||
end
|
||
end
|
||
end)
|
||
end
|
||
|
||
-- Function to check for available magnets and select the best one
|
||
local function GetBestAvailableMagnet()
|
||
local availableMagnets = {}
|
||
|
||
-- Check all magnet types
|
||
for _, magnet in pairs(Config.magnets.types) do
|
||
local hasItem = lib.callback.await('nordi_magnetfishing:checkItem', 100, magnet.itemName)
|
||
if hasItem then
|
||
table.insert(availableMagnets, magnet)
|
||
end
|
||
end
|
||
|
||
if #availableMagnets == 0 then
|
||
return nil
|
||
end
|
||
|
||
-- Sort magnets by catch bonus (highest first)
|
||
table.sort(availableMagnets, function(a, b)
|
||
return (a.catchBonus or 0) > (b.catchBonus or 0)
|
||
end)
|
||
|
||
-- Return the best magnet
|
||
return availableMagnets[1]
|
||
end
|
||
|
||
-- Function to handle the magnet fishing process
|
||
local function StartMagnetFishingProcess(selectedMagnet, waterLoc)
|
||
magnetFishing = true
|
||
|
||
-- Create magnet rope prop
|
||
local model = `prop_rope_family_3` -- Besseres Prop für ein Seil mit Magnet
|
||
lib.requestModel(model, 100)
|
||
local magnetRope = CreateObject(model, GetEntityCoords(cache.ped), true, false, false)
|
||
AttachEntityToEntity(magnetRope, cache.ped, GetPedBoneIndex(cache.ped, 28422), -0.010000, 0.270000, -0.230000, 84.299286, 105.998955, -0.600000, true, true, false, true, 1, true)
|
||
SetModelAsNoLongerNeeded(model)
|
||
|
||
-- Load animations
|
||
lib.requestAnimDict('amb@world_human_golf_player@male@idle_a', 100) -- Für das Auswerfen
|
||
lib.requestAnimDict('amb@world_human_stand_fishing@idle_a', 100) -- Für das Warten
|
||
|
||
-- Initial animation - Auswerfen des Magneten
|
||
TaskPlayAnim(cache.ped, 'amb@world_human_golf_player@male@idle_a', 'idle_a' , 8.0, -8.0, -1, 16, 0, false, false, false)
|
||
Wait(2000)
|
||
TaskPlayAnim(cache.ped, 'amb@world_human_stand_fishing@idle_a', 'idle_c', 8.0, -8.0, -1, 1, 0, false, false, false)
|
||
|
||
-- Main magnet fishing loop
|
||
while magnetFishing do
|
||
Wait(0)
|
||
local unarmed = `WEAPON_UNARMED`
|
||
SetCurrentPedWeapon(cache.ped, unarmed)
|
||
ShowHelp(Strings.intro_instruction)
|
||
DisableControlAction(0, 24, true)
|
||
|
||
-- Cast magnet
|
||
if IsDisabledControlJustReleased(0, 24) then
|
||
-- Auswerfen Animation
|
||
TaskPlayAnim(cache.ped, 'amb@world_human_golf_player@male@idle_a', 'idle_a', 8.0, -8.0, -1, 16, 0, false, false, false)
|
||
TriggerEvent('nordi_magnetfishing:notify', Strings.waiting_find, Strings.waiting_find_desc, 'inform')
|
||
|
||
-- Wait for magnet to find something
|
||
local waitTime = math.random(Config.timeForFind.min, Config.timeForFind.max)
|
||
Wait(waitTime)
|
||
|
||
-- Check if player is still magnet fishing
|
||
if not magnetFishing then
|
||
break
|
||
end
|
||
|
||
TriggerEvent('nordi_magnetfishing:notify', Strings.got_pull, Strings.got_pull_desc, 'inform')
|
||
Wait(1000)
|
||
|
||
-- Get find data based on selected magnet
|
||
local findData = lib.callback.await('nordi_magnetfishing:getFindData', 100, selectedMagnet.itemName)
|
||
|
||
-- Skill check to retrieve find
|
||
if lib.skillCheck(findData.difficulty) then
|
||
-- Erfolgreiche Zieh-Animation
|
||
ClearPedTasks(cache.ped)
|
||
TaskPlayAnim(cache.ped, 'amb@world_human_hammering@male@base', 'base', 8.0, -8.0, -1, 16, 0, false, false, false)
|
||
Wait(1500)
|
||
TryMagnetFind(findData)
|
||
-- Sende Polizeimeldung nach erfolgreichem Fund
|
||
SendPoliceAlert(GetEntityCoords(cache.ped), findData.item)
|
||
TaskPlayAnim(cache.ped, 'amb@world_human_hang_out_street@male_c@base', 'base', 8.0, -8.0, -1, 1, 0, false, false, false)
|
||
|
||
-- Check for magnet loss
|
||
local loseChance = math.random(1,100)
|
||
if loseChance <= selectedMagnet.loseChance then
|
||
TriggerServerEvent('nordi_magnetfishing:loseMagnet', selectedMagnet.itemName)
|
||
TriggerEvent('nordi_magnetfishing:notify', Strings.magnet_lost, Strings.magnet_lost_desc, 'error')
|
||
|
||
-- Check if we still have this magnet
|
||
local hasMagnet = lib.callback.await('nordi_magnetfishing:checkItem', 100, selectedMagnet.itemName)
|
||
if not hasMagnet then
|
||
-- Try to get a new magnet
|
||
local newMagnet = GetBestAvailableMagnet()
|
||
if newMagnet then
|
||
selectedMagnet = newMagnet
|
||
TriggerEvent('nordi_magnetfishing:notify', 'Neuer Magnet', 'Du verwendest jetzt ' .. selectedMagnet.label, 'inform')
|
||
else
|
||
TriggerEvent('nordi_magnetfishing:notify', Strings.no_magnet, Strings.no_magnet_desc, 'error')
|
||
magnetFishing = false
|
||
break
|
||
end
|
||
end
|
||
end
|
||
else
|
||
-- Failed to retrieve find - Fehlgeschlagene Animation
|
||
local breakChance = math.random(1,100)
|
||
if breakChance < Config.magnetRope.breakChance then
|
||
TriggerServerEvent('nordi_magnetfishing:ropeBroke')
|
||
TriggerEvent('nordi_magnetfishing:notify', Strings.rope_broke, Strings.rope_broke_desc, 'error')
|
||
ClearPedTasks(cache.ped)
|
||
magnetFishing = false
|
||
break
|
||
end
|
||
TriggerEvent('nordi_magnetfishing:notify', Strings.failed_find, Strings.failed_find_desc, 'error')
|
||
end
|
||
elseif IsControlJustReleased(0, 194) then
|
||
-- Cancel magnet fishing with backspace
|
||
ClearPedTasks(cache.ped)
|
||
TriggerEvent('nordi_magnetfishing:notify', 'Magnet Fishing abgebrochen', 'Du hast aufgehört zu angeln', 'inform')
|
||
break
|
||
elseif #(GetEntityCoords(cache.ped) - waterLoc) > 30 then
|
||
-- Too far from water
|
||
TriggerEvent('nordi_magnetfishing:notify', 'Zu weit weg', 'Du bist zu weit vom Wasser entfernt', 'error')
|
||
break
|
||
end
|
||
end
|
||
|
||
-- Clean up
|
||
magnetFishing = false
|
||
DeleteObject(magnetRope)
|
||
RemoveAnimDict('amb@world_human_hammering@male@base')
|
||
RemoveAnimDict('amb@world_human_hang_out_street@male_c@base')
|
||
end
|
||
|
||
RegisterNetEvent('nordi_magnetfishing:startMagnetFishing', function()
|
||
-- Check if player is in a valid state to magnet fish
|
||
if IsPedInAnyVehicle(cache.ped) or IsPedSwimming(cache.ped) then
|
||
TriggerEvent('nordi_magnetfishing:notify', Strings.cannot_perform, Strings.cannot_perform_desc, 'error')
|
||
return
|
||
end
|
||
|
||
-- Check if already magnet fishing
|
||
if magnetFishing then
|
||
TriggerEvent('nordi_magnetfishing:notify', 'Already Magnet Fishing', 'You are already magnet fishing', 'error')
|
||
return
|
||
end
|
||
|
||
-- Check for water
|
||
local water, waterLoc = WaterCheck()
|
||
if not water then
|
||
TriggerEvent('nordi_magnetfishing:notify', Strings.no_water, Strings.no_water_desc, 'error')
|
||
return
|
||
end
|
||
|
||
-- Select magnet
|
||
local selectedMagnet = GetBestAvailableMagnet()
|
||
if not selectedMagnet then
|
||
TriggerEvent('nordi_magnetfishing:notify', Strings.no_magnet, Strings.no_magnet_desc, 'error')
|
||
return
|
||
end
|
||
|
||
-- Start magnet fishing process
|
||
TriggerEvent('nordi_magnetfishing:notify', 'Magnet Selected', 'Using ' .. selectedMagnet.label, 'inform')
|
||
StartMagnetFishingProcess(selectedMagnet, waterLoc)
|
||
end)
|
||
|
||
RegisterNetEvent('nordi_magnetfishing:interupt', function()
|
||
magnetFishing = false
|
||
ClearPedTasks(cache.ped)
|
||
end)
|