Adding party members after the start

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
User avatar
LocalFire
Posts: 261
Joined: Thu Feb 21, 2013 1:16 am
Location: Auckland, New Zealand

Adding party members after the start

Post by LocalFire »

So my new dungeon is going to have you start as a single player and give you the chance to find and release 3 other prisoners to join you if you wish (and if you can find them)

I already have the script in place to add the new members to the party and it works but it needs to add them to an empty slot and if you rearrange the party it either won't add or will overwrite one of the others, so far I can get it so that it will work but by adding the same member to all empty slots and then replacing the extras with the new members as you go, as you can imagine thats not optimal

so how can I check for and then add to the empty slots?
My Dungeons
Paths of the Earth: viewtopic.php?f=14&t=5136
Beneath the Sands: viewtopic.php?f=14&t=5216
Videos: viewtopic.php?f=11&t=5443
User avatar
LocalFire
Posts: 261
Joined: Thu Feb 21, 2013 1:16 am
Location: Auckland, New Zealand

Re: Adding party members after the start

Post by LocalFire »

to clarify I can get it to add just one copy of each, but rearranging the party will screw it up, the adding multiple copies is just to get around that but I'd like to get rid o that if I can
My Dungeons
Paths of the Earth: viewtopic.php?f=14&t=5136
Beneath the Sands: viewtopic.php?f=14&t=5216
Videos: viewtopic.php?f=11&t=5443
User avatar
Dr.Disaster
Posts: 2876
Joined: Wed Aug 15, 2012 11:48 am

Re: Adding party members after the start

Post by Dr.Disaster »

LocalFire wrote:so how can I check for and then add to the empty slots?
I'd check if the character in a slot is enabled or disabled with party:getChampion(i):getEnabled() with (i) being the slot number 1 to 4.
User avatar
LocalFire
Posts: 261
Joined: Thu Feb 21, 2013 1:16 am
Location: Auckland, New Zealand

Re: Adding party members after the start

Post by LocalFire »

ok so this is what I'm using now

function Merin()


if party:getChampion(2):getEnabled() == false then

i=2 do party:getChampion(2):setEnabled(true)
party:getChampion(2):setRace("Human")
party:getChampion(2):setName("Merin Uskor")
party:getChampion(2):setClass("Fighter")
party:getChampion(2):setPortrait("mod_assets/Spearman.tga")
party:getChampion(2): trainSkill("swords",10,true)
party:getChampion(2): trainSkill("athletics",5,true)
party:getChampion(2): trainSkill("armors",5,true)

end
end
end

so that prevents adding to a slot thats occupied, I guess now I'll try adding else add to 3 and 4 and see how it goes thanks
My Dungeons
Paths of the Earth: viewtopic.php?f=14&t=5136
Beneath the Sands: viewtopic.php?f=14&t=5216
Videos: viewtopic.php?f=11&t=5443
User avatar
LocalFire
Posts: 261
Joined: Thu Feb 21, 2013 1:16 am
Location: Auckland, New Zealand

Re: Adding party members after the start

Post by LocalFire »

Excellent

Code: Select all

function Merin()


 
   
 if party:getChampion(2):getEnabled()==false then
         
 i=2 do party:getChampion(2):setEnabled(true)
party:getChampion(2):setRace("Human")
party:getChampion(2):setName("Merin Uskor")
party:getChampion(2):setClass("Fighter")
party:getChampion(2):setPortrait("mod_assets/Spearman.tga")
party:getChampion(2): trainSkill("swords",10,true)
party:getChampion(2): trainSkill("athletics",5,true)
party:getChampion(2): trainSkill("armors",5,true)

end
else

if party:getChampion(3):getEnabled()==false then
         
 i=2 do party:getChampion(3):setEnabled(true)
party:getChampion(3):setRace("Human")
party:getChampion(3):setName("Merin Uskor")
party:getChampion(3):setClass("Fighter")
party:getChampion(3):setPortrait("mod_assets/Spearman.tga")
party:getChampion(3): trainSkill("swords",10,true)
party:getChampion(3): trainSkill("athletics",5,true)
party:getChampion(3): trainSkill("armors",5,true)


end
end
end
end
so that works just got to add conditions to add to slots 1 and 4 if they are empty
My Dungeons
Paths of the Earth: viewtopic.php?f=14&t=5136
Beneath the Sands: viewtopic.php?f=14&t=5216
Videos: viewtopic.php?f=11&t=5443
Ryeath_Greystalk
Posts: 366
Joined: Tue Jan 15, 2013 3:26 am
Location: Oregon

Re: Adding party members after the start

Post by Ryeath_Greystalk »

I didn't look at your script but I can tell you for sure that if you have situations where moving characters causes problems then you will want to reference them by ordinal number, not by party slot.

I ran into that issue on my mod.

