D4rk0 Posted September 13, 2013 Share Posted September 13, 2013 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. Link to comment https://forums.kleientertainment.com/forums/topic/27700-mod-questionaddprefabpostinit-can-it-be-done/ Share on other sites More sharing options...
Heavenfall Posted September 13, 2013 Share Posted September 13, 2013 No, I don't think it is. Link to comment https://forums.kleientertainment.com/forums/topic/27700-mod-questionaddprefabpostinit-can-it-be-done/#findComment-320566 Share on other sites More sharing options...
debugman18 Posted September 13, 2013 Share Posted September 13, 2013 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. Use an eventlistener for lightning, then apply a speed boost to it. It'll help to perform a check to see if he's charged or not, as well. Link to comment https://forums.kleientertainment.com/forums/topic/27700-mod-questionaddprefabpostinit-can-it-be-done/#findComment-320588 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