New modder, need help (Default party, custom class)

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
User avatar
bazuso
Posts: 15
Joined: Sat Jul 29, 2017 12:40 pm

Re: New modder, need help (Default party, custom class)

Post by bazuso »

Isaac wrote:That could work. It does not have to be separate scripts, but it shouldn't cause any problem.

Does it cause this problem in a new project? (as before, with setPortraits)
The names and races are changed to the altered ones but the portraits remain default. I put both the scripts into one entity this time.

Edit: In the connector menu of the new dungeon, I changed "setCustomPC" to "setPortrait" and this seems to work in the editor playtest right away but upon exporting the map, the portraits, names, and races all go back to default.
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: New modder, need help (Default party, custom class)

Post by Isaac »

Sometimes the editor has to be closed and restarted for certain things to take effect.


Does this script not work in a new project? (leave out the floor_trigger)

Code: Select all

function setPortraits()
   local images = {
               "minotaur_male_03",
               "minotaur_male_02",
               "human_female_05",
               "human_male_04"
               }
   for x = 1, #images do
      local champ = party.party:getChampion(x)
      local path = "assets/textures/portraits/"
      local file = images[x]..".tga"
      if champ:getEnabled() then 
         champ:setPortrait(path..file)
      end   
   end
end

function setCustomPC()
	party.party:getChampion(1):setName("test1")
	party.party:getChampion(1):setRace("minotaur")
	party.party:getChampion(1):setSex("male")
	party.party:getChampion(2):setName("test2")
	party.party:getChampion(2):setRace("minotaur")
	party.party:getChampion(2):setSex("male")
	party.party:getChampion(3):setName("test3")
	party.party:getChampion(3):setRace("human")
	party.party:getChampion(3):setSex("female")
	party.party:getChampion(4):setName("test4")
	party.party:getChampion(4):setRace("human")
	party.party:getChampion(4):setSex("male")
end

setCustomPC()
setPortraits()
User avatar
bazuso
Posts: 15
Joined: Sat Jul 29, 2017 12:40 pm

Re: New modder, need help (Default party, custom class)

Post by bazuso »

Isaac wrote:Sometimes the editor has to be closed and restarted for certain things to take effect.


Does this script not work in a new project? (leave out the floor_trigger)

Code: Select all

function setPortraits()
   local images = {
               "minotaur_male_03",
               "minotaur_male_02",
               "human_female_05",
               "human_male_04"
               }
   for x = 1, #images do
      local champ = party.party:getChampion(x)
      local path = "assets/textures/portraits/"
      local file = images[x]..".tga"
      if champ:getEnabled() then 
         champ:setPortrait(path..file)
      end   
   end
end

function setCustomPC()
	party.party:getChampion(1):setName("test1")
	party.party:getChampion(1):setRace("minotaur")
	party.party:getChampion(1):setSex("male")
	party.party:getChampion(2):setName("test2")
	party.party:getChampion(2):setRace("minotaur")
	party.party:getChampion(2):setSex("male")
	party.party:getChampion(3):setName("test3")
	party.party:getChampion(3):setRace("human")
	party.party:getChampion(3):setSex("female")
	party.party:getChampion(4):setName("test4")
	party.party:getChampion(4):setRace("human")
	party.party:getChampion(4):setSex("male")
end

setCustomPC()
setPortraits()
That does work for the names, races, and portraits, however I then tried using the custom portraits which does not work (except in the editor playtest, again).
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: New modder, need help (Default party, custom class)

Post by Isaac »

bazuso wrote: That does work for the names, races, and portraits, however I then tried using the custom portraits which does not work (except in the editor playtest, again).
This was a test script, to make sure that everything worked as expected. And it does.

For custom portraits (with this script) you would need to edit the path variable: local path = "assets/textures/portraits/"
It needs to be changed to: local path = "mod_assets/textures/portraits/"

*And of course, that's where your custom portrait images have to be; or else adjust the path to match where you put them. (I mentioned before, that all of your files must be in the mod_assets folder; or in a folder within that folder... or the editor won't export them.)

