diff --git a/cl_uteknark.lua b/cl_uteknark.lua index 5c60f89..1cc86cf 100644 --- a/cl_uteknark.lua +++ b/cl_uteknark.lua @@ -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) @@ -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) @@ -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)) @@ -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) \ No newline at end of file diff --git a/lib/cropstate.lua b/lib/cropstate.lua index 5f0f26e..5a38cfc 100644 --- a/lib/cropstate.lua +++ b/lib/cropstate.lua @@ -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 @@ -179,6 +180,7 @@ 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 @@ -186,15 +188,14 @@ if onServer then 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 diff --git a/sv_uteknark.lua b/sv_uteknark.lua index 70bda2b..5511c09 100644 --- a/sv_uteknark.lua +++ b/sv_uteknark.lua @@ -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 @@ -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') @@ -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) @@ -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) @@ -412,4 +408,4 @@ RegisterCommand('uteknark', function(source, args, raw) else inChat(source, _U('command_empty', VERSION)) end -end,true) \ No newline at end of file +end,true)