[Script] SetDefaultParty (SDP)

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Magus
Posts: 56
Joined: Wed Sep 12, 2012 6:05 pm

[Script] SetDefaultParty (SDP)

Post by Magus »

EDIT - with update BETA 1.3.0 - you can now set up a default party for your dungeon, so some of this is unnecessary, but some parts may still be useful
---------------------------------
-Added a sdpInventory(ID,"Item1","Item2","Item3",...) function to add the Items you want to the champ. For now
you can't add more than 1 item per inventoryslot (I'll change this later on)

-Added sdpGetNextChamp(), this function returns the first disabled champion slot. Returns 0 if none is found.

---
There are probably a few bugs since its written fully with nodepad++ without much testing so,
posting any bugs, requests or suggestions are appreciated and will help me a lot!

I. Instruction
What is SDP?
SDP allows you to change the basics of your party(stats,equipment,level etc) without knowing lua.
I want to make it easy to use for non-scripter and also powerful for scripters.

II. Installation
1. Copy&Paste the script below to a script_entity.
2. Set the things how you want it.
3. Done :P
4. For more complex things see the script section below.

III. Configuration

sdpEnable: This boolean enables(true) or disbales(false) this whole script. This could be usefull if you want to
use this script for testing your map but don't wanna use it for the normal player.

sdpUseDefaultOnly: If enabled(true), sdp will only run if the player uses the default party. (not custom made)

sdpDefaultSats: If this is enabled(true), this script will automatically sets the stats of the
party based of the race and class. (this doesn't work fully because changing vitallity/willpower doesn't affect health and energy.
Maybe a bug?)

sdpSetChamp(ID,ENABLE,LEVEL,NAME,RACE,CLASS,GENDER,PORTRAIT)
SpoilerShow
ID - Which champion should be changed. 1=topleft, 2=topright etc. (number)
ENABLE - Enables(true) or disables(false) the champion. (boolean)
LEVEL - Sets the level of the champion. (number)
NAME - Changes the name of the Champion (string)
RACE - Changes the race: "Human", "Minotaur" or "Lizardman". (string)
CLASS - Changes the class: "Fighter", "Rogue" or "Mage". (string)
GENDER - Changes the sex: "male" or "female" (keep it lowercase!) (string)
PORTRAIT - Changes the portrait of the champion (string)

sdpStats(ID,HEALTH,ENERGY,STR,DEX,VIT,WIL,PROTECTION,EVASION,RES_FIRE,RES_COLD,RES_POISON,RES_SHOCK)
SpoilerShow
ID - Same as above. (1=topleft...)(number)
HEALTH - Sets the health of the champion. (number)
ENERGY - Sets the energy of the champion. (number)
STR - Sets the strength of the champion. (number)
... (same for the rest)

sdpEquip(ID,LEFTHAND,RIGHTHAND,HELMET,TORSO,LEG,FEET,CLOAK,NECK,GAUNTLET,BRACERS)
SpoilerShow
ID - ID of the champion. (number)
LEFTHAND - Sets the item on the left hand (string)
RIGHTHAND - Sets the item on the right hand (string)
HELMET - Sets the helm slot of the champion (string)
... (same for the rest again)
sdpInventory(ID,{Item1,Item2,Item3,...})
SpoilerShow
ID - ID of the champion. (number)
Item1 - (string)
Item2 - (string)
... (up to all backpack slots)
--- currently you can't add more than 1 item per slot (I'll change this later on)
If you don't wanna change a value use "nil" without the quotes. If you don't want to use a function
comment it with "--" (without the quotes).

IV. Script section
This script comes with a new function called "sdpChamp(champID)" which is a shorter version of "party:getChampion(champID)",
so instead of writing "party:getChampion(1):setStatMax("health",100)" you could write "sdpChamp(1):setStatMax("health",100)"
to keep your code smaller/cleaner. Everything you write here will override the settings you made above!

Now let's do some scripting!

Let's check if the first champion have the name "Hax" if yes, then change his health to 1000.
SpoilerShow

Code: Select all

	if sdpChamp(1):getName("Hax") then
		sdpChamp(1):setStatMax("health",1000)
	end
V. Code

Code: Select all

sdpEnable = true			-- Set this to false if you don't want to use sdp.
sdpUseDefaultOnly = false	-- Set this to true if you only want to change the default party (not custom).
sdpDefaultSats = false		--[[ Set this to true if the script should
							automatically set the stats(STR,INT...)
							based on race and class. ]]--
