local fishing = false
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_fish)
textUI = true
end
if IsControlJustReleased(0, 38) then
FishingSellItems()
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
RegisterNetEvent('walker_fishing:startFishing', function()
if IsPedInAnyVehicle(cache.ped) or IsPedSwimming(cache.ped) then
TriggerEvent('walker_fishing:notify', Strings.cannot_perform, Strings.cannot_perform_desc, 'error')
return
end
local hasItem = lib.callback.await('walker_fishing:checkItem', 100, Config.bait.itemName)
if hasItem then
local water, waterLoc = WaterCheck()
if water then
if not fishing then
fishing = true
local model = `prop_fishing_rod_01`
lib.requestModel(model, 100)
local pole = CreateObject(model, GetEntityCoords(cache.ped), true, false, false)
AttachEntityToEntity(pole, cache.ped, GetPedBoneIndex(cache.ped, 18905), 0.1, 0.05, 0, 80.0, 120.0, 160.0, true, true, false, true, 1, true)
SetModelAsNoLongerNeeded(model)
lib.requestAnimDict('mini@tennis', 100)
lib.requestAnimDict('amb@world_human_stand_fishing@idle_a', 100)
TaskPlayAnim(cache.ped, 'mini@tennis', 'forehand_ts_md_far', 1.0, -1.0, 1.0, 48, 0, 0, 0, 0)
Wait(3000)
TaskPlayAnim(cache.ped, 'amb@world_human_stand_fishing@idle_a', 'idle_c', 1.0, -1.0, 1.0, 11, 0, 0, 0, 0)
while fishing do
Wait()
local unarmed = `WEAPON_UNARMED`
SetCurrentPedWeapon(ped, unarmed)
ShowHelp(Strings.intro_instruction)
DisableControlAction(0, 24, true)
if IsDisabledControlJustReleased(0, 24) then
TaskPlayAnim(cache.ped, 'mini@tennis', 'forehand_ts_md_far', 1.0, -1.0, 1.0, 48, 0, 0, 0, 0)
TriggerEvent('walker_fishing:notify', Strings.waiting_bite, Strings.waiting_bite_desc, 'inform')
Wait(math.random(Config.timeForBite.min, Config.timeForBite.max))
TriggerEvent('walker_fishing:notify', Strings.got_bite, Strings.got_bite_desc, 'inform')
Wait(1000)
local fishData = lib.callback.await('walker_fishing:getFishData', 100)
if lib.skillCheck(fishData.difficulty) then
ClearPedTasks(cache.ped)
TryFish(fishData)
TaskPlayAnim(cache.ped, 'amb@world_human_stand_fishing@idle_a', 'idle_c', 1.0, -1.0, 1.0, 11, 0, 0, 0, 0)
else
local breakChance = math.random(1,100)
if breakChance < Config.fishingRod.breakChance then
TriggerServerEvent('walker_fishing:rodBroke')
TriggerEvent('walker_fishing:notify', Strings.rod_broke, Strings.rod_broke_desc, 'error')
ClearPedTasks(cache.ped)
fishing = false
break
end
TriggerEvent('walker_fishing:notify', Strings.failed_fish, Strings.failed_fish_desc, 'error')
end
elseif IsControlJustReleased(0, 194) then
ClearPedTasks(cache.ped)
break
elseif #(GetEntityCoords(cache.ped) - waterLoc) > 30 then
break
end
end
fishing = false
DeleteObject(pole)
RemoveAnimDict('mini@tennis')
RemoveAnimDict('amb@world_human_stand_fishing@idle_a')
end
else
TriggerEvent('walker_fishing:notify', Strings.no_water, Strings.no_water_desc, 'error')
end
else
TriggerEvent('walker_fishing:notify', Strings.no_bait, Strings.no_bait_desc, 'error')
end
end)
RegisterNetEvent('walker_fishing:interupt', function()
fishing = false
ClearPedTasks(cache.ped)
end)
Write, Run & Share Lua code online using OneCompiler's Lua online compiler for free. It's one of the robust, feature-rich online compilers for Lua language, running the latest Lua version 5.4. Getting started with the OneCompiler's Lua editor is easy and fast. The editor shows sample boilerplate code when you choose language as Lua and start coding.
OneCompiler's Lua online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample Lua program which takes name as input and prints hello message with your name.
name = io.read("*a")
print ("Hello ", name)
Lua is a light weight embeddable scripting language which is built on top of C. It is used in almost all kind of applications like games, web applications, mobile applications, image processing etc. It's a very powerful, fast, easy to learn, open-source scripting language.
-- global variables
a = 10
-- local variables
local x = 30
| Value Type | Description |
|---|---|
| number | Represents numbers |
| string | Represents text |
| nil | Differentiates values whether it has data or not |
| boolean | Value can be either true or false |
| function | Represents a sub-routine |
| userdata | Represents arbitary C data |
| thread | Represents independent threads of execution. |
| table | Can hold any value except nil |
While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.
while(condition)
do
--code
end
Repeat-Until is also used to iterate a set of statements based on a condition. It is very similar to Do-While, it is mostly used when you need to execute the statements atleast once.
repeat
--code
until( condition )
For loop is used to iterate a set of statements based on a condition.
for init,max/min value, increment
do
--code
end
Function is a sub-routine which contains set of statements. Usually functions are written when multiple calls are required to same set of statements which increase re-usuability and modularity.
optional_function_scope function function_name( argument1, argument2, argument3........, argumentn)
--code
return params with comma seperated
end