Jump to content

Recommended Posts

I'm working on a mod and I'd like to be able to make this one creature have a different name chosen at random every day. Sort of like the pigmen, but have it so that the name changes every once in a while.

 

example: instance of the prefab  

day 1: Jason

day 2: George

day 3: Paul

day 4: etc

from a list of names

This is what the M­­oose Goose does. It picks M­oose or Goose.

local function rename(inst)
	inst.components.named:PickNewName()
end

inst:AddComponent("named")
inst.components.named.possiblenames = {STRINGS.NAMES["MOOSE1"], STRINGS.NAMES["MOOSE2"]}
inst.components.named:PickNewName()
inst:DoPeriodicTask(5, rename)

 

Edited by DarkXero
6 hours ago, Kzisor said:

Added the named component to the prefab, then set the name like pigmen.

But I mean, that would give the thing a name from a list of names, but the name wouldn't randomly change.

 

@DarkXero and that would allow the name to change at random?

Edited by mf99k
2 minutes ago, mf99k said:

But I mean, that would give the thing a name from a list of names, but the name wouldn't randomly change.

 

@DarkXero and that would allow the name to change at random?

yes PickNewName picks a random name from the "possiblenames".

9 minutes ago, mf99k said:

and that would allow the name to change at random?

inst:DoPeriodicTask(5, rename)

A function that picks a new name is ran every 5 seconds.

You can set it to 480, which is a day's duration.

Or you can make it like:

inst:WatchWorldState("cycles", rename)

A cycle is completed when a day is completed. (Game goes from Day 1 to Day 2)

 

1 minute ago, DarkXero said:

inst:DoPeriodicTask(5, rename)

A function that picks a new name is ran every 5 seconds.

You can set it to 480, which is a day's duration.

Or you can make it like:


inst:WatchWorldState("cycles", rename)

A cycle is completed when a day is completed. (Game goes from Day 1 to Day 2)

 

awesome, thanks

On 4/8/2016 at 11:01 AM, DarkXero said:

This is what the M­­oose Goose does. It picks M­oose or Goose.


local function rename(inst)
	inst.components.named:PickNewName()
end

inst:AddComponent("named")
inst.components.named.possiblenames = {STRINGS.NAMES["MOOSE1"], STRINGS.NAMES["MOOSE2"]}
inst.components.named:PickNewName()
inst:DoPeriodicTask(5, rename)

 

could I set up the possiblenames part of the code to have the names listed directly instead of referencing strings?

14 minutes ago, mf99k said:

could I set up the possiblenames part of the code to have the names listed directly instead of referencing strings?

Yeah, sure. possiblenames just needs a table with strings.

local my_custom_names = {
	"Jeff",
	"Bob",
	"Berethor",
	"Spasmodicus, The Third",
}

inst.components.named.possiblenames = my_custom_names

 

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