. . . Posted May 19, 2016 Share Posted May 19, 2016 Hello, I need help... You see I made a Varg follower and it works just fine and everything... there's just one little problem and that it can summon hounds even when tamed which I don't want because it breaks my mod's balance! This is the code which involves the Varg summoning hounds local function NumHoundsToSpawn(inst) local numHounds = TUNING.WARG_BASE_HOUND_AMOUNT local pt = Vector3(inst.Transform:GetWorldPosition()) local ents = TheSim:FindEntities(pt.x, pt.y, pt.z, TUNING.WARG_NEARBY_PLAYERS_DIST, {"player"}, {"playerghost"}) for i,player in ipairs(ents) do local playerAge = player.components.age:GetAgeInDays() local addHounds = math.clamp(Lerp(1, 4, playerAge/100), 1, 4) numHounds = numHounds + addHounds end local numFollowers = inst.components.leader:CountFollowers() local num = math.min(numFollowers+numHounds/2, numHounds) -- only spawn half the hounds per howl num = (math.log(num)/0.4)+1 -- 0.4 is approx log(1.5) num = RoundToNearest(num, 1) return num - numFollowers end I don't want to remove the Varg's abilty to summon hounds while it's not tamed so I wanted to make it that he can't spawn hounds (to make not able to spawn hounds you just change the numbers in the above code to 0) when he has inst.AddTag("notraptrigger") which he gains when he is tamed. So, I did this (of course if there's an different way to go about changing his summoning code when he is tamed then that's fine too, it doesn't have to be when he gains inst.AddTag("notraptrigger")) local function NumHoundsToSpawn(inst) local numHounds = TUNING.WARG_BASE_HOUND_AMOUNT local pt = Vector3(inst.Transform:GetWorldPosition()) local ents = TheSim:FindEntities(pt.x, pt.y, pt.z, TUNING.WARG_NEARBY_PLAYERS_DIST, {"player"}, {"playerghost"}) for i,player in ipairs(ents) do local playerAge = player.components.age:GetAgeInDays() local addHounds = math.clamp(Lerp(1, 4, playerAge/100), 1, 4) numHounds = numHounds + addHounds end local numFollowers = inst.components.leader:CountFollowers() local num = math.min(numFollowers+numHounds/2, numHounds) -- only spawn half the hounds per howl num = (math.log(num)/0.4)+1 -- 0.4 is approx log(1.5) num = RoundToNearest(num, 1) return num - numFollowers if dude:HasTag("notraptrigger") then return local numHounds = 0 * TUNING.WARG_BASE_HOUND_AMOUNT local pt = Vector3(inst.Transform:GetWorldPosition()) local ents = TheSim:FindEntities(pt.x, pt.y, pt.z, TUNING.WARG_NEARBY_PLAYERS_DIST, {"player"}, {"playerghost"}) for i,player in ipairs(ents) do local playerAge = player.components.age:GetAgeInDays() local addHounds = math.clamp(Lerp(0, 0, playerAge/0), 0, 0) numHounds = numHounds + addHounds end local numFollowers = inst.components.leader:CountFollowers() local num = math.min(numFollowers+numHounds/0, numHounds) -- only spawn half the hounds per howl num = (math.log(num)/0)+0 -- 0.4 is approx log(1.5) num = RoundToNearest(num, 0) return num - numFollowers end end Of course the game just crashes like always, so please somebody tell me the proper way to do this, please ! If worse comes to worse and nobody can help me then I guess I will just make that he can't summon hounds at all ... Link to comment Share on other sites More sharing options...
Aquaterion Posted May 19, 2016 Share Posted May 19, 2016 (edited) you're using return wrong return stops the function at where return is written, and you can return values, but not declare them in the return(not to mention numHounds already existed); return local numHounds = 0 * TUNING.WARG_BASE_HOUND_AMOUNT --to return 0 * TUNING.WARG_BASE_HOUND_AMOUNT also, "dude" doesn't exist in this function you should be able to do something like this(check if he has a leader) if inst.components.follower and inst.components.follower:GetLeader() ~= nil then return 0 end Edited May 19, 2016 by Aquaterion Link to comment Share on other sites More sharing options...
. . . Posted May 21, 2016 Author Share Posted May 21, 2016 Aquaterion I did this local function NumHoundsToSpawn(inst) local numHounds = TUNING.WARG_BASE_HOUND_AMOUNT local pt = Vector3(inst.Transform:GetWorldPosition()) local ents = TheSim:FindEntities(pt.x, pt.y, pt.z, TUNING.WARG_NEARBY_PLAYERS_DIST, {"player"}, {"playerghost"}) for i,player in ipairs(ents) do local playerAge = player.components.age:GetAgeInDays() local addHounds = math.clamp(Lerp(1, 4, playerAge/100), 1, 4) numHounds = numHounds + addHounds end local numFollowers = inst.components.leader:CountFollowers() local num = math.min(numFollowers+numHounds/2, numHounds) -- only spawn half the hounds per howl num = (math.log(num)/0.4)+1 -- 0.4 is approx log(1.5) num = RoundToNearest(num, 1) return num - numFollowers else if inst.components.follower and inst.components.follower:GetLeader() ~= nil then return 0 end return 0 * TUNING.WARG_BASE_HOUND_AMOUNT local pt = Vector3(inst.Transform:GetWorldPosition()) local ents = TheSim:FindEntities(pt.x, pt.y, pt.z, TUNING.WARG_NEARBY_PLAYERS_DIST, {"player"}, {"playerghost"}) for i,player in ipairs(ents) do local playerAge = player.components.age:GetAgeInDays() local addHounds = math.clamp(Lerp(0, 0, playerAge/0), 0, 0) numHounds = numHounds + addHounds end local numFollowers = inst.components.leader:CountFollowers() local num = math.min(numFollowers+numHounds/0, numHounds) -- only spawn half the hounds per howl num = (math.log(num)/0)+0 -- 0.4 is approx log(1.5) num = RoundToNearest(num, 0) return num - numFollowers end but just crashes the game, please help ! Link to comment Share on other sites More sharing options...
Muche Posted May 21, 2016 Share Posted May 21, 2016 What does the log say? Anyways, I can see two syntactical errors - at line 18 there is else without previous if; at line 22 there is return 0 * TUNING.WARG_BASE_HOUND_AMOUNT that is not the last statement of a block, there is code following it. Also, fixing the first error by removing the else at line 18 makes return num - numFollowers at line 17 not valid, since it becomes not the last statement of a block. See https://www.lua.org/manual/5.1/manual.html#2.4.4. Link to comment Share on other sites More sharing options...
Aquaterion Posted May 21, 2016 Share Posted May 21, 2016 (edited) I went to look at the default code for varg, and I realised you copy paste most of it again? why? Try this: local function NumHoundsToSpawn(inst) local numHounds = TUNING.WARG_BASE_HOUND_AMOUNT if inst.components.follower and inst.components.follower:GetLeader ~= nil then return 0--these 3 lines should be all you need. end local pt = Vector3(inst.Transform:GetWorldPosition()) local ents = TheSim:FindEntities(pt.x, pt.y, pt.z, TUNING.WARG_NEARBY_PLAYERS_DIST, {"player"}, {"playerghost"}) for i,player in ipairs(ents) do local playerAge = player.components.age:GetAgeInDays() local addHounds = math.clamp(Lerp(1, 4, playerAge/100), 1, 4) numHounds = numHounds + addHounds end local numFollowers = inst.components.leader:CountFollowers() local num = math.min(numFollowers+numHounds/2, numHounds) -- only spawn half the hounds per howl num = (math.log(num)/0.4)+1 -- 0.4 is approx log(1.5) num = RoundToNearest(num, 1) return num - numFollowers end Edited May 21, 2016 by Aquaterion Link to comment Share on other sites More sharing options...
. . . Posted May 21, 2016 Author Share Posted May 21, 2016 Aquaterion I put the code you gave me local function NumHoundsToSpawn(inst) local numHounds = TUNING.WARG_BASE_HOUND_AMOUNT if inst.components.follower and inst.components.follower:GetLeader ~= nil then --This is 144 return 0--these 3 lines should be all you need. end local pt = Vector3(inst.Transform:GetWorldPosition()) local ents = TheSim:FindEntities(pt.x, pt.y, pt.z, TUNING.WARG_NEARBY_PLAYERS_DIST, {"player"}, {"playerghost"}) for i,player in ipairs(ents) do local playerAge = player.components.age:GetAgeInDays() local addHounds = math.clamp(Lerp(1, 4, playerAge/100), 1, 4) numHounds = numHounds + addHounds end local numFollowers = inst.components.leader:CountFollowers() local num = math.min(numFollowers+numHounds/2, numHounds) -- only spawn half the hounds per howl num = (math.log(num)/0.4)+1 -- 0.4 is approx log(1.5) num = RoundToNearest(num, 1) return num - numFollowers end When I try to go in the game it crashes then says ":144: function arguments expected near '~='" any help appreciated from anyone ! Also, the reason I copy and paste is because I don't really understand difficult coding so I just try my luck, 90% of the time my copy paste crashes, 10% of the time actually works ... And if it doesn't work then I come to the forums for help which thank god so many kind people here willing to help noobs like me ! Link to comment Share on other sites More sharing options...
Aquaterion Posted May 21, 2016 Share Posted May 21, 2016 33 minutes ago, SuperDavid said: Aquaterion I put the code you gave me local function NumHoundsToSpawn(inst) local numHounds = TUNING.WARG_BASE_HOUND_AMOUNT if inst.components.follower and inst.components.follower:GetLeader ~= nil then --This is 144 return 0--these 3 lines should be all you need. end local pt = Vector3(inst.Transform:GetWorldPosition()) local ents = TheSim:FindEntities(pt.x, pt.y, pt.z, TUNING.WARG_NEARBY_PLAYERS_DIST, {"player"}, {"playerghost"}) for i,player in ipairs(ents) do local playerAge = player.components.age:GetAgeInDays() local addHounds = math.clamp(Lerp(1, 4, playerAge/100), 1, 4) numHounds = numHounds + addHounds end local numFollowers = inst.components.leader:CountFollowers() local num = math.min(numFollowers+numHounds/2, numHounds) -- only spawn half the hounds per howl num = (math.log(num)/0.4)+1 -- 0.4 is approx log(1.5) num = RoundToNearest(num, 1) return num - numFollowers end When I try to go in the game it crashes then says ":144: function arguments expected near '~='" any help appreciated from anyone ! Also, the reason I copy and paste is because I don't really understand difficult coding so I just try my luck, 90% of the time my copy paste crashes, 10% of the time actually works ... And if it doesn't work then I come to the forums for help which thank god so many kind people here willing to help noobs like me ! oh oops change GetLeader to GetLeader() Link to comment Share on other sites More sharing options...
. . . Posted May 21, 2016 Author Share Posted May 21, 2016 Thank you so much Aquaterion it works perfectly! Now he don't summon hounds when he howls when tamed, thanks so much !!! Now if I can ask just 1 more thing because I don't think my next question's big enough for a new topic is do you know a code that can give a health regeneration to the spider, hound, warg ect. like 1 health per 10 seconds, that would be so helpful & thanks for all of your help, you really are so awesome! Link to comment Share on other sites More sharing options...
Aquaterion Posted May 21, 2016 Share Posted May 21, 2016 (edited) 1 hour ago, SuperDavid said: Thank you so much Aquaterion it works perfectly! Now he don't summon hounds when he howls when tamed, thanks so much !!! Now if I can ask just 1 more thing because I don't think my next question's big enough for a new topic is do you know a code that can give a health regeneration to the spider, hound, warg ect. like 1 health per 10 seconds, that would be so helpful & thanks for all of your help, you really are so awesome! inst:DoPeriodicTask(10, --do this every 10seconds function() if inst.components.health then inst.components.health:DoDelta(1) --heal 1hp end end) Edited May 21, 2016 by Aquaterion Link to comment Share on other sites More sharing options...
. . . Posted May 21, 2016 Author Share Posted May 21, 2016 Aquaterion... YOU'RE AWESOME !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 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