function setDefaultParty()
	
	sdpSetChamp(1,true,1,"ContarStonesKull","Human","Fighter","male",nil)
	sdpSetChamp(2,true,1,"Mork","Minotaur","Fighter","male",nil)
	sdpSetChamp(3,true,1,"Yennica Whitefeather","Human","Rogue","female",nil)
	sdpSetChamp(4,true,1,"Sancsaron","Human","Mage","male",nil)
	
	sdpStats(1, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil)
	sdpStats(2, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil)
	sdpStats(3, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil)
	sdpStats(4, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil)
	
	sdpEquip(1, nil,"torch", nil, nil, nil, nil, nil, nil, nil, nil)
	sdpEquip(2, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil)
	sdpEquip(3, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil)
	sdpEquip(4, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil)
	
	sdpInventory(1,{})
	sdpInventory(2,{})
	sdpInventory(3,{})
	sdpInventory(4,{})
	
	-- add custom party-scripts here
	
	
	
	
	-----
end

function sdpSetStatHuman(champID)
	party:getChampion(champID):setStatMax("health",60)
	party:getChampion(champID):setStatMax("energy",50)
	party:getChampion(champID):setStatMax("strength",10)
	party:getChampion(champID):setStatMax("dexterity",10)
	party:getChampion(champID):setStatMax("vitality",10)
	party:getChampion(champID):setStatMax("willpower",10)
	party:getChampion(champID):setStatMax("resist_fire",0)
	party:getChampion(champID):setStatMax("resist_cold",0)
	party:getChampion(champID):setStatMax("resist_poison",0)
	party:getChampion(champID):setStatMax("resist_shock",0)
end

function sdpSetStatMinotaur(champID)
	party:getChampion(champID):setStatMax("health",70)
	party:getChampion(champID):setStatMax("energy",42)
	party:getChampion(champID):setStatMax("strength",15)
	party:getChampion(champID):setStatMax("dexterity",6)
	party:getChampion(champID):setStatMax("vitality",14)
	party:getChampion(champID):setStatMax("willpower",7)
	party:getChampion(champID):setStatMax("resist_fire",0)
	party:getChampion(champID):setStatMax("resist_cold",8)
	party:getChampion(champID):setStatMax("resist_poison",8)
	party:getChampion(champID):setStatMax("resist_shock",0)
end

function sdpSetStatLizardman(champID)
	party:getChampion(champID):setStatMax("health",60)
	party:getChampion(champID):setStatMax("energy",47)
	party:getChampion(champID):setStatMax("strength",10)
	party:getChampion(champID):setStatMax("dexterity",12)
	party:getChampion(champID):setStatMax("vitality",10)
	party:getChampion(champID):setStatMax("willpower",9)
	party:getChampion(champID):setStatMax("resist_fire",2)
	party:getChampion(champID):setStatMax("resist_cold",0)
	party:getChampion(champID):setStatMax("resist_poison",0)
	party:getChampion(champID):setStatMax("resist_shock",2)
end

function sdpSetStatInsectoid(champID)
	party:getChampion(champID):setStatMax("health",55)
	party:getChampion(champID):setStatMax("energy",60)
	party:getChampion(champID):setStatMax("strength",8)
	party:getChampion(champID):setStatMax("dexterity",11)
	party:getChampion(champID):setStatMax("vitality",8)
	party:getChampion(champID):setStatMax("willpower",14)
	party:getChampion(champID):setStatMax("resist_fire",1)
	party:getChampion(champID):setStatMax("resist_cold",0)
	party:getChampion(champID):setStatMax("resist_poison",0)
	party:getChampion(champID):setStatMax("resist_shock",1)
end

