Page 1 of 8

Hiring party member(s) script - SOLVED

Posted: Sun Nov 23, 2014 11:19 pm
by Drakkan
huge thanks to JKos, who invented this wonderful GUI for hiring new members. all credits to him please

download here:
https://github.com/JKos/log2doc/archive/master.zip

with it you can do following:

- define new champions to hire
- define starting items for hired champions
- replace old party members with new champions in case no free slots

Re: Huge script request - new party member(s)

Posted: Sat Nov 29, 2014 4:34 pm
by Drakkan
just up in case somebody have free Saturday evening :)

Re: Huge script request - new party member(s)

Posted: Fri Dec 05, 2014 6:59 pm
by QuintinStone
Drakkan, I might take a look at this this weekend.

Re: Huge script request - new party member(s)

Posted: Fri Dec 05, 2014 7:20 pm
by Drakkan
hm... universe would be gratefufull if you check it :) I alraedy managed to set lots of champion statistics with setting it manualy (like:

Code: Select all

party.party:getChampion(4):setPortrait("") 
party.party:getChampion(1):setClass("")
party.party:getChampion(1):setName("")
party.party:getChampion(2):setName("")
party.party:getChampion(2):setRace("")
party.party:getChampion(2):removeTrait("")
etc...
and also just simply enabling / disabling party members
party.party:getChampion(4):setEnabled(true)

however the sccript need to work with champion names and also need some other clever checks. And the most important part of course the "swapping" for new party members...
anyway keeping my fingers if you try something !

Re: Huge script request - new party member(s)

Posted: Fri Dec 05, 2014 10:06 pm
by JKos
Well here is a start so you don't have to begin from scratch:

Code: Select all

champions = {}
skills = { 
	"accuracy","athletics", "armors", "critical", "dodge", "missile_weapons",
	"throwing", "firearms", "light_weapons", "heavy_weapons", "concentration", "alchemy",
	"fire_magic","earth_magic","water_magic","air_magic" 
}

stats = {'strength','dexterity','vitality','willpower'}

conditions = {}

traits = {
	"fighter","barbarian","knight","rogue","wizard","battle_mage","alchemist","farmer","human",
	"minotaur","lizardman","insectoid","ratling","skilled","fast_learner","head_hunter","rage",
	"fast_metabolism","endure_elements","poison_immunity","chitin_armor","quick","mutation","athletic",
	"agile","healthy","strong_mind","tough","aura","aggressive","evasive","fire_resistant","cold_resistant",
	"poison_resistant","natural_armor","endurance","weapon_specialization","pack_mule","meditation",
	"two_handed_mastery","light_armor_proficiency","heavy_armor_proficiency","armor_expert","shield_expert",
	"staff_defence","improved_alchemy","bomb_expert","backstab","assassin","firearm_mastery","dual_wield",
	"improved_dual_wield","piercing_arrows","double_throw","reach","uncanny_speed","fire_mastery","air_mastery",
	"earth_mastery","water_mastery","leadership","nightstalker"
}

function storeChampion(champ)
	champions[champ:getName()] ={
		baseStats = getBaseStats(champ),
		class = champ:getClass(),
		dualClass = champ:getDualClass(),
		energy = champ:getEnergy(),
		evasion = champ:getEvasion(),
		experience = champ:getExp(),
		food = champ:getFood(),
		health = champ:getHealth(),
		level = champ:getLevel(),
		load = champ:getLoad(),
		maxEnergy = champ:getMaxEnergy(),
		maxHealth = champ:getMaxHealth(),
		maxLoad = champ:getMaxLoad(),
		name = champ:getName(),
		protection = champ:getProtection(),
		race = champ:getRace(),
		sex = champ:getSex(),
		skillLevels = getSkillLevels(champ),
		traits = getTraits(champ),
		skillPoints = champ:getSkillPoints()
	}
end

function defineChampion(def)
	champions[def.name] = def
end

function loadChampion(name,replaceChamp)
	local data = champions[name]
	setBaseStats(replaceChamp,data.baseStats) 	
	replaceChamp:setRace(data.race) 	
	replaceChamp:setSex(data.sex) 	
	replaceChamp:setClass(data.class) 	
	--replaceChamp:setCondition(name) 	
	--replaceChamp:setConditionValue(name, value) 	
	replaceChamp:setEnergy(data.energy) 	
	replaceChamp:setFood(data.food) 	
	replaceChamp:setHealth(data.health) 	
	replaceChamp:setName(data.name) 
	if data.portrait then
		replaceChamp:setPortrait(data.portrait)
	end 	
	local toTargetXp = data.experience - replaceChamp:getExp()
	replaceChamp:gainExp(toTargetXp)

	setSkillLevels(replaceChamp,data.skillLevels)
	replaceChamp:setSkillPoints(data.skillPoints)
	setTraits(replaceChamp,data.traits)	
end


function getSkillLevels(champ)
	local result = {}
	for _,skill in ipairs(skills) do
		result[skill] = champ:getSkillLevel(skill)
	end
	return result
end

function setSkillLevels(champ,champSkills)
	for _,skill in ipairs(skills) do
		local value = champSkills[skill] or 0
		local currentLevel = champ:getSkillLevel(skill)
		local trainToTarget = value - currentLevel
		champ:trainSkill(skill,trainToTarget)
	end
end

function getBaseStats(champ)
	local result = {}
	for _,stat in ipairs(stats) do
		result[stat] = champ:getBaseStat(stat)
	end
	return result
end


function setBaseStats(champ,stats)
	for stat,value in pairs(stats) do
		champ:setBaseStat(stat,value)
	end
end

function getTraits(champ)
	local result = {}
	for _,trait in ipairs(traits) do
		result[trait] = champ:hasTrait(trait)
	end
	return result
end
function setTraits(champ,champTraits)
	for _,trait in ipairs(traits) do
		if champTraits[trait] then
			champ:addTrait(trait)
		else
			champ:removeTrait(trait)
		end
	end
end
usage example:
define champion named 'Test Man'
store champion 2
replace champion 2 with 'Test Man'

Code: Select all

	local champ = {
		name = 'Test Man',
		race = 'ratling',
		class = 'farmer',
		sex='male',
		portrait='assets/textures/portraits/human_male_02.tga',
		experience=6000,
		baseStats = {
			strength=20,
			dexterity=1,
			vitality=18,
			willpower=1
		},
		skillLevels = {
			accuracy=1,
			light_weapons=4
		},
		energy=110,
		food=1000,
		health=100,
		level=4,
		skillPoints=0,
		traits={
			human=true,
		}
	}
	champions.script.defineChampion(champ) -- define new champion
	champions.script.storeChampion(party.party:getChampion(2)) --store champion 2
	champions.script.loadChampion('Test Man',party.party:getChampion(2)) -- replace champion 2 with ''Test Man'
Feel free to improve and develop it further.

Re: Huge script request - new party member(s)

Posted: Sat Dec 06, 2014 3:02 am
by QuintinStone
Nice work!

Re: Huge script request - new party member(s)

Posted: Sat Dec 06, 2014 3:58 am
by Drakkan
thats really nice, hope QuintinStone will be able to extend it a little :)