**I am nearly done with a different script that handles this (and more) automatically. I'll post it when it's complete.
User avatar
bazuso
Posts: 15
Joined: Sat Jul 29, 2017 12:40 pm

Re: New modder, need help (Default party, custom class)

Post by bazuso »

This was a test script, to make sure that everything worked as expected. And it does.

For custom portraits (with this script) you would need to edit the path variable: local path = "assets/textures/portraits/"
It needs to be changed to: local path = "mod_assets/textures/portraits/"

*And of course, that's where your custom portrait images have to be; or else adjust the path to match where you put them. (I mentioned before, that all of your files must be in the mod_assets folder; or in a folder within that folder... or the editor won't export them.)

**I am nearly done with a different script that handles this (and more) automatically. I'll post it when it's complete.
I should have mentioned I changed "assets" to "mod_assets" and it still doesn't work. However I am glad to hear you're working on a script and I have to thank you for posting in this thread for as long as you have :)
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: New modder, need help (Default party, custom class)

Post by Isaac »

This script allows for custom PCs:

Code: Select all

--Set a Custom Party:
--By Isaac

function setCustomPC()
   local function rnd(min,max) if max then return math.random(min,max) else return math.random(min) end end
   -- Character stats can optionally be set to a random value instead of fixed numbers, by using the rnd() function.
   local characters = {
                        {--PC #1 
                         enabled = true,  
                         name = "test1",
                         race = "minotaur",
                         sex  = "male",
                         class = "fighter",
                         portrait = "minotaur_male_02",
                         isCustomPortrait = false,
                         stats = {strength = rnd(15), dexterity = rnd(15), vitality = 16, willpower = rnd(15)}, --remember to account for racial Stat Bonuses!
                         traits = {"head_hunter",},
                         skills = {
                                    alchemy=0, accuracy=1, athletics=3, critical=0, 
                                    concentration=0, light_weapons=0, heavy_weapons=2, 
                                    missile_weapons=0, throwing=0, firearms=0, armors=2,
                                    earth_magic=0, water_magic=0, fire_magic=0, dodge=0,
                                    air_magic=0,
                                  },
                        },

                        {--PC #2
                         enabled = true,
                         name = "test2",
                         race = "minotaur",
                         sex  = "male",
                         class = "fighter",
                         portrait = "minotaur_male_11",
                         isCustomPortrait = true,
                         stats = {strength = 20, dexterity = rnd(6,20), vitality = rnd(15,22), willpower = rnd(20)}, 
                         traits = {"head_hunter",},
                         skills = {
                                    alchemy=0, accuracy=0, athletics=2, critical=1, 
                                    concentration=0, light_weapons=2, heavy_weapons=1, 
                                    missile_weapons=0, throwing=0, firearms=1, armors=2,
                                    earth_magic=0, water_magic=0, fire_magic=0, dodge=0,
                                    air_magic=0,
                                  },
                        },

                        {--PC #3
                         enabled = false,
                         name = "test3",
                         race = "insectoid",
                         sex  = "female",
                         class = "rogue",
                         portrait = "insectoid_female_03",
                         isCustomPortrait = false,
                         stats = {strength = rnd(16), dexterity = rnd(6,20), vitality = 16, willpower = rnd(16,20)}, 
                         traits = {},
                         skills = {
                                    alchemy=3, accuracy=3, athletics=0, critical=1, 
                                    concentration=4, light_weapons=0, heavy_weapons=0, 
                                    missile_weapons=0, throwing=0, firearms=0, armors=2,
                                    earth_magic=0, water_magic=0, fire_magic=0, dodge=1,
                                    air_magic=0,
                                  },
                        },

                        {--PC #4
                         enabled = true,
                         name = "test4",
                         race = "human",
                         sex  = "female",
                         class = "wizard",
                         portrait = "human_female_03",
                         isCustomPortrait = false,
                         stats = {strength = 20, dexterity = rnd(6,20), vitality = 16, willpower = rnd(15,20)}, 
                         traits = {},
                         skills = {
                                    alchemy=1, accuracy=3, athletics=1, critical=0, 
                                    concentration=4, light_weapons=0, heavy_weapons=0, 
                                    missile_weapons=0, throwing=0, firearms=0, armors=0,
                                    earth_magic=1, water_magic=0, fire_magic=2, dodge=1,
                                    air_magic=1,
                                  },
                        },
                     }


