SCRIPTING HELP NEEDED

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
User avatar
WaspUK1966
Posts: 135
Joined: Sat Aug 09, 2014 9:17 am

SCRIPTING HELP NEEDED

Post by WaspUK1966 » Mon Apr 27, 2015 4:20 pm

Hope someone can help me!

In the game that I am coding, you start off as one champion (champion1). The others champions are disabled. Later on, you enable champion 4. So far so good. Both show, and you can move them around into different slots etc as you play. Further on in the game, champions 2 and 3 are enabled. This is where I hit a problem. If the previous champions (1 and 4) are still in their default slots , then all the champions appear. Which is what I want. But, if any of the previous champions happen to occupy the slot for either champion 2 or 3 at the time that they are enabled, then the newly enabled champion doesn't appear. I presume this is because its default slot is already taken up by another champion. How can I get around this?
Any help greatly appreciated as always

George

Glew
Posts: 64
Joined: Sat Dec 21, 2013 7:57 pm

Re: SCRIPTING HELP NEEDED

Post by Glew » Mon Apr 27, 2015 10:27 pm

I've never done this kind of script so I don't really know what is going on. But maybe a cheap workaround could be to swap the enabled champions back to their slots before enabling the new party member.
Something with Party:getChampion(slot) and Party:swapChampions(slot1, slot2)
But hopefully someone more knowledgeable will turn up and share the solution.

In the meanwhile maybe this topic will be useful: viewtopic.php?f=14&t=3368&p=34000&hilit ... ion#p34000

User avatar
Isaac
Posts: 2981
Joined: Fri Mar 02, 2012 10:02 pm

Re: SCRIPTING HELP NEEDED

Post by Isaac » Tue Apr 28, 2015 7:24 pm

Champions are numbered by whatever slot they happen to occupy at the time. party:getChampion(1) refers to whichever champion is in slot 1. If that champion is moved, they are not Champion(1) anymore.

Champions also have an ordinal number that does not change. A champion that started in slot 3 will have 3 as their ordinal number for the whole game; even when jostled around from slot to slot.

It's possible to write a function that looks through all slots for a name or ordinal, and enable the slot where you find them.

Code: Select all

function wakeUpChampion(self, target, bool)
	if bool == nil then
	 bool = true
	end
	for x = 1,4 do
		local champ =  party:getChampion(x)
		if champ:getOrdinal() == target then
			champ:setEnabled(bool)
		end
	end
end
This function checks all champions for a given ordinal (where they started when the game first began). It then enables them ~wherever it finds them. It also has the option to include 'false' as the last argument; which disables whatever slot they are in.

Usage: ~your script name~:wakeUpChampion(3) , or :wakeUpChampion(3, false)

This function could be altered to accept the PC's name if you like:
Change this line:

Code: Select all

if champ:getOrdinal() == target then
to this:

Code: Select all

if champ:getName() == target then

and the usage becomes: :wakeUpChampion("Sancsaron") , or :wakeUpChampion("Sancsaron", false)

Post Reply