Page 1 of 1
Adding party members after the start
Posted: Fri Aug 02, 2013 2:13 am
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?
Re: Adding party members after the start
Posted: Fri Aug 02, 2013 2:24 am
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
Re: Adding party members after the start
Posted: Fri Aug 02, 2013 2:45 am
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.
Re: Adding party members after the start
Posted: Fri Aug 02, 2013 3:12 am
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
Re: Adding party members after the start
Posted: Fri Aug 02, 2013 3:15 am
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
Re: Adding party members after the start
Posted: Fri Aug 02, 2013 3:21 am
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.
Re: Adding party members after the start
Posted: Sat Aug 03, 2013 2:16 pm
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
Re: Adding party members after the start
Posted: Sat Aug 03, 2013 6:52 pm
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!
Re: Adding party members after the start
Posted: Mon Aug 05, 2013 5:41 am
by LocalFire
thank you!
Re: Adding party members after the start
Posted: Fri Aug 09, 2013 10:39 am
by Halluinoid
this is a great idea, starting with one character who then has to find the other three, like it!!
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
well whatever gamers can do to make them happy!