--**************************************************************************************
   local function setEnabledPCs()
      for x,PC in pairs(characters) do
         local champ = party.party:getChampion(x)
         champ:setEnabled(PC["enabled"])
      end   
   end   
   setEnabledPCs()
   
   local function setSkills(champ, skills)
      for k,v in pairs(skills) do
         champ:trainSkill(k,champ:getSkillLevel(k)*-1, false)
         champ:trainSkill(k,v)
      end
      champ:upgradeBaseStat("health", champ:getMaxHealth()-champ:getHealth())
      champ:upgradeBaseStat("energy", champ:getMaxEnergy()-champ:getEnergy())
      champ:setSkillPoints(0) 
   end
   local function setStats(champ, stats)
      for k,v in pairs(stats) do
         champ:setBaseStat(k,v)
      end
   end            
   for pos,PC in pairs(characters) do
      local champ = party.party:getChampion(pos)

      if champ:getEnabled() then
         champ:setRace(PC["race"])
         champ:setName(PC["name"])
         champ:setSex(PC["sex"])
         local filepath = iff(characters[pos]["isCustomPortrait"],"mod_","").."assets/textures/portraits/"..characters[pos]["portrait"]..".tga"
         champ:setPortrait(filepath)
         champ:setClass(PC["class"])
         setStats(champ, PC["stats"])
         setSkills(champ, PC["skills"])
         if #PC["traits"] > 0 then
            for x = 1, #PC["traits"] do
               champ:addTrait(characters[pos]["traits"][x])
            end   
         end  
      end   
   end
   for x=1,5 do hudPrint("") end
   delayedCall(self.go.id, .2, "fixHealth")
end

function fixHealth()
   for x = 1, 4 do
      local champ = party.party:getChampion(x)
      if champ:getEnabled() then
         champ:setHealth(champ:getMaxHealth())
         champ:setEnergy(champ:getMaxEnergy())
      end 
   end 
end 

setCustomPC() 

It's new (as of minutes ago) and as such, might have a bug or two that I haven't found, but it passes my initial tests, and seems to work just fine for me. It supports custom and default portraits, and detailed assignment of PC stats & skills.

It presently has an unwanted —feature, in that it may sound the level-up sound at load. Once I have the slightest idea how to fix that without redefining the sound during start-up, I'll see what can be done about it.

** This script has not yet been updated to support assigning inventory items.
Last edited by Isaac on Mon Jul 31, 2017 11:07 am, edited 2 times in total.
User avatar
bazuso
Posts: 15
Joined: Sat Jul 29, 2017 12:40 pm

Re: New modder, need help (Default party, custom class)

Post by bazuso »

Isaac wrote:This script allows for custom PCs:

Code: Select all

--Set a Custom Party:
--By Isaac