function sdpSetChamp(champID, champAllow, champLevel, champName, champRace, champClass, champGender, champPortrait)
	if champAllow ~= true then
		party:getChampion(champID):setEnabled(champAllow)
	end
	if champName then
		party:getChampion(champID):setName(champName)
	end
	if champRace then
		party:getChampion(champID):setRace(champRace)
	end
	if champClass then
		party:getChampion(champID):setClass(champClass)
	end
	if champGender then
		party:getChampion(champID):setSex(champGender)
	end
	if champPortrait then
		party:getChampion(champID):setPortrait(champPortrait)
	end
	if sdpDefaultSats then
		if party:getChampion(champID):getRace() == "Human" then
			sdpSetStatHuman(champID)
			sdpCheckClass(champID)
		elseif party:getChampion(champID):getRace() == "Minotaur" then
			sdpSetStatMinotaur(champID)
			sdpCheckClass(champID)
		elseif party:getChampion(champID):getRace() == "Lizardman" then
			sdpSetStatLizardman(champID)
			sdpCheckClass(champID)
		else
			sdpSetStatInsectoid(champID)
			sdpCheckClass(champID)
		end
	end
	while party:getChampion(champID):getLevel() <= champLevel-1 do
		party:getChampion(champID):levelUp()
	end
end

function sdpEquip(champID, champLeftH, champRightH, champHelmet, champTorso, champLeg, champFeet, champCloak, champNeck, champGauntlet, champBracers)
	if champLeftH then
		party:getChampion(champID):insertItem(7,spawn(champLeftH))
	end
	if champRightH then
		party:getChampion(champID):insertItem(8,spawn(champRightH))
	end
	if champHelmet then
		party:getChampion(champID):insertItem(1,spawn(champHelmet))
	end
	if champTorso then
		party:getChampion(champID):insertItem(2,spawn(champTorso))
	end
	if champLeg then
		party:getChampion(champID):insertItem(3,spawn(champLeg))
	end
	if champFeet then
		party:getChampion(champID):insertItem(4,spawn(champFeet))
	end
	if champCloak then
		party:getChampion(champID):insertItem(5,spawn(champCloak))
	end
	if champNeck then
		party:getChampion(champID):insertItem(6,spawn(champNeck))
	end
	if champGauntlet then
		party:getChampion(champID):insertItem(9,spawn(champGauntlet))
	end
	if champBracers then
		party:getChampion(champID):insertItem(10,spawn(champBracers))
	end
end

function sdpStats(champID, champHealth, champEnergy, champStr, champDex, champVit, champWil, champProtection, champEvasion, champResFire, champResCold, champResPoison, champResShock)	
	if champHealth then
		party:getChampion(champID):setStatMax("health",champHealth)
	end
	if champEnergy then
		party:getChampion(champID):setStatMax("energy",champEnergy)
	end
	if champStr then
		party:getChampion(champID):setStatMax("strength",champStr)
	end
	if champDex then
		party:getChampion(champID):setStatMax("dexterity",champDex)
	end
	if champVit then
		party:getChampion(champID):setStatMax("vitality",champVit)
	end
	if champWil then
		party:getChampion(champID):setStatMax("willpower",champWil)
	end
	if champProtection then
		party:getChampion(champID):setStatMax("protection",champProtection)
	end
	if champEvasion then
		party:getChampion(champID):setStatMax("evasion",champEvasion)
	end
	if champResFiret then
		party:getChampion(champID):setStatMax("resist_fire",champResFire)
	end
	if champResCold then
		party:getChampion(champID):setStatMax("resist_cold",champResCold)
	end
	if champResPoison then
		party:getChampion(champID):setStatMax("resist_poison",champResPoison)
	end
	if champResShock then
		party:getChampion(champID):setStatMax("resist_shock",champResShock)
	end
end

function sdpInventory(champID, itemTable)
	for v,i in ipairs(itemTable) do
		party:getChampion(champID):insertItem(v+10,spawn(i))
	end
end

function sdpCheckClass(champID)
	if party:getChampion(champID):getClass() == "Mage" then
		party:getChampion(champID):modifyStatCapacity("health",-25)
	elseif party:getChampion(champID):getClass() == "Rogue" then
		party:getChampion(champID):modifyStatCapacity("health",-15)
	end
end

function sdpChamp(champID)
	return party:getChampion(champID)
end

function sdpGetNextChamp()
	for p=1,4 do
		if party:getChampion(p):getEnabled() == false then
			return p
		end
	end
	return 0
end

if sdpEnable then
	if sdpUseDefaultOnly and party:getChampion(1):getName() == "ContarStonesKull" then
		setDefaultParty()
	elseif sdpUseDefaultOnly == false then
		setDefaultParty()
	end
end
Feel free to me ask any question.
Last edited by Magus on Tue Sep 18, 2012 8:18 pm, edited 1 time in total.
User avatar
Komag
Posts: 3658
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: [Script] SetDefaultParty (SDP)