Re: Huge script request - new party member(s)

Posted: Sat Dec 06, 2014 6:25 am
by Mysterious
Hi Jkos I was wondering if you could supply a demo dungeon on how your script works it look so awesome, but my script understanding is limited so thxs in advance :)

EDIT: I sort of understand how the script works and can see how to create additional Champs for slot 2, but how do I activate the champ in the game eg: A monster that you click on becomes champ 2? I don't know how to get the new champ to activate and help please I really want to use this and I hope it comes with a GUI interface soon thxs Jkos :)

Re: Huge script request - new party member(s)

Posted: Mon Dec 08, 2014 5:36 am
by Mysterious
Sorry guys: Bump up.

Re: Huge script request - new party member(s)

Posted: Mon Dec 08, 2014 8:46 am
by Drakkan
Mysterious wrote:Hi Jkos I was wondering if you could supply a demo dungeon on how your script works it look so awesome, but my script understanding is limited so thxs in advance :)

EDIT: I sort of understand how the script works and can see how to create additional Champs for slot 2, but how do I activate the champ in the game eg: A monster that you click on becomes champ 2? I don't know how to get the new champ to activate and help please I really want to use this and I hope it comes with a GUI interface soon thxs Jkos :)
create two scripts - first script name will be -- champions -- and copy inside whole first code. then copy second code (where you define new champion) inside second script (no particular name required).
when you start the game in the editor, chosen default champion will be automatically replaced with defined champion. As I was making some tries, I found out that if you make some changes inside scripts, just reloading the dungeon does not help, you need to exit and start editor again.