function setCustomPC()
   local function rnd(min,max) if max then return math.random(min,max) else return math.random(min) end end
   -- Character stats can optionally be set to a random value instead of fixed numbers, by using the rnd() function.
   local characters = {
                        {--PC #1 
                         enabled = true,  
                         name = "test1",
                         race = "minotaur",
                         sex  = "male",
                         class = "fighter",
                         portrait = "minotaur_male_02",
                         isCustomPortrait = false,
                         stats = {strength = rnd(15), dexterity = rnd(15), vitality = 16, willpower = rnd(15)}, --remember to account for racial Stat Bonuses!
                         traits = {"head_hunter",},
                         skills = {
                                    alchemy=0, accuracy=1, athletics=3, critical=0, 
                                    concentration=0, light_weapons=0, heavy_weapons=2, 
                                    missile_weapons=0, throwing=0, firearms=0, armors=2,
                                    earth_magic=0, water_magic=0, fire_magic=0, dodge=0,
                                    air_magic=0,
                                  },
                        },

                        {--PC #2
                         enabled = true,
                         name = "test2",
                         race = "minotaur",
                         sex  = "male",
                         class = "fighter",
                         portrait = "minotaur_male_11",
                         isCustomPortrait = true,
                         stats = {strength = 20, dexterity = rnd(6,20), vitality = rnd(15,22), willpower = rnd(20)}, 
                         traits = {"head_hunter",},
                         skills = {
                                    alchemy=0, accuracy=0, athletics=2, critical=1, 
                                    concentration=0, light_weapons=2, heavy_weapons=1, 
                                    missile_weapons=0, throwing=0, firearms=1, armors=2,
                                    earth_magic=0, water_magic=0, fire_magic=0, dodge=0,
                                    air_magic=0,
                                  },
                        },

                        {--PC #3
                         enabled = false,
                         name = "test3",
                         race = "insectoid",
                         sex  = "female",
                         class = "rogue",
                         portrait = "insectoid_female_03",
                         isCustomPortrait = false,
                         stats = {strength = rnd(16), dexterity = rnd(6,20), vitality = 16, willpower = rnd(16,20)}, 
                         traits = {},
                         skills = {
                                    alchemy=3, accuracy=3, athletics=0, critical=1, 
                                    concentration=4, light_weapons=0, heavy_weapons=0, 
                                    missile_weapons=0, throwing=0, firearms=0, armors=2,
                                    earth_magic=0, water_magic=0, fire_magic=0, dodge=1,
                                    air_magic=0,
                                  },
                        },

                        {--PC #4
                         enabled = true,
                         name = "test4",
                         race = "human",
                         sex  = "female",
                         class = "wizard",
                         portrait = "human_female_03",
                         isCustomPortrait = false,
                         stats = {strength = 20, dexterity = rnd(6,20), vitality = 16, willpower = rnd(15,20)}, 
                         traits = {},
                         skills = {
                                    alchemy=1, accuracy=3, athletics=1, critical=0, 
                                    concentration=4, light_weapons=0, heavy_weapons=0, 
                                    missile_weapons=0, throwing=0, firearms=0, armors=0,
                                    earth_magic=1, water_magic=0, fire_magic=2, dodge=1,
                                    air_magic=1,
                                  },
                        },
                     }


--**************************************************************************************
   local function setEnabledPCs()
      for x,PC in pairs(characters) do
         local champ = party.party:getChampion(x)
         champ:setEnabled(PC["enabled"])
      end   
   end   
   setEnabledPCs()
   
   local function setSkills(champ, skills)
      for k,v in pairs(skills) do
         champ:trainSkill(k,champ:getSkillLevel(k)*-1, false)
         champ:trainSkill(k,v)
      end
      champ:upgradeBaseStat("health", champ:getMaxHealth()-champ:getHealth())
      champ:upgradeBaseStat("energy", champ:getMaxEnergy()-champ:getEnergy())
      champ:setSkillPoints(0) 
   end
   local function setStats(champ, stats)
      for k,v in pairs(stats) do
         champ:setBaseStat(k,v)
      end
   end            
   for pos,PC in pairs(characters) do
      local champ = party.party:getChampion(pos)

      if champ:getEnabled() then
         champ:setRace(PC["race"])
         champ:setName(PC["name"])
         champ:setSex(PC["sex"])
         local filepath = iff(characters[pos]["isCustomPortrait"],"mod_","").."assets/textures/portraits/"..characters[pos]["portrait"]..".tga"
         champ:setPortrait(filepath)
         champ:setClass(PC["class"])
         setStats(champ, PC["stats"])
         setSkills(champ, PC["skills"])
         if #PC["traits"] > 0 then
            for x = 1, #PC["traits"] do
               champ:addTrait(characters[pos]["traits"][x])
            end   
         end  
      end   
   end
   for x=1,5 do hudPrint("") end
   delayedCall(self.go.id, .2, "fixHealth")
