Jump to content

Recommended Posts

I'm making a lamia character and could use some scripting programming help on what to put in if I want to make it so she moves faster with warmer temperatures and slower with colder ones. Anyone have a solution or advice? I really haven't learned the coding language or how to arrange anything but I'd appreciate it. I've taken a look at the character mods by Haruz and found they added a variable for night/day run speeds. is it possible to do the same thing but dependant on the temperature? Snakes are poikilothermic and I think it'd be an interesting dynamic to add to my custom character.

How would an appropriate way be to contact the mod author Haruz? Should I just add them on steam and message them? I can't imagine someone with 800+ subscribes would want strangers to bother them... I want to ask if they'll collab or allow me to use their leveling coding or whatnot. I'm not directly using their character model(s) either just the coding for leveling and the modified speed based on time of day switched to temperature.

relevant files added I believe.
noir.lua speech_noir.lua modmain.lua modinfo.lua

@Argosa47,

put this in noir.lua after "inst.components.locomotor.runspeed = 6":

inst.DoPeriodicTask(inst, 1, function(inst)	inst.components.locomotor.runspeed =   TUNING.WILSON_RUN_SPEED * math.min(math.max(0.75 + 0.5 * inst.components.temperature.current / 70, 0.75), 1.25)	end)
this task will run every second and will scale her runspeed from 75% to 125% between 0 and 70 degrees.

as for contacting, yeah, just add them, dont be shy. u can also try to find and contact them on the forums here.

or just ask here in the forums for help, here are enough pple willing to help or even collab with u.

if u want to use code from other mods, just do it, as long as u do the artrelated parts yourself and dont copy whole mods without puting in any work yourself, noone will mind.

also, i recently collabed with someone on a dragonthemed character, might also be interesting for u: http://forums.kleientertainment.com/topic/52924-wyvard-the-cold-blooded-cavalier/?hl=wyvard

the code i posted above is a shortened version of what we did on his character.

i dont think he has released it on steam yet, but there's a pretty new version of the modmain and the the prefab in his post#12.

Edited by Seiai
  • Like 1

@Seiai, it's better programming/coding practice to listen for the world state for temperature to change instead of wasting processing power on a task being ran every second. This matters significantly when running mods on lesser computers.

inst:WatchWorldState("temperature", function()    inst.components.locomotor.runspeed = TUNING.WILSON_RUN_SPEED * math.min(math.max(0.75 + 0.5 * inst.components.temperature.current / 70, 0.75), 1.25)end, TheWorld)
Edited by Kzisor
  • Like 1

Thanks for the great responses! I'm kinda shy when it comes to asking for help. I have an animator maybe and other stuff I'll post my concept art though too should I do a separate thread?

I want it to be based off of the character's current temp rather than the world-temp I noticed the wording in the code.

 

@Seiai, it's better programming/coding practice to listen for the world state for temperature to change instead of wasting processing power on a task being ran every second. This matters significantly when running mods on lesser computers.

inst:WatchWorldState("temperature", function()    inst.components.locomotor.runspeed = TUNING.WILSON_RUN_SPEED * math.min(math.max(0.75 + 0.5 * inst.components.temperature.current / 70, 0.75), 1.25)end, TheWorld)

 

I highly doubt performance wise yours is better, I would even think its worse. Considering that temperature can change every tick, meaning that event can get fired every tick as opposed to a fixed one per second custom event.

 

I highly doubt performance wise yours is better, I would even think its worse. Considering that temperature can change every tick, meaning that event can get fired every tick as opposed to a fixed one per second custom event.

that was my thought too, however, iam not sure how the taskplaner is implemented. many things in the game are implemented via the updatefunction, which triggers each tick, even stuff that actually only takes effect each second, like the dmg u take from starving or freezing, which could mean, that the taskplaner is much more resourcehungry, than such a direction calculation into a variable.

then again, one periodic task on a playercharacter doesnt really cost that much performance for something such gameplayrelevant, and is maybe easier to use for certain things than a tickrelated function.

@Kzisor, what's your take on this?

Edited by Seiai

