Jump to content

Random titles with profession


BudeRoy

Recommended Posts

Heya, i need some help with my LUA code here. I'am pretty newbie with the LUA, like "write some code, test it out, cry & retry until it works."

 

I have created new profession 'Soldier' and i wanted to randomly generate army title for the character.

local function soldier_start(player, square)	local profession = player:getDescriptor():getProfession();		if profession == 'soldier' then			getPlayer():getDescriptor():setForename("Sgt.");

Code above works perfectly! When i enter into game with my Soldier profession, it'll show my character name as Sgt. Porter for example.

 

But.. I want to add more titles to be randomly picked up when entering game, like Sgt. Pvt. & Cpt. so you can be example Sgt. Porter or Pvt.Porter etc. so you'll never know what your "military rank" will be, even it doesn't matter anyhow. What's the function here to make it pick one from many title options?

 

I'am officially out of ideas here after 4 hours of struggling, any help would be greatly appreciated!

Link to comment
Share on other sites

I've tackled with something like this, where I needed to have randomization. Since tables are able to hold information as numbered entries, I just had a random number generator pull out an entry based on the number generated.

 

Example: Table has 5entries, 1,2,3,4, and 5.. RNG generates 3, so I use the third entry.

 

This should do the trick:

titleTable = {"Pvt. ","Sgt. ","Cpt. "}local function GRN(argTable)	local randNumber = ZombRandBetween(1, #argTable) -- sets the maximum generated number to the size of the given table. Example: fooTable has 2 entries, so the maximum number is 2.	return argTable[randNumber]endlocal function soldier_start(player, square)	local profession = player:getDescriptor():getProfession();	if profession == 'soldier' then		getPlayer():getDescriptor():setForename( GRN(titleTable) );	endendsoldier_start(getPlayer())
Link to comment
Share on other sites

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