Skip to content
This repository has been archived by the owner on Nov 25, 2022. It is now read-only.

Commit

Permalink
Re-did how scenarios are handled
Browse files Browse the repository at this point in the history
Way less likely to get stuck in a scenario now, and it's not longer
possible to ninja out of cars by trying to do a drive-by plant.
  • Loading branch information
DemmyDemon committed Nov 19, 2019
1 parent a2efa9e commit 433ac2c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 30 deletions.
41 changes: 23 additions & 18 deletions cl_uteknark.lua
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,35 @@ function RunScenario(name, facing)
inScenario = true
end

RegisterNetEvent('esx_uteknark:do')
AddEventHandler ('esx_uteknark:do', function(scenarioName, location)
if Config.Scenario[scenarioName] then
print("Got order for scenario " .. scenarioName)
Citizen.CreateThread(function()
local begin = GetGameTimer()
RunScenario(Config.Scenario[scenarioName], location)
while GetGameTimer() <= begin + Config.ScenarioTime do
Citizen.Wait(0)
end
if inScenario then
ClearPedTasks(PlayerPedId())
end
inScenario = false
print("Scenario "..scenarioName.." ends")
end)
else
print("Got ordered to do invalid scenario "..scenarioName)
end
end)

RegisterNetEvent('esx_uteknark:attempt_plant')
AddEventHandler ('esx_uteknark:attempt_plant', function()
local plantable, message, location, _, soil = getPlantingLocation()
if plantable then
TriggerServerEvent('esx_uteknark:success_plant', location, soil)
RunScenario(Config.Scenario.Plant)
lastAction = GetGameTimer()
else
makeToast(_U('planting_text'), _U(message))
ClearPedTasksImmediately(PlayerPedId())
end
end)

Expand Down Expand Up @@ -248,15 +267,11 @@ Citizen.CreateThread(function()
while true do
local now = GetGameTimer()
local playerPed = PlayerPedId()

if inScenario then
debug('In scenario', inScenario)
if now >= lastAction + Config.ScenarioTime then
ClearPedTasks(playerPed)
inScenario = false
end
end

if #activePlants > 0 then
debug(#activePlants,'active plants')
local myLocation = GetEntityCoords(playerPed)
Expand Down Expand Up @@ -292,16 +307,12 @@ Citizen.CreateThread(function()
table.remove(activePlants, closestIndex)
DeleteObject(closestPlant.object)
TriggerServerEvent('esx_uteknark:remove', closestPlant.id, myLocation)
RunScenario(Config.Scenario.Destroy, closestPlant.at)
-- FIXME: This causes people to run away!
-- AddExplosion(closestPlant.at,24,0.5,true,false,0.0,true)
else
if stage.interact then
interactHelp(closestPlant.stage, _U(stage.label))
if IsControlJustPressed(0, 38) then
lastAction = now
TriggerServerEvent('esx_uteknark:frob', closestPlant.id, myLocation)
RunScenario(Config.Scenario.Frob, closestPlant.at)
end
else
passiveHelp(closestPlant.stage, _U(stage.label))
Expand Down Expand Up @@ -485,9 +496,3 @@ AddEventHandler ('esx_uteknark:test_forest',function(count, randomStage)
TriggerEvent("chat:addMessage", {args={'UteKnark', 'Actual viable locations: '..#forest}})
TriggerServerEvent('esx_uteknark:test_forest', forest)
end)

RegisterNetEvent('esx_uteknark:abort')
AddEventHandler ('esx_uteknark:abort', function()
-- FIXME: This causes people to ninja out of moving cars if they try to plant while driving
ClearPedTasksImmediately(PlayerPedId())
end)
5 changes: 3 additions & 2 deletions lib/cropstate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ if onServer then
if distance <= Config.Distance.Interact then
cropstate:remove(plantID)
makeToast(src, _U('interact_text'), _U('interact_destroyed'))
doScenario(src, 'Destroy', plantLocation)
else
Citizen.Trace(GetPlayerName(src)..' ('..src..') is too far away from '..plantID..' to remove it ('..distance'm)\n')
end
Expand All @@ -179,22 +180,22 @@ if onServer then
local seeds = math.random(Config.YieldSeed[1], Config.YieldSeed[2])
if GiveItem(src, Config.Items.Product, yield) then
cropstate:remove(plantID)
doScenario(src, 'Frob', plantLocation)
if seeds > 0 and GiveItem(src, Config.Items.Seed, seeds) then
makeToast(src, _U('interact_text'), _U('interact_harvested', yield, seeds))
else
makeToast(src, _U('interact_text'), _U('interact_harvested', yield, 0))
end
else
makeToast(src, _U('interact_text'), _U('interact_full', yield))
abortAction(src)
end
else
if #Growth > plant.data.stage then
if not Config.Items.Tend or TakeItem(src, Config.Items.Tend) then
makeToast(src, _U('interact_text'), _U('interact_tended'))
cropstate:update(plantID, plant.data.stage + 1)
doScenario(src, 'Frob', plantLocation)
else
abortAction(src)
makeToast(src, _U('interact_text'), _U('interact_missing_item'))
end
end
Expand Down
16 changes: 6 additions & 10 deletions sv_uteknark.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ local VERBOSE = false
local lastPlant = {}
local tickTimes = {}
local tickPlantCount = 0
local VERSION = '1.1.0'
local VERSION = '1.1.1'

AddEventHandler('playerDropped',function(why)
lastPlant[source] = nil
Expand Down Expand Up @@ -134,8 +134,9 @@ function plantSeed(location, soil)
return true
end

function abortAction(who)
TriggerClientEvent('esx_uteknark:abort', who)
function doScenario(who, what, where)
verbose('Telling', who,'to',what,'at',where)
TriggerClientEvent('esx_uteknark:do', who, what, where)
end

RegisterNetEvent('esx_uteknark:success_plant')
Expand All @@ -162,22 +163,19 @@ AddEventHandler ('esx_uteknark:success_plant', function(location, soil)
if TakeItem(src, Config.Items.Seed) then
if plantSeed(location, soil) then
makeToast(src, _U('planting_text'), _U('planting_ok'))
doScenario(src, 'Plant', location)
else
GiveItem(src, Config.Items.Seed)
makeToast(src, _U('planting_text'), _U('planting_failed'))
abortAction(src)
end
else
makeToast(src, _U('planting_text'), _U('planting_no_seed'))
abortAction(src)
end
else
makeToast(src, _U('planting_text'), _U('planting_too_close'))
abortAction(src)
end
else
makeToast(src, _U('planting_text'), _U('planting_not_suitable_soil'))
abortAction(src)
end
end)

Expand Down Expand Up @@ -232,11 +230,9 @@ Citizen.CreateThread(function()
lastPlant[source] = now
else
makeToast(source, _U('planting_text'), _U('planting_no_seed'))
abortAction(source)
end
else
makeToast(source, _U('planting_text'), _U('planting_too_fast'))
abortAction(source)
end
end)
end)
Expand Down Expand Up @@ -412,4 +408,4 @@ RegisterCommand('uteknark', function(source, args, raw)
else
inChat(source, _U('command_empty', VERSION))
end
end,true)
end,true)

0 comments on commit 433ac2c

Please sign in to comment.