Thanks for the great responses! I'm kinda shy when it comes to asking for help. I have an animator maybe and other stuff I'll post my concept art though too should I do a separate thread?

I want it to be based off of the character's current temp rather than the world-temp I noticed the wording in the code.

dont be shy, just ask. there are so many new threads each day asking "how to mod?!", even though the "getting started"-thread is literally an inch away from the "start new topic"- button, so it's nice to have actual questions from pple who try.

as for the thread, until u want to release your mod and make an "official" modthread, or u have problems that the pple that still watch this thread cant fix, u should probably just stay in this one.

as for the temperature: this world-stuff is just for the trigger, it triggers when ALL the temperaturecalculation in the world including your character's are being done(which pretty much just means each tick of the game). the temperature, which it uses for the calculation, depends on the variable in the calculation, and these are from your character.

Edited by Seiai

@Sarcen, @Seiai, the execution of the actual code which is inside the actual task isn't the issue, because it only requires 1-2 milliseconds to actually complete that equation. The issue lies in creating a task which needs to be ran on top of what is already being ran. By creating an additional task you create a scenario where it becomes a "race-condition" with other code to change that specific variable. When creating a program you need to be aware of how others will change the code and modify your approach so that you reduce the amount of race-conditions created in an application. The more race-conditions you create the harder of a time you will have to actually debug an issue in your own code.

 

Example:

If I were to create a mod which added an environmental affect which caused every ones run speed to be reduced by 50% and used a task which is running every second; there would be at times where you would get a "glitchy" feeling because we are both modifying the variable every second. This is not noticeable on high end machines because we usually have the processing power to spare, however, on a computer at the lower end of the spectrum this affect can be easily seen.

 

The proper way of handling this type of scenario is to use event based programming along with the proper execution. The proper execution would be to use the locomotor:SetExternalSpeedMultiplier(source, key, value) function instead of directly setting the run speed. This way no matter what execution either mod uses it will be properly handled and no "glitchiness" will be displayed to the end user.

 

 

Edit:

Alternatively to using the WatchWorldState("temperature") you could use:

inst:ListenForEvent("temperaturedelta", function()     --BLAHend)
Edited by Kzisor
  • Like 3

@Kzisor. Yes, I agree you should be using the locomotor:SetExternalSpeedMultiplier.

 

But that's a completely different issue from how to trigger it. A 1 second timer will still be better on performance, both cpu and network performance. Since changing it every frame will also cause it to be transmitted over the network every (network)tick.

@Sarcen, using the proper function most certainly is tied into the issue. However, I'm not going to argue with you, I've already explained the issues with that approach. The OP may use whichever approach they deem fit for their own execution.

 

 

 

 

Edit:

Alternatively to using the WatchWorldState("temperature") you could use:

inst:ListenForEvent("temperaturedelta", function()     --BLAHend)

This would be listening for when the ambient temperature changes my character's temperature? My only concern if I'm listening for ambient world temperature that wearing a puffy coat and vest and or having a thermal stone wont affect keeping my run-speed up.

Edit: Additionally where would I put this in and for the other code should I change WILSON to NOIR?

 

 

Edited by Argosa47

This is the coding I'm looking at right now copied from @Haruz characters. did I modify the numbers correctly or should I get rid of the things dependant upon the time of day? it's about the leveling function off of the Sollyz character.
-------------------------- my edit

local function runner(inst)
 
local max_upgrades = 30
local upgrades = math.min(inst.level, max_upgrades)
if TheWorld.state.phase == "day" then 
inst.components.locomotor.walkspeed =  math.ceil (4 + upgrades / 6) --9
inst.components.locomotor.runspeed = math.ceil (6 + upgrades / 5) --12
elseif TheWorld.state.phase == "dusk" then
inst.components.locomotor.walkspeed = math.ceil (4 + upgrades / 12) --6.5
inst.components.locomotor.runspeed = math.ceil (6 + upgrades / 12) --8.5
elseif TheWorld.state.phase == "night" then
inst.components.locomotor.walkspeed =  3
inst.components.locomotor.runspeed = 5
end
 
 
end
-----------------------------------------------
 

