Jump to content

Recommended Posts

@Eir
 
You will need to add the talker component  to the prefab, and some ChattyNode behaviours to the brain of the prefab.

You can use the AddPrefabPostInit to modify the prefab

local function prefab_postinit(inst)    -- Modify prefab    inst:AddComponent("talker")endAddPrefabPostInit("prefab_name", prefab_postinit)

And AddBrainPostInit to modify the prefab's brain.

local function prefab_brain_postinit(inst)    -- Modify brainendAddBrainPostInit("prefab_brain_name", prefab_brain_postinit)

See this mod for prefab and brain modification examples.
 
 
Locations of relevant lua files.

  • Pigman prefab - (..\scripts\prefabs\pigman.lua)
  • Pig brain - (..\scripts\brains\pigbrain.lua)
  • Talker component - (..\scripts\components\talker.lua)
  • ChattyNode behaviour - (..\scripts\behaviours\chattynode.lua)
Edited by Blueberrys

 

@Eir

 

You will need to add the talker component  to the prefab, and some ChattyNode behaviours to the brain of the prefab.

You can use the AddPrefabPostInit to modify the prefab

local function prefab_postinit(inst)    -- Modify prefab    inst:AddComponent("talker")endAddPrefabPostInit("prefab_name", prefab_postinit)

And AddBrainPostInit to modify the prefab's brain.

local function prefab_brain_postinit(inst)    -- Modify brainendAddBrainPostInit("prefab_brain_name", prefab_brain_postinit)

See this mod for prefab and brain modification examples.

 

 

Locations of relevant lua files.

  • Pigman prefab - (..\scripts\prefabs\pigman.lua)
  • Pig brain - (..\scripts\brains\pigbrain.lua)
  • Talker component - (..\scripts\components\talker.lua)
  • ChattyNode behaviour - (..\scripts\behaviours\chattynode.lua)

 

 

Thanks for helping me! Just one more thing: I can't figure out where to put the quotes I want them to say. In the local function prefab_brain_postinit(inst)?

@Eir, err. That isn't the full code, just to be clear. It's an example on how you can get started on making the whole thing.

See the function PigBrain:OnStart() in pigbrain.lua, it has these things called "ChattyNode". Notice that they are getting their second parameter from the global STRINGS variable.

Ex,

ChattyNode(self.inst, STRINGS.PIG_TALK_FIND_MEAT, ...

You'll need to define your own ChattyNodes and inject them into the brain of the prefab you want. See the brainpostinit portion of the api examples mod (in modmain.lua) I linked for an example on how to do something like this.

Then, when you have your ChattyNodes set up to inject in the brain, set their second parameter to something like,

STRINGS.YOURPREFAB_TALK_ATTACK

And define that near the top of your modmain.lua as so,

STRINGS.YOURPREFAB_TALK_ATTACK = {"I'm gonna attack!", "Charge!", "Die foul beast!"}

If set up correctly, your prefab will randomly use one of these strings when performing the corresponding action.

 

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