RadiantRoma Posted March 3, 2017 Share Posted March 3, 2017 For a new character I'm developing, I wanted the character to benefit from having many trees around in the area. If anyone knows some way for a way to add some sort of invisible aura that would affect the character, maybe increasing speed or damage when in a certain radius of a tree, help would be highly appreciated. Link to comment Share on other sites More sharing options...
CarlZalph Posted March 4, 2017 Share Posted March 4, 2017 1 hour ago, Romanful said: For a new character I'm developing, I wanted the character to benefit from having many trees around in the area. If anyone knows some way for a way to add some sort of invisible aura that would affect the character, maybe increasing speed or damage when in a certain radius of a tree, help would be highly appreciated. In the master_postinit. inst:DoPeriodicTask( 0.1, function(inst) local x, y, z = inst.Transform:GetWorldPosition() local ents = GLOBAL.TheSim:FindEntities(x, y, z, 4.0, {"tree"}, {"FX", "NOCLICK", "DECOR", "INLIMBO", "stump", "burnt"}) if #ents > 0 then if inst.mymodname_treebonus == nil then inst.components.locomotor:SetExternalSpeedMultiplier(inst, "mymodname_treebonus", 5.0*GLOBAL.TUNING.CANE_SPEED_MULT) inst.mymodname_treebonus = true end else if inst.mymodname_treebonus ~= nil then inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "mymodname_treebonus") inst.mymodname_treebonus = nil end end end ) I set it to make your movement 5*cane speed to easily see when it procs. 4.0 is the radius around trees in which the effect takes hold. 4.0 = 1 turf, for reference in dimensions. Link to comment Share on other sites More sharing options...
RadiantRoma Posted March 4, 2017 Author Share Posted March 4, 2017 33 minutes ago, CarlZalph said: In the master_postinit. inst:DoPeriodicTask( 0.1, function(inst) local x, y, z = inst.Transform:GetWorldPosition() local ents = GLOBAL.TheSim:FindEntities(x, y, z, 4.0, {"tree"}, {"FX", "NOCLICK", "DECOR", "INLIMBO", "stump", "burnt"}) if #ents > 0 then if inst.mymodname_treebonus == nil then inst.components.locomotor:SetExternalSpeedMultiplier(inst, "mymodname_treebonus", 5.0*GLOBAL.TUNING.CANE_SPEED_MULT) inst.mymodname_treebonus = true end else if inst.mymodname_treebonus ~= nil then inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "mymodname_treebonus") inst.mymodname_treebonus = nil end end end ) I set it to make your movement 5*cane speed to easily see when it procs. 4.0 is the radius around trees in which the effect takes hold. 4.0 = 1 turf, for reference in dimensions. Thank you so much for helping! I put that in the prefabs file and replaced all of the "mymodname" with the character's name (Wollawossiky), but got this error message when attempting to enter the game. Quote [00:02:06]: [string "../mods/Wollawossiky/scripts/prefabs/wollaw..."]:87: variable 'GLOBAL' is not declared LUA ERROR stack traceback: =[C]:-1 in (global) error (C) <-1--1> scripts/strict.lua:23 in () ? (Lua) <21-26> ../mods/Wollawossiky/scripts/prefabs/wollawossiky.lua:87 in (field) fn (Lua) <85-102> scripts/scheduler.lua:177 in (method) OnTick (Lua) <155-207> scripts/scheduler.lua:371 in (global) RunScheduler (Lua) <369-377> scripts/update.lua:170 in () ? (Lua) <149-228> Thanks again for the help Link to comment Share on other sites More sharing options...
CarlZalph Posted March 4, 2017 Share Posted March 4, 2017 40 minutes ago, Romanful said: Thank you so much for helping! I put that in the prefabs file and replaced all of the "mymodname" with the character's name (Wollawossiky), but got this error message when attempting to enter the game. Thanks again for the help Yeah for custom prefabs and such remove the "GLOBAL." portions (The dot included). Only needed in modmain, where I throw things together. Link to comment Share on other sites More sharing options...
RadiantRoma Posted March 5, 2017 Author Share Posted March 5, 2017 10 hours ago, CarlZalph said: Yeah for custom prefabs and such remove the "GLOBAL." portions (The dot included). Only needed in modmain, where I throw things together. It works like a charm! If I wanted to also add a damage bonus would I add a line underneath so it would be this? inst:DoPeriodicTask( 0.1, function(inst) local x, y, z = inst.Transform:GetWorldPosition() local ents = TheSim:FindEntities(x, y, z, 3.5, {"tree"}, {"FX", "NOCLICK", "DECOR", "INLIMBO", "stump", "burnt"}) if #ents > 0 then if inst.wollawossiky_treebonus == nil then inst.components.locomotor:SetExternalSpeedMultiplier(inst, "wollawossiky_treebonus", 1.0*TUNING.CANE_SPEED_MULT) inst.components.combat:SetExternalDamageMultiplier(inst, "wollawossiky_treebonus", 2.0*TUNING.WILSON_DAMAGE_MULT) inst.wollawossiky_treebonus = true end else if inst.wollawossiky_treebonus ~= nil then inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "wollawossiky_treebonus") inst.components.combat:RemoveExternalDamageMultiplier(inst, "wollawossiky_treebonus") inst.wollawossiky_treebonus = nil end end end ) Link to comment Share on other sites More sharing options...
CarlZalph Posted March 5, 2017 Share Posted March 5, 2017 2 minutes ago, Romanful said: It works like a charm! If I wanted to also add a damage bonus would I add a line underneath so it would be this? Since you're making a new character, use: inst.components.combat.damagemultiplier = 2.0*TUNING.WILSON_DAMAGE_MULT and inst.components.combat.damagemultiplier = 1.0 Link to comment Share on other sites More sharing options...
RadiantRoma Posted March 5, 2017 Author Share Posted March 5, 2017 2 minutes ago, CarlZalph said: Since you're making a new character, use: inst.components.combat.damagemultiplier = 2.0*TUNING.WILSON_DAMAGE_MULT and inst.components.combat.damagemultiplier = 1.0 Got this error code when I got in the radius of a tree in game Quote [00:01:23]: [string "../mods/Wollawossiky/scripts/prefabs/wollaw..."]:93: attempt to perform arithmetic on field 'WILSON_DAMAGE_MULT' (a nil value) LUA ERROR stack traceback: ../mods/Wollawossiky/scripts/prefabs/wollawossiky.lua:93 in (field) fn (Lua) <85-104> scripts/scheduler.lua:177 in (method) OnTick (Lua) <155-207> scripts/scheduler.lua:371 in (global) RunScheduler (Lua) <369-377> scripts/update.lua:170 in () ? (Lua) <149-228> This is what the code looks like... inst:DoPeriodicTask( 0.1, function(inst) local x, y, z = inst.Transform:GetWorldPosition() local ents = TheSim:FindEntities(x, y, z, 3.5, {"tree"}, {"FX", "NOCLICK", "DECOR", "INLIMBO", "stump", "burnt"}) if #ents > 0 then if inst.wollawossiky_treebonus == nil then inst.components.locomotor:SetExternalSpeedMultiplier(inst, "wollawossiky_treebonus", 1.0*TUNING.CANE_SPEED_MULT) inst.components.combat.damagemultiplier = 2.0*TUNING.WILSON_DAMAGE_MULT inst.components.combat.damagemultiplier = 1.0 inst.wollawossiky_treebonus = true end else if inst.wollawossiky_treebonus ~= nil then inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "wollawossiky_treebonus") inst.wollawossiky_treebonus = nil end end end ) Link to comment Share on other sites More sharing options...
CarlZalph Posted March 5, 2017 Share Posted March 5, 2017 2 minutes ago, Romanful said: Got this error code when I got in the radius of a tree in game This is what the code looks like... I just took what you had. There is no damage mult for wilson, default is just 1.0. So it's: inst.components.combat.damagemultiplier = 2.0 Link to comment Share on other sites More sharing options...
RadiantRoma Posted March 5, 2017 Author Share Posted March 5, 2017 17 minutes ago, CarlZalph said: I just took what you had. There is no damage mult for wilson, default is just 1.0. So it's: inst.components.combat.damagemultiplier = 2.0 Fixed! Thank you so much for all your help! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now