Jump to content

Recommended Posts

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 = 10endend

The 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 by D4rk0

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 by RCatta

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...