D4rk0 Posted September 13, 2013 Share Posted September 13, 2013 (edited) So I'm new and I wanna try my own mod. I have enough coding knowledge , but I'm "stuck" at something. How can I overwrite a function , or is it possible to do so , using AddPrefabPostInit ? This is the code: local function onupdate(inst, dt)inst.charge_time = inst.charge_time - dtif inst.charge_time <= 0 theninst.charge_time = 0if inst.charged_task theninst.charged_task:Cancel()inst.charged_task = nilendinst.SoundEmitter:KillSound("overcharge_sound")inst.charged_task = nilinst.Light:Enable(false)inst.components.locomotor.runspeed = TUNING.WILSON_RUN_SPEED inst.AnimState:SetBloomEffectHandle( "" )inst.components.temperature.mintemp = -20inst.components.talker:Say(GetString("wx78", "ANNOUNCE_DISCHARGE"))--inst.SoundEmitter:KillSound("overcharge_sound")else local runspeed_bonus = .5 local rad = 3 if inst.charge_time < 60 then rad = math.max(.1, rad * (inst.charge_time / 60)) runspeed_bonus = (inst.charge_time / 60)*runspeed_bonus end inst.Light:Enable(true) inst.Light:SetRadius(rad)inst.components.locomotor.runspeed = TUNING.WILSON_RUN_SPEED*(1+runspeed_bonus)inst.components.temperature.mintemp = 10endendThe code is taken from WX78 and is supposed to increase runspeed when you're hit by lightning. I want to overwrite this line: inst.components.locomotor.runspeed = TUNING.WILSON_RUN_SPEED*(1+runspeed_bonus)and make it inst.components.locomotor.runspeed = TUNING.WILSON_RUN_SPEED*(2+runspeed_bonus) Is this possible to do in modmain.lua so that I don't have to duplicate the wx78.lua prefab ? EDIT: Sorry if wrong section. Like I said am new here and in a rush writing this. Edited September 13, 2013 by D4rk0 Link to comment https://forums.kleientertainment.com/forums/topic/27698-modding-question-how-do-i-do-this/ Share on other sites More sharing options...
tehMugwump Posted September 13, 2013 Share Posted September 13, 2013 Look at Starter Inventory mod for how to inject things into character lua files... Link to comment https://forums.kleientertainment.com/forums/topic/27698-modding-question-how-do-i-do-this/#findComment-320633 Share on other sites More sharing options...
RCatta Posted September 13, 2013 Share Posted September 13, 2013 (edited) Look at Starter Inventory mod for how to inject things into character lua files... I don't think that's what he wants to know. Sure you can "Add" ,but I don't think you can overwrite functions in a ,say,character prefab using AddPrefabPostInit. You can add custom functions to it (you can actually add just about anything), but not overwrite existing ones. I'm not entirely sure about this though. Edited September 13, 2013 by RCatta Link to comment https://forums.kleientertainment.com/forums/topic/27698-modding-question-how-do-i-do-this/#findComment-320756 Share on other sites More sharing options...
Heavenfall Posted September 13, 2013 Share Posted September 13, 2013 In this specific case you might as well include the whole prefab. Link to comment https://forums.kleientertainment.com/forums/topic/27698-modding-question-how-do-i-do-this/#findComment-320764 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