Post by Komag »

Wow, this is amazing so far! Looking forward to your finishing the parts you want to 8-)
Finished Dungeons - complete mods to play
Magus
Posts: 56
Joined: Wed Sep 12, 2012 6:05 pm

Re: [Script] SetDefaultParty (SDP)

Post by Magus »

hehe, thanks. I really hope this script helps someone.

Dunno exactly what I should add for now (don't have much time).
Right now i'm thinking about a save/load function for champions but I feel that this is missing the whole point of this script.

Anyway, time for my bed again!
User avatar
Merethif
Posts: 274
Joined: Tue Apr 24, 2012 1:58 pm
Location: Poland

Re: [Script] SetDefaultParty (SDP)

Post by Merethif »

Great script. Thanks a lot for sharing it.
Is there a way to predefine Skills and Traits with that Script as well?
User avatar
Daght
Posts: 146
Joined: Sun Apr 15, 2012 12:28 pm
Location: Italy

Re: [Script] SetDefaultParty (SDP)

Post by Daght »

I tried the script to run a single champion (ID4) and I noticed something.
Got no torch and still have a similar light source on the party, how can I set it OFF?
How can I change the picture of the character?

Thanks again.
If we do not end the war, the war will end us.
Magus
Posts: 56
Joined: Wed Sep 12, 2012 6:05 pm

Re: [Script] SetDefaultParty (SDP)

Post by Magus »

Merethif wrote:Great script. Thanks a lot for sharing it.
Is there a way to predefine Skills and Traits with that Script as well?
I'll add skills later(after work).
Dunno about traits, I don't see a way to change the default traits from a champion with lua.

Daght wrote:I tried the script to run a single champion (ID4) and I noticed something.
Got no torch and still have a similar light source on the party, how can I set it OFF?
How can I change the picture of the character?
You can only remove the default torch with "sdpChamp(1):removeItem(8)" but I can't do something about the default lightning stuff.
User avatar
Daght
Posts: 146
Joined: Sun Apr 15, 2012 12:28 pm
Location: Italy

Re: [Script] SetDefaultParty (SDP)

Post by Daght »

Magus wrote:
Merethif wrote:Great script. Thanks a lot for sharing it.
Is there a way to predefine Skills and Traits with that Script as well?
I'll add skills later(after work).
Dunno about traits, I don't see a way to change the default traits from a champion with lua.

Daght wrote:I tried the script to run a single champion (ID4) and I noticed something.
Got no torch and still have a similar light source on the party, how can I set it OFF?
How can I change the picture of the character?
You can only remove the default torch with "sdpChamp(1):removeItem(8)" but I can't do something about the default lightning stuff.
Thanks, DONE!
If we do not end the war, the war will end us.
User avatar
Starnice
Posts: 13
Joined: Thu Sep 13, 2012 7:08 pm
Contact:

Re: [Script] SetDefaultParty (SDP)

Post by Starnice »

Did you find a way to choose the traits?
User avatar
Montis
Posts: 340
Joined: Sun Apr 15, 2012 1:25 am
Location: Grimrock II 2nd playthrough (hard/oldschool)

Re: [Script] SetDefaultParty (SDP)

Post by Montis »

Starnice wrote:Did you find a way to choose the traits?
I don't think there's a (documented) way to do this. -> Feature request!
When destiny calls, the chosen have no choice.

My completed dungeon (LoG1): Hypercube
User avatar
HaunterV
Posts: 676
Joined: Mon Apr 16, 2012 9:54 pm
Location: Barrie, Ontario, Canada

Re: [Script] SetDefaultParty (SDP)

Post by HaunterV »

Montis wrote:
Starnice wrote:Did you find a way to choose the traits?
I don't think there's a (documented) way to do this. -> Feature request!

custom traits just out of reach!
I want a Butterfingers trait where you drop a wepon on a 15% chance, counterbalanced by an additional +2 to all stats except dex.
Grimrock Community 'FrankenDungeon 2012. Submit your entry now!: http://tinyurl.com/cnupr7h
SUBMIT YOUR ASSETS! Community Asset Pack (C.A.P.): http://tinyurl.com/bqvykrp
Behold! The HeroQuest Revival!: http://tinyurl.com/cu52ksc
Post Reply