Jump to content

Changing Zombies Sight/Hearing/Memory dynamically


Recommended Posts

Posted (edited)

Hello, I've made this mod: https://steamcommunity.com/sharedfiles/filedetails/?id=2888099799


And I'm trying to add this feature: Given a specific time of the day, assign a specific hearing/sight to a zombie (eventually to ALL zombies if not possible on a one-by-one basis)

I've been looking at the documentation APIs but beside the name of properties or functions, they don't really explain how to use them.


What I've found is this:





Which could work in changing the hearing and sight of all zombies I guess, which is good enough eventually.

My question would be then:


- How to I get/set this value (code example)

- Do I need to have the game/server reload the sandbox values or is it automatically happening? If the former, how do I do that (code example again)?


If there are attributes that can be set on the individual zombie level that would even be better but it's a "plus" that I'm willing to compromise with if it's not possible :)


Thank you!

Edited by theCrius
Link to comment
Share on other sites

Posted (edited)

Alright so, further exploring brought this up:


When a session start I can get the default values that for a regular zombie lore are:


Memory		2
Sight		2
Hearing		2


Now I don't care much to store those values as I read them every time the server start before any modification can be done by my mod. It's just so I can store the "default" values.

What I found weird is that if I try and retrieve the same attributes from the zombies in the active cells, I get these values:


Memory	800
Sight	2
Hearing	2


The anomaly here seems to be the "memory" value as in the SandboxVars is 2 but on the Zombie itself is 800.

Is there a relationship between the two values that I can translate in an algorithm? Are there only specific values accepted or I could use any integer between X - 800 - Y?

Edited by theCrius
Link to comment
Share on other sites

Posted (edited)

Writing my thoughts in case others look for it.


Further tests return this:


| Sadbox Value | Zombie Attr | UI Label |
| 1            | 1250        | Long     |
| 2            | 800         | Normal   |
| 3            | 500         | Short    |
| 4            | 25          | None     |
| 5            | one above   | Random   |


Imho, the best way to apply a change with the memory is doing something like this.

Image you want to change memory of a zombie from the default value (2) to long term memory (1).


local MEMORY_LONG = 1
getSandboxOptions():set('ZombieLore.Cognition', MEMORY_LONG)
getSandboxOptions():set('ZombieLore.Cognition', MEMORY_DEFAULT)


This will change momentarily the value of the sandbox variable value to what you want. Recalculate the stats for the zombie, then return them to the previous value.

You can easily make this dynamic by firs reading the current values and store it.

Edited by theCrius
Link to comment
Share on other sites

Aaaaaand, apparently that doesn't work.

Other stats work that way, I even tried the full shebang with:


getSandboxOptions():set('ZombieLore.Cognition', MEMORY_LONG)
getSandboxOptions():set('ZombieLore.Cognition', MEMORY_DEFAULT)


That should force the zombie stats to be recalculated, but nothing.

Unless I'm checking the wrong attribute.


I'm running this to verify after the change:


modData.speed = getClassFieldVal(zombie, speedType)
modData.cognition = getClassFieldVal(zombie, cognition)
modData.memory = getClassFieldVal(zombie, memory)
modData.sight = getClassFieldVal(zombie, sight)
modData.hearing = getClassFieldVal(zombie, hearing)
modData.crawling = zombie:isCrawling()

print("[RZF] Zombie ", zid, " updated with speed ", modData.speed, " cognition ", modData.cognition, " memory ", modData.memory, " sight ", modData.sight, " hearing ", modData.hearing)
    if (modData.crawling) then print("[RZF] | is crawling") end


But the memory remains always 800 (which is the default value from proper zombies) even if the other values are indeed changed instead.

Another weird thing is that cognition is always set to -1 apparently. No matter that according to the game settings it should be 1,2,3,4 and the default should be 2. But at least the mod is changing that to 1 as expected when a zombie should be updated to be "smart".


I'm stumped at the moment. If anyone have any idea, maybe I'm checking the wrong attribute?

Link to comment
Share on other sites

  • theCrius changed the title to Changing Zombies Sight/Hearing/Memory dynamically

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...