end

function fixHealth()
   for x = 1, 4 do
      local champ = party.party:getChampion(x)
      if champ:getEnabled() then
         champ:setHealth(champ:getMaxHealth())
         champ:setEnergy(champ:getMaxEnergy())
      end 
   end 
end 

setCustomPC() 

It's new (as of minutes ago) and as such, might have a bug or two that I haven't found, but it passes my initial tests, and seems to work just fine for me. It supports custom and default portraits, and detailed assignment of PC stats & skills.

It presently has an unwanted —feature, in that it may sound the level-up sound at load. Once I have the slightest idea how to fix that without redefining the sound during start-up, I'll see what can be done about it.

** This script (it just occurred to me) does not offer the option to add inventory items. I'll be updating it with that feature soon.
Thanks! It works as intended so far. However they still spawn with the default traits in addition to whatever ones I add, is there a command in the traits section I have to add to fix this?

Edit: For the time being, I'm going to use a function block to remove the default traits
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: New modder, need help (Default party, custom class)

Post by Isaac »

Classes and races automatically give traits. The definition includes the race & class—which includes the traits.

What you can do for some (but not all) of the traits, is manually remove them by name.
Put a script_entity on the map with the floor_trigger connected to it; and placed under the starting_location.

**It goes without saying, but whenever you use a floor_triggered script that alters the party like this, it's best to make it only party activated, and that it disables itself on first use.

In the script you can select a character and call the removeTrait() function for any that you wish to remove; not every trait can be removed this way.

You can experiment with this in the console, and with the traits panel open. Those that can be removed, will be erased in realtime.

*Here is a list of the traits, for reference: https://github.com/JKos/log2doc/wiki/Traits
User avatar
bazuso
Posts: 15
Joined: Sat Jul 29, 2017 12:40 pm

Re: New modder, need help (Default party, custom class)

Post by bazuso »

Isaac wrote:Classes and races automatically give traits. The definition includes the race & class—which includes the traits.

What you can do for some (but not all) of the traits, is manually remove them by name.
Put a script_entity on the map with the floor_trigger connected to it; and placed under the starting_location.

**It goes without saying, but whenever you use a floor_triggered script that alters the party like this, it's best to make it only party activated, and that it disables itself on first use.

In the script you can select a character and call the removeTrait() function for any that you wish to remove; not every trait can be removed this way.

You can experiment with this in the console, and with the traits panel open. Those that can be removed, will be erased in realtime.

*Here is a list of the traits, for reference: https://github.com/JKos/log2doc/wiki/Traits
I had done some experimentation with basic party functions earlier so I got this working easily. Thank you again for the help you've provided
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: New modder, need help (Default party, custom class)

Post by Isaac »

It's very strange... I have a finished version of the script that includes assigning inventory. It would seem to work exactly as intended, except... when it's used, the PCs can no longer attack with any item except unarmed hands; and I've no idea why —yet. :?

With the inventory feature disabled, the PCs can attack as normal, but when the script has added items to their inventory, all items in the hands cease to respond to mouse clicks; (in the editor and in the game). I'll have to puzzle it out before posting it as ready to use.

But here is the [broken!!] beta version to look at; if anyone wants to try to figure it out:
SpoilerShow

Code: Select all

 --BROKEN SCRIPT! ~~DO NOT USE~~
--Set a Custom Party: (with experimental inventory support)
--By Isaac