EDIT: basically what I'm asking is do you guys think I should even keep this in or change it so that it's only related to temperature?

 

Edited by Argosa47

This would be listening for when the ambient temperature changes my character's temperature? My only concern if I'm listening for ambient world temperature that wearing a puffy coat and vest and or having a thermal stone wont affect keeping my run-speed up.

Edit: Additionally where would I put this in and for the other code should I change WILSON to NOIR?

 

You would add that line of code to your master_postfn for NOIR. It would be only listening when your character's temperature changes.

 

 

This is the coding I'm looking at right now copied from @Haruz characters. did I modify the numbers correctly or should I get rid of the things dependant upon the time of day? it's about the leveling function off of the Sollyz character.

-------------------------- my edit

local function runner(inst)
 
local max_upgrades = 30
local upgrades = math.min(inst.level, max_upgrades)
if TheWorld.state.phase == "day" then 
inst.components.locomotor.walkspeed =  math.ceil (4 + upgrades / 6) --9
inst.components.locomotor.runspeed = math.ceil (6 + upgrades / 5) --12
elseif TheWorld.state.phase == "dusk" then
inst.components.locomotor.walkspeed = math.ceil (4 + upgrades / 12) --6.5
inst.components.locomotor.runspeed = math.ceil (6 + upgrades / 12) --8.5
elseif TheWorld.state.phase == "night" then
inst.components.locomotor.walkspeed =  3
inst.components.locomotor.runspeed = 5
end
 
 
end

-----------------------------------------------

 

EDIT: basically what I'm asking is do you guys think I should even keep this in or change it so that it's only related to temperature?

 
You could leave it or change it, it's completely up to you. Leaving it based on time of day eliminates the argument about the performance issue entirely. Personally I'd base it on temperature with a clause that it only update if the temperature changes a full degrees.
inst:ListenForEvent("temperaturedelta", function(inst, data)    if math.modf(data.last) ~= math.modf(data.new) then        -- DO CHANGES HERE TO inst.components.locomotor:SetExternalSpeedMultiplier(source, key, value)    endend)

math.modf separates the decimals from the whole number. The whole number is the first value returned from the function with the decimals being the last.

 

For more information about math.modf check out: http://lua-users.org/wiki/MathLibraryTutorial

 

Edited by Kzisor

 

You would add that line of code to your master_postfn for NOIR. It would be only listening when your character's temperature changes.

 

 
 
You could leave it or change it, it's completely up to you. Leaving it based on time of day eliminates the argument about the performance issue entirely. Personally I'd base it on temperature with a clause that it only update if the temperature changes a full degrees.
inst:ListenForEvent("temperaturedelta", function(inst, data)    if math.modf(data.last) ~= math.modf(data.new) then        -- DO CHANGES HERE TO inst.components.locomotor:SetExternalSpeedMultiplier(source, key, value)    endend)

math.modf separates the decimals from the whole number. The whole number is the first value returned from the function with the decimals being the last.

 

For more information about math.modf check out: http://lua-users.org/wiki/MathLibraryTutorial

 

So I would just copy this into my Noir.lua? where do I put that like under what line area and such? What are source, key, and value should I change those to numbers? I feel like there's a coding tuitorial somewhere that I can learn how to interpret this all better. I wasn't properly taught math really so that doesn't make sense to me what it's saying or what it affects? Maybe a glossary or something. this is my first time working with coding or programming of any kind and I just feel like I'm being annoying...

@Argosa47, as stated previously it would go in your master_postfn in noir.lua. Copy/pasting the code will do nothing as I haven't set it to do anything other than try to execute code if noir's temperature changes by a full degree.

 

As far as source, key, and value those are the arguments which you will pass when you call locomot:SetExternalSpeedMultiplier function. The source is the instance of your character, the key is a string of your choosing, example "temperature_speed", the value is the amount in which you want to adjust the modifier. It can be negative or positive it cannot be 1 though as if you divide by 1 you get the same number.

 

As far as a glossary, I linked you directly to the information you need to know about lua math functions. Scroll the page for modf and you will get an example of what it does.

  • Like 1

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