halberdsturgeon Posted March 26, 2014 Share Posted March 26, 2014 I'm completely new to lua and still struggling to get my mind around the basics; as the title suggests, I'm trying to make a character that gets a damage bonus when using certain existing weapons (farming implements), but I haven't been able to find any existing files that give me an indication of how to do this. Anyone able to help? Link to comment https://forums.kleientertainment.com/forums/topic/33578-modding-a-character-adding-a-damage-multiplier-for-certain-weapons/ Share on other sites More sharing options...
halberdsturgeon Posted March 29, 2014 Author Share Posted March 29, 2014 Hm, nobody can give me a hand with this? Link to comment https://forums.kleientertainment.com/forums/topic/33578-modding-a-character-adding-a-damage-multiplier-for-certain-weapons/#findComment-439846 Share on other sites More sharing options...
debugman18 Posted March 29, 2014 Share Posted March 29, 2014 (edited) Hm, nobody can give me a hand with this?Well, assuming you know where to put it (hint: your character's constructor):inst:DoPeriodicTask(0, function(inst) local weapon = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HAND) if weapon:HasTag("mod_multipliedweapon") then local boost = (whatever multiplier you want) local newdamage = weapon.components.weapon.damage * boost if weapon.components.weapon then weapon.components.weapon:SetDamage(newdamage) end endend)You'll then want to give each weapon the "mod_multpliedweapon" tag through your modmain.local function addmultipliedweapontag(inst) inst:AddTag("mod_multipliedweapon")endFor example, to add it to the nightsword:AddPrefabPostInit("nightsword", addmultipliedweapontag) Edited March 29, 2014 by debugman18 Link to comment https://forums.kleientertainment.com/forums/topic/33578-modding-a-character-adding-a-damage-multiplier-for-certain-weapons/#findComment-439959 Share on other sites More sharing options...
halberdsturgeon Posted March 29, 2014 Author Share Posted March 29, 2014 Firstly, thanks a lot for the help, I appreciate it! I'm getting a crash: "attempt to index local 'weapon' (a nil value)". I've fiddled around with it a bit without luck, I'm not sure why it's failing to set the value correctly. Any ideas? Link to comment https://forums.kleientertainment.com/forums/topic/33578-modding-a-character-adding-a-damage-multiplier-for-certain-weapons/#findComment-440215 Share on other sites More sharing options...
debugman18 Posted March 29, 2014 Share Posted March 29, 2014 (edited) Firstly, thanks a lot for the help, I appreciate it! I'm getting a crash: "attempt to index local 'weapon' (a nil value)". I've fiddled around with it a bit without luck, I'm not sure why it's failing to set the value correctly. Any ideas?Yes, it's an issue in the code snippet I gave you. Changeif weapon:HasTag("mod_multipliedweapon") thentoif weapon and weapon:HasTag("mod_multipliedweapon") thenIf it tells you that EQUIPSLOTS is nil, then change EQUIPSLOTS.HAND to _G.EQUIPSLOTS.HAND. Edited March 29, 2014 by debugman18 Link to comment https://forums.kleientertainment.com/forums/topic/33578-modding-a-character-adding-a-damage-multiplier-for-certain-weapons/#findComment-440217 Share on other sites More sharing options...
halberdsturgeon Posted March 30, 2014 Author Share Posted March 30, 2014 Hm, okay. That fixed the error, but the damage bonus doesn't seem to be applying itself. I've got this in my modmain.lua:-- add multiplier for farming implementsfunction addmultipliedweapontag(inst) inst:AddTag("mod_multipliedweapon")endAddPrefabPostInit("shovel", addmultipliedweapontag)AddPrefabPostInit("pitchfork", addmultipliedweapontag)And this in my character prefab, under the local fn = function(inst): -- boost set high for testing purposesinst:DoPeriodicTask(0, function(inst) local weapon = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HAND) if weapon and weapon:HasTag("mod_multipliedweapon") then local boost = 100 local newdamage = weapon.components.weapon.damage * boost if weapon.components.weapon then weapon.components.weapon:SetDamage(newdamage) end endend)Am I missing anything obvious? Link to comment https://forums.kleientertainment.com/forums/topic/33578-modding-a-character-adding-a-damage-multiplier-for-certain-weapons/#findComment-440309 Share on other sites More sharing options...
debugman18 Posted March 30, 2014 Share Posted March 30, 2014 (edited) Hm, okay. That fixed the error, but the damage bonus doesn't seem to be applying itself. I've got this in my modmain.lua:-- add multiplier for farming implementsfunction addmultipliedweapontag(inst) inst:AddTag("mod_multipliedweapon")endAddPrefabPostInit("shovel", addmultipliedweapontag)AddPrefabPostInit("pitchfork", addmultipliedweapontag)And this in my character prefab, under the local fn = function(inst): -- boost set high for testing purposesinst:DoPeriodicTask(0, function(inst) local weapon = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HAND) if weapon and weapon:HasTag("mod_multipliedweapon") then local boost = 100 local newdamage = weapon.components.weapon.damage * boost if weapon.components.weapon then weapon.components.weapon:SetDamage(newdamage) end endend)Am I missing anything obvious?Hmm, what shows up in your log? It might help to add print(newdamage) after declaring newdamage, and to add print(weapon.prefab) in the if block. That way we can see what's being passed. Edit: Oh, I feel silly. It should be EQUIPSLOTS.HANDS. Plural. Edited March 30, 2014 by debugman18 Link to comment https://forums.kleientertainment.com/forums/topic/33578-modding-a-character-adding-a-damage-multiplier-for-certain-weapons/#findComment-440316 Share on other sites More sharing options...
halberdsturgeon Posted March 30, 2014 Author Share Posted March 30, 2014 (edited) Excellent! Works like a charm now. Much more elegant a bit of code than I figured I'd have to use, as well. Thanks a lot. Edit: Oops, wait, there are a couple of problems. It's calling the function over and over again whilst the weapon is equipped and increasing the damage each time. I modified it a little to make it call only once, but then encountered another problem - the damage doesn't change back to normal when the weapon's unequipped, so unequipping and reequipping it repeatedly causes repeated damage increases. Still, I have a much better idea of how things work now than before. Further edit: Got it working with a bit of tweaking. Probably fairly clumsy in how I did it, but it was a good learning experience. Thanks again, wouldn't have had a clue where to start without the help Edited March 30, 2014 by halberdsturgeon Link to comment https://forums.kleientertainment.com/forums/topic/33578-modding-a-character-adding-a-damage-multiplier-for-certain-weapons/#findComment-440320 Share on other sites More sharing options...
NikMik Posted March 30, 2014 Share Posted March 30, 2014 you could put something like this in the modmain. Much smaller and works just fine:AddPrefabPostInit("spear", function(inst)if GetPlayer().prefab == "Your character's name" then inst.components.weapon:SetDamage(How much damage you want it to do)endend) Link to comment https://forums.kleientertainment.com/forums/topic/33578-modding-a-character-adding-a-damage-multiplier-for-certain-weapons/#findComment-440339 Share on other sites More sharing options...
halberdsturgeon Posted March 30, 2014 Author Share Posted March 30, 2014 (edited) Hm... when I put that in the modmain, I get an error: "function arguments expected near '='". Edit: Wait, no, my bad, I must've been entering it wrong. It is giving me a different error, though - something about GetPlayer() being a nil value? Edit edit: Nevermind, I'm a fool, it works perfectly well. Must have been because I was testing it on Wilson's prefab. Edited March 30, 2014 by halberdsturgeon Link to comment https://forums.kleientertainment.com/forums/topic/33578-modding-a-character-adding-a-damage-multiplier-for-certain-weapons/#findComment-440350 Share on other sites More sharing options...
NikMik Posted March 30, 2014 Share Posted March 30, 2014 It has to be in a specific part of the modmain, beneath "GeyPlayer() = GLOBAL.GetPlayer(). Tlese you could replace the GetPlayer() in the postinit with GLOBAL.GeyPlayer(). Link to comment https://forums.kleientertainment.com/forums/topic/33578-modding-a-character-adding-a-damage-multiplier-for-certain-weapons/#findComment-440354 Share on other sites More sharing options...
halberdsturgeon Posted March 30, 2014 Author Share Posted March 30, 2014 Ah, I see. Yes, now it works fine in all cases; thanks. Pardon my silly newbie errors. Link to comment https://forums.kleientertainment.com/forums/topic/33578-modding-a-character-adding-a-damage-multiplier-for-certain-weapons/#findComment-440357 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