Here is a sample of code I would call whenever I needed to get a characters name.

Code: Select all

-- Ordinal Test Champion 1

function championOneName()

	local name1
	
	for x = 1,4 do
		if party:getChampion(x):getOrdinal() == 1 then
			name1 = party:getChampion(x):getName()
			break
		end
	end
	
	return name1
		
end

-- Ordinal Test Champion 2

function championTwoName()

	local name2
	
	for x = 1,4 do
		if party:getChampion(x):getOrdinal() == 2 then
			name2 = party:getChampion(x):getName()
			break
		end
	end
	
	return name2
		
end

-- Ordinal Test Champion 3

function championThreeName()

	local name3
	
	for x = 1,4 do
		if party:getChampion(x):getOrdinal() == 3 then
			name3 = party:getChampion(x):getName()
			break
		end
	end
	
	return name3
		
end

-- Ordinal Test Champion 4

function championFourName()

	local name4
	
	for x = 1,4 do
		if party:getChampion(x):getOrdinal() == 4 then
			name4 = party:getChampion(x):getName()
			break
		end
	end
	
	return name4
		
end
This way if I wanted the player originally in slot one, the code would find them, no mater what slot they currently resided in.

Don't know if this helps you or not, just throwing it out there.
User avatar
LocalFire
Posts: 261
Joined: Thu Feb 21, 2013 1:16 am
Location: Auckland, New Zealand

Re: Adding party members after the start

Post by LocalFire »

Thanks, that could prove useful

Right now I'm just adding a new set of party members after the start and want them to add into an empty slot, but as things grow this could be very helpful
My Dungeons
Paths of the Earth: viewtopic.php?f=14&t=5136
Beneath the Sands: viewtopic.php?f=14&t=5216
Videos: viewtopic.php?f=11&t=5443
User avatar
JohnWordsworth
Posts: 1397
Joined: Fri Sep 14, 2012 4:19 pm
Location: Devon, United Kingdom
Contact:

Re: Adding party members after the start

Post by JohnWordsworth »

I would start by creating a few helper functions that you can use throughout your script / scripts to make your code a little tidier. But putting some of the for loop logic into their own functions, you can just call these functions instead of having to duplicate these loops wherever you want this functionality.

I normally put all of these sort of 'utility' functions in their own script entity. If you put them into a script entity called 'utils' say, then you can easily call them from anywhere in the rest of your project. So, I will assume that you put this code into it's own script entity (anywhere in your dungeon) called 'utils'.

Code: Select all

-- Returns the index of the first empty character slot, or 0 if there are no empty slots left.
function firstEmptyCharacterIndex() 
  for i=1,4 do
    if ( party:getChampion(i):isEnabled() == false ) then
      return i;
    end
  end

  return 0
end

-- Returns the champion object with the given ordinal, or nil if no champion exists with that ordinal.
function championWithOrdinal(ordinal)
  for i=1,4 do 
    if ( party:getChampion(i):getOrdinal() == ordinal ) then
      return party:getChampion(i);
    end
  end
 
  return nil;
end

-- Returns the name of the champion at the given ordinal, or nil if the ordinal is invalid.
function championNameByOrdinal(ordinal)
  local champion = championWithOrdinal(ordinal);
  
  if ( champion == nil ) then
    return nil;
  end

  return champion:getName();
end
You can then use these functions as follows;

Code: Select all

function createCharacterInFirstEmptySlot()
  local emptyIndex = utils.firstEmptyCharacterIndex();

  if ( emptyIndex < 1 ) then 
    print("No empty slots available!");
    return;
  end

  local champion = party:getChampion(emptyIndex);
  champion:setEnabled(true);
  champion:setName("Meryll");
  ...
end

function printMainCharacterName()
  print(utils.championNameByOrdinal(1));
end
I hope that makes sense. Feel free to ask any questions if I've done something stupid. Also, it's untested - so there might be a syntax error or two in there for good luck!
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
User avatar
LocalFire
Posts: 261
Joined: Thu Feb 21, 2013 1:16 am
Location: Auckland, New Zealand

Re: Adding party members after the start

Post by LocalFire »

thank you!
My Dungeons
Paths of the Earth: viewtopic.php?f=14&t=5136
Beneath the Sands: viewtopic.php?f=14&t=5216
Videos: viewtopic.php?f=11&t=5443
User avatar
Halluinoid
Posts: 165
Joined: Tue Apr 02, 2013 7:08 pm
Contact:

Re: Adding party members after the start

Post by Halluinoid »

this is a great idea, starting with one character who then has to find the other three, like it!! :D

I notice that many people like to "import" their veteran team to the MOD Custom Dungeon but surely the author has created the Custom Dungeon with just a new default party in mind :o

well whatever gamers can do to make them happy! ;)
Post Reply