function setCustomPC()
   local function rnd(min,max) if max then return math.random(min,max) else return math.random(min) end end
   local characters = {
                        {--PC #1 
                         enabled = true,  
                         name = "test1",
                         race = "minotaur",
                         sex  = "male",
                         class = "farmer",
                         portrait = "minotaur_male_02",
                         isCustomPortrait = false,
                         stats = {strength = rnd(15), dexterity = rnd(15), vitality = 56, willpower = rnd(15)}, --remember to account for racial Stat Bonuses!
                         traits = {"head_hunter",},
                         skills = {
                                    alchemy=0, accuracy=1, athletics=3, critical=0, 
                                    concentration=0, light_weapons=0, heavy_weapons=2, 
                                    missile_weapons=0, throwing=0, firearms=0, armors=2,
                                    earth_magic=0, water_magic=0, fire_magic=0, dodge=0,
                                    air_magic=0,
                                  },
                         equipped = {
                                    "hand_axe", --Weapon 
                                    "", -- OffHand
                                    "peasant_cap", --Head
                                    "leather_brigandine", --Chest
                                    "", --Legs
                                    "", --Feet
                                    "", --Cloak
                                    "", --Necklace
                                    "leather_gloves", --Gloves
                                    "", --Bracers
                                    "fire_bomb", --Weapon2
                                    "", --Offhand2
                                    },
                         Backpack = {"dagger", "pitroot_bread","dagger", "pitroot_bread","dagger", "pitroot_bread",
                                                "dagger", "pitroot_bread","dagger", "pitroot_bread","dagger", "pitroot_bread",
                                                "dagger", "pitroot_bread","dagger", "pitroot_bread","dagger", "pitroot_bread",
                                                "dagger", "potion_healing",}, -- 20 comma separated items max         
                        },

                        {--PC #2
                         enabled = true,
                         name = "test2",
                         race = "minotaur",
                         sex  = "male",
                         class = "fighter",
                         portrait = "minotaur_male_11",
                         isCustomPortrait = true,
                         stats = {strength = 20, dexterity = rnd(6,20), vitality = rnd(15,22), willpower = rnd(20)}, 
                         traits = {"head_hunter",},
                         skills = {
                                    alchemy=0, accuracy=0, athletics=2, critical=1, 
                                    concentration=0, light_weapons=2, heavy_weapons=1, 
                                    missile_weapons=0, throwing=0, firearms=1, armors=2,
                                    earth_magic=0, water_magic=0, fire_magic=0, dodge=0,
                                    air_magic=0,
                                  },
                         equipped = {
                                    "dagger", --Weapon 
                                    "", -- OffHand
                                    "peasant_cap", --Head
                                    "", --Chest
                                    "", --Legs
                                    "", --Feet
                                    "", --Cloak
                                    "", --Necklace
                                    "", --Gloves
                                    "", --Bracers
                                    "", --Weapon2
                                    "", --Offhand2
                                    },
                         Backpack = {"dagger", "pitroot_bread", "potion_healing",},-- 20 comma separated items max          
                        },

                        {--PC #3
                         enabled = true,
                         name = "test3",
                         race = "insectoid",
                         sex  = "female",
                         class = "rogue",
                         portrait = "insectoid_female_03",
                         isCustomPortrait = false,
                         stats = {strength = rnd(16), dexterity = rnd(6,20), vitality = 16, willpower = rnd(16,20)}, 
                         traits = {},
                         skills = {
                                    alchemy=3, accuracy=3, athletics=0, critical=1, 
                                    concentration=4, light_weapons=0, heavy_weapons=0, 
                                    missile_weapons=0, throwing=0, firearms=0, armors=2,
                                    earth_magic=0, water_magic=0, fire_magic=0, dodge=1,
                                    air_magic=0,
                                  },
                         equipped = {
                                    "dagger", --Weapon 
                                    "", -- OffHand
                                    "peasant_cap", --Head
                                    "", --Chest
                                    "", --Legs
                                    "", --Feet
                                    "", --Cloak
                                    "", --Necklace
                                    "", --Gloves
                                    "", --Bracers
                                    "", --Weapon2
                                    "", --Offhand2
                                    },
                         Backpack = {"dagger", "pitroot_bread", "potion_healing",},-- 20 comma separated items max          
                        },

                        {--PC #4
                         enabled = true,
                         name = "test4",
                         race = "human",
                         sex  = "female",
                         class = "wizard",
                         portrait = "human_female_03",
                         isCustomPortrait = false,
                         stats = {strength = 20, dexterity = rnd(6,20), vitality = 16, willpower = rnd(15,20)}, 
                         traits = {},
                         skills = {
                                    alchemy=1, accuracy=3, athletics=1, critical=0, 
                                    concentration=4, light_weapons=0, heavy_weapons=0, 
                                    missile_weapons=0, throwing=0, firearms=0, armors=0,
                                    earth_magic=1, water_magic=0, fire_magic=2, dodge=1,
                                    air_magic=1,
                                  },
                         equipped = {
                                    "dagger", --Weapon 
                                    "", -- OffHand
                                    "peasant_cap", --Head
                                    "", --Chest
                                    "", --Legs
                                    "", --Feet
                                    "", --Cloak
                                    "", --Necklace
                                    "", --Gloves
                                    "", --Bracers
                                    "", --Weapon2
                                    "", --Offhand2
                                    },
                         Backpack = {"dagger", "pitroot_bread", "potion_healing",},-- 20 comma separated items max          
                        },
                     }
                        
