Jump to content

Recommended Posts

Hi everyone, I'm pretty new in the modding of character and I need your advices.

I'd like to make my character run pretty fast when it's "day" period, a little less faster during "dawn" period, and at the same speed as Wilson at "night".

Do you guys know how I could do this ? I guess it's in the "scripts" and "prefabs" folders and into the character's_name.lua file, but I don't know how to do this, but I know that it's possible.

Thank you for your attention !

Edited by AzurasLight
On 2/17/2016 at 2:57 PM, AzurasLight said:

Hi everyone, I'm pretty new in the modding of character and I need your advices.

I'd like to make my character run pretty fast when it's "day" period, a little less faster during "dawn" period, and at the same speed as Wilson at "night".

Do you guys know how I could do this ? I guess it's in the "scripts" and "prefabs" folders and into the character's_name.lua file, but I don't know how to do this, but I know that it's possible.

Thank you for your attention !

prefab file

local day_speed = 5
local dusk_speed = 2.5
local night_speed = 1

local function onphase(inst, phase)
	local speed = 1
	
	if phase == "day" then speed = day_speed
	elseif phase == "dusk" then speed = dusk_speed
	else speed = night_speed
	end
	
	inst.components.locomotor:SetExternalSpeedMultiplier( inst, "Acceleration", speed )

end

master_postinit

inst:WatchWorldState("phase", onphase)

 

Just now, SenL said:

Wow cool code.

What is "Acceleration"? I see the function takes 3 params: source, key and m.

source is inst. speed is m. key is "Acceleration" ... is this just a custom key of locomotor internal array?

This is correct, because we need to have a way of knowing which speed multiplier to change. Technically you can have N speed multipliers on your character, where N is infinite(or as large as lua allows arrays).

I got a crash on "inst:WatchWorldState("phase", onphase)" saying attempting to index global 'inst' (a nil value).

Maybe put in prefab lua?

Edit: Omg I misread. Thought you said put in modmain lua.

Edited by SenL

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...