--BROKEN SCRIPT! ~~DO NOT USE~~
--**************************************************************************************
   local function setEnabledPCs()
      for x,PC in pairs(characters) do
         local champ = party.party:getChampion(x)
         champ:setEnabled(PC["enabled"])
      end   
   end   
   setEnabledPCs()

   local function setSkills(champ, skills)
      for k,v in pairs(skills) do
         champ:trainSkill(k,champ:getSkillLevel(k)*-1, false)
         champ:trainSkill(k,v)
      end
      champ:upgradeBaseStat("health", champ:getMaxHealth()-champ:getHealth())
      champ:upgradeBaseStat("energy", champ:getMaxEnergy()-champ:getEnergy())
      champ:setSkillPoints(0) 
   end
   local function setStats(champ, stats)
      for k,v in pairs(stats) do
         champ:setBaseStat(k,v)
      end
   end            
   for pos,PC in pairs(characters) do
      local champ = party.party:getChampion(pos)

      if champ:getEnabled() then
         champ:setRace(PC["race"])
         champ:setName(PC["name"])
         champ:setSex(PC["sex"])
         local filepath = iff(characters[pos]["isCustomPortrait"],"mod_","").."assets/textures/portraits/"..characters[pos]["portrait"]..".tga"
         champ:setPortrait(filepath)
         champ:setClass(PC["class"])
         setStats(champ, PC["stats"])
         setSkills(champ, PC["skills"])
         if #PC["traits"] > 0 then
            for x = 1, #PC["traits"] do
               champ:addTrait(characters[pos]["traits"][x])
            end   
         end
--**********************************************[ Inventory feature; reads the PC's equipped & Backpack tables]***************** 
--It works, but somehow causes a problem with the PCs not being able to use items/weapons for melee attacks.   
         for x = 1,12 do                              --The twelve equipped item slots
            if #PC["equipped"][x] > 0 then    --IF Not an empty string—process it
               champ:insertItem(x,spawn(PC["equipped"][x]).item)  --Spawn the item in the specified item slot
            end
         end

         if #PC["Backpack"] then   
            for x = 1, #PC["Backpack"] do      --The (up to) twenty inventory slots
                 champ:insertItem(x+12,spawn(PC["Backpack"][x]).item)   --Spawn the item in the specified item slot (#13-20)
            end
         end 
 --**********************************************[ Inventory feature; reads the PC's equipped & Backpack tables]*****************     
      end   
   end
   for x=1,5 do hudPrint("") end
   delayedCall(self.go.id, .2, "fixHealth")
end

function fixHealth()
   for x = 1, 4 do
      local champ = party.party:getChampion(x)
      if champ:getEnabled() then
         champ:setHealth(champ:getMaxHealth())
         champ:setEnergy(champ:getMaxEnergy())
      end 
   end 
end 

setCustomPC() 
--BROKEN SCRIPT! ~~DO NOT USE~~
Post Reply