Complicated NPC shenanigans for script

Ask and answer questions about making games and related topics. Unrelated topics go in that other forum.

Moderators: marionline, SDHawk

Post Reply
User avatar
guo
Metal Slime
Posts: 749
Joined: Fri Dec 04, 2009 9:12 pm

Complicated NPC shenanigans for script

Post by guo »

Bothering ya'll again with another scripting question. Thanks for your patience and help:

I have scripted a lengthy cutscene/series of battles. I'll give a basic rundown of what I want to happen, and then the problems I've discovered.

The player enters an area, several npcs (ie copies of the same npc reference) move to the player and trigger a battle. After the battle, the npcs are removed, a new set spawn at an entryway, move in and repeat.

The problem I am having is when it comes to NPC references. Basically, I use one NPC multiple times. I have set variables for each copy of the NPC so that I can easily manipulate them for movement. What I'm guessing happens, however, is that when I use destroy npc to delete some of them, and create npc to create the next "wave" , that the NPC references aren't being reset and are instead assigning new id numbers to the NPCs being created. Does that make sense?

Here is the script (warning, huge):

Code: Select all

plotscript, ghulfight, begin

#these variables are to make moving the NPCs easier
	variable (ghul1, ghul2, ghul3, ghul4, ghul5, ghul6, ghul7, ghul8, ogre, talid1, talid2, talid3, talid4, zosimus, i)
	ghul1 := NPC reference(3,0)
	ghul2 := NPC reference(3,1)
	ghul3 := NPC reference(3,2)
	ghul4 := NPC reference(3,3)
	ghul5 := NPC reference(3,4)
	ghul6 := NPC reference(3,5)
	ghul7 := NPC reference(3,6)
	ghul8 := NPC reference(3,7)

	ogre := NPC reference (6,0)
	talid1 := NPC reference (7,0)
	talid2 := NPC reference (7,1)
	talid3 := NPC reference (7,2)
	talid4 := NPC reference (7,3)
	zosimus := NPC reference (8,0)
	
#DON'T WORRY ABOUT THIS STUFF, WORKS FINE
	suspend player
	show text box (452)
	wait for text box
	walk hero to x ( me, 8 )
	wait for hero
	walk hero (me, up, 4)
	wait for hero
	suspend caterpillar
	walk hero (find hero (hero:Lint), right, 1)
	wait for hero (find hero (hero:Lint))
	walk hero (find hero (hero:Lint), up, 1)
	wait for hero (find hero (hero:Lint))
	focus camera ( 8, 15, 2 )
	show text box (453)
	wait for text box

#moving the ghuls into combat - AGAIN, THIS WORKS FINE SO FAR, AS GHULS1-4 ARE ALREADY PRESENT ON THE MAP
	walk npc (ghul1, down, 2)
	walk npc (ghul2, down, 2)
	walk npc (ghul3, down, 7)
	walk npc (ghul4, down, 7)
	wait for npc (ghul1)
	wait for npc (ghul2)
	walk npc (ghul1, left, 1)
	walk npc (ghul2, right, 1)
	wait for npc (ghul1)
	wait for npc (ghul2)
	walk npc (ghul1, down, 3)
	walk npc (ghul2, down, 3)
	wait for npc (ghul1)
	wait for npc (ghul2)
	wait for npc (ghul3)
	wait for npc (ghul4)
	walk npc (ghul1, right, 1)
	walk npc (ghul2, left, 1)
	walk npc (ghul3, right, 3)
	walk npc (ghul4, left, 3)
	wait for npc (ghul1)
	wait for npc (ghul2)
	set npc direction (ghul1, down)
	set npc direction (ghul2, down)
	wait for npc (ghul3)
	wait for npc (ghul4)
	set npc direction (ghul3, up)
	set npc direction (ghul4, up)

#screen fades out so npcs can be removed smoothly & zoticus npc created, battle is fought - EVERYTHING WORKING OK SO FAR
	fade screen out
	camera follows hero
	set tag ( tag: ath_frontgate_MAIN, 1)
	destroy NPC (ghul1)
	destroy NPC (ghul2)
	destroy NPC (ghul3)
	destroy NPC (ghul4)
	create NPC (5,8,27,up)
	fight formation (24)
	fade screen in

#zoticus (NPC 5) approaches the player,  heroes move to gate, next wave of ghuls attack - HERE IS WHERE THE TROUBLES START. 
	walk npc (5, up, 7)
	wait for npc (5)
	set hero direction (me, down)
	set hero direction (find hero (hero:Lint), down)
	wait (8)
	show text box (455)
	walk hero (me, up, 1)
	walk hero (find hero (hero:Lint), up, 1)
	wait for hero (me)
	wait for hero (find hero (hero:Lint))
	walk hero (me, left, 1)
	walk hero (find hero (hero:Lint), right, 1)
	wait for hero (me)
	wait for hero (find hero (hero:Lint))
	walk npc (zoticus, up, 2)
	walk hero (me, up, 3)
	walk hero (find hero (hero:Lint), up, 3)
	wait for hero (me)
	wait for hero (find hero (hero:Lint))
	walk hero (me, right, 1)
	walk hero (find hero (hero:Lint), left, 1)
	walk npc (zoticus, left, 1)
	wait for hero (me)
	wait for hero (find hero (hero:Lint))
	walk hero (me, up, 1)
	walk hero (find hero (hero:Lint), up, 1)
	walk npc (zoticus, up, 3)
	wait for npc (zoticus)
	walk npc (zoticus, right, 1)
	wait for npc (zoticus)
	set npc direction (zoticus, down)
	wait (8)
	show text box (456)
	wait for text box
	create npc (3, 8, 11)
	create npc (3, 9, 11)
	walk npc (ghul1, down, 1)
	walk npc (ghul2, down, 1)
	wait for npc (ghul1)
	wait for npc (ghul2)
	create npc (3, 8, 11)
	create npc (3, 9, 11)	
	walk npc (ghul1, down, 1)
	walk npc (ghul2, down, 1)
	wait for npc (ghul1)
	wait for npc (ghul2)
	walk npc (ghul3, down, 1)
	walk npc (ghul4, down, 1)
	walk npc (ghul1, left, 1)
	walk npc (ghul2, right, 1)
	wait for npc (ghul1)
	wait for npc (ghul2)
	wait for npc (ghul3)
	wait for npc (ghul4)
	walk npc (ghul3, down, 1)
	walk npc (ghul4, down, 1)
	set npc direction (ghul1, down)
	set npc direction (ghul2, down)
	wait for npc (ghul3)
	wait for npc (ghul4)
	wait (8)
	fight formation (25)	
	
#another text box, another wave

	create npc (3, 8, 11)
	create npc (3, 9, 11)	
	walk npc (ghul5, down, 1)
	walk npc (ghul6, down, 1)
	wait for npc (ghul5)
	wait for npc (ghul6)
	create npc (3, 8, 11)
	create npc (3, 9, 11)	
	wait (8)
	show text box (458)
	wait for text box
	fade screen out
	fight formation (26)

#wipe middle ghuls, spawn ogre, walk ogre, ZOSIMUS arrives 
	destroy npc (ghul8)
	destroy npc (ghul7)
	destroy npc (ghul6)
	destroy npc (ghul5)
	destroy npc (ghul4)
	destroy npc (ghul3)
	fade screen in
	show text box (460)
	wait for text box
	fade screen out
	create npc (6, 9, 11)
	wait (1)
	fade screen in
	wait (8)
	walk npc (ogre, down, 1)
	wait for npc (ogre)
	walk hero (me, down, 1) 
	set hero direction (me, up) 
	walk hero (find hero (hero:Lint), down, 1)
	set hero direction (find hero (hero:Lint), up)
	wait for hero (me) 
	wait for hero (find hero (hero:Lint))
	fade screen out (32, 0, 50)
	create npc (7, 7, 22)
	create npc (7, 7, 23)
	create npc (7, 7, 24)
	create npc (7, 7, 25)
	create npc (8, 10, 15)
	wait (1)
	fade screen in
	show text box (462)
	wait for text box

#talid are created, run to position - final battle with ogre - I'M GUESSING I'M GOING TO HAVE ISSUES WITH THE "TALID" NPCS SIMILAR TO THE GHULS
	walk npc (talid1, up, 2)
	walk npc (talid2, up, 2)
	walk npc (talid3, up, 2)
	walk npc (talid4, up, 2)
	wait for npc (talid1)
	walk npc (talid1, left, 1)
	walk npc (talid4, right, 1)
	wait for npc (talid1)
	walk npc (talid1, left, 1)
	walk npc (talid2, left, 1)
	walk npc (talid3, right, 1)
	walk npc (talid4, right, 1)
	wait for npc (talid1)
	walk npc (talid1, up, 1)
	walk npc (talid4, up, 1)
	wait for npc (talid1)
	walk npc (talid2, left, 1)
	walk npc (talid3, right, 1)
	wait for npc (talid2)
	walk npc (talid1, up, 6)
	walk npc (talid2, up, 6)
	walk npc (talid3, up, 6)
	walk npc (talid4, up, 6)
	wait for npc (talid1)
	walk npc (talid1, right, 1)
	walk npc (talid4, left, 1)
	wait for npc (talid1)
	walk npc (talid2, up, 1)
	walk npc (talid3, up, 1)
	wait for npc (talid2)
	set npc direction (talid2, right)
	set npc direction (talid3, left)
	wait (2)
	fade screen out
	fight formation (27)
	destroy npc (ghul2)
	destroy npc (ghul1)
	destroy npc (ogre)
	wait (1)
	fade screen in
	for(i,1,32,1),do,(
		pan camera(random(0,3),1,random(1,5))
		wait(1)
	)
	camera follows hero
	fade screen out (63, 63, 63)
	set tag ( tag: ath_frontgate_MAIN, 0)
	teleport to map (19, 8, 15)
	resume player
	resume caterpillar
	fade screen in

end
	
Note: The NPCs have to be moved separately as in most cases they are moving around obstacles, each other etc.

Many kind regards and thanks for your time.

-Guo
Last edited by guo on Sun Dec 04, 2016 8:32 am, edited 1 time in total.
vvight.wordpress.com
User avatar
Gizmog
Metal King Slime
Posts: 2622
Joined: Tue Feb 19, 2008 5:41 am

Post by Gizmog »

CreateNPC returns a reference to the NPC that it just created. So you could do like

Code: Select all

variable (NewGuy1,NewGuy2,NewGuy3)
NewGuy1 := CreateNPC (Whatever)
WalkNPC (NewGuy1,1,1,North) 
and maybe avoid some of the trouble?
User avatar
guo
Metal Slime
Posts: 749
Joined: Fri Dec 04, 2009 9:12 pm

Post by guo »

I'm trying to wrap my feeble brain around this one.

So if newguy1 is a variable, and that variable := create npc (#, x , y) , does that mean that to create that NPC I just have to use the command "newguy1" in the script? And then when I use walknpc (newguy1, x, y, up) it will move the npc thats there rather than create a new npc on the spot?

Cheers.
vvight.wordpress.com
User avatar
Gizmog
Metal King Slime
Posts: 2622
Joined: Tue Feb 19, 2008 5:41 am

Post by Gizmog »

It works almost exactly like the

Code: Select all

ghul1 := NPC reference(3,0)
bits in the code you have. When you type "NPC Reference (3,0)" it returns a value, the NPC reference, of that particular instance of that particular NPC.

CreateNPC does the same thing. It creates an NPC and "returns" the reference to it. It feels like voodoo, because you're recording the reference of an NPC that theoretically doesn't exist yet, but that's the way the engine interprets code.

It's important to note that you're not creating an NPC every time you use that variable. You've merely recorded the reference, the phone number, of that NPC into the variable.

Scripts and commands that return stuff usually let you do some pretty serious slime. Here's a pretty useless example of how it works..

Code: Select all

plotscript,ReturninStuff,begin
#Run the script TenSpot and shows that value
ShowValue (TenSpot)

#Doing this won't seem to do anything, because we're getting the number ten but not doing anything with it.
TenSpot
end

script,TenSpot,begin
#Leaves this script and announces the value of 5+5
ExitReturning (5+5)
end
I'm probably just making you more confused, sorry. Hell, I'm making myself confused. Here's a more commented version of what's going on

Code: Select all


#This is just where we record the reference of the NPC.
variable (NewGuy1)

#Creates a New NPC and records its reference to  the variable NewGuy1
NewGuy1 :=    create npc (3, 8, 11) 

#Creates a new NPC. It still returns a reference, but because we didn't record its reference to a variable, we have no way of referencing that in the future. This NPC is now way harder to move around.
create npc (3, 9, 11)   

#Walks the NPC we created down 1. Does NOT create a New NPC, but I can see why you'd think so!
WalkNPC (NewGuy1,Down,1)
Essentially, Variable := CreateNPC just records the reference that CreateNPC "returns", as explained in the plotscripting dictionary. It doesn't tie that variable as a shortcut to the CreateNPC command, though how cool would that be?
User avatar
guo
Metal Slime
Posts: 749
Joined: Fri Dec 04, 2009 9:12 pm

Post by guo »

Oh, thanks! I get it now.... Erm, I think. I'll let you know once I've tinkered with it.

As always, big love TheGiz.
vvight.wordpress.com
User avatar
guo
Metal Slime
Posts: 749
Joined: Fri Dec 04, 2009 9:12 pm

Post by guo »

Ok I think I've already run into an issue.

What happens if I do the following:

Code: Select all

variable (ghul1, ghul2, ghul3)

ghul1 := create npc (3, 8, 11)
ghul2 := create npc (3, 8, 11)
ghul3 := create npc (3, 8, 11)
When I run a command such as "walk npc (ghul1, down, 2)" will the system known which npc I'm referencing? How will it tell the difference between ghul 1 created at x8 y11 and ghul2 created at x8 y11?

Cheers.

Edit: I'm almost thinking it might be easier to do it (messily) by moving NPCs out of view using "set NPC position (who, X, Y)" rather than destroying them, then putting them back instead of using "Create npc" ... that way I can retain the individual NPC references.
Last edited by guo on Mon Dec 05, 2016 8:53 am, edited 1 time in total.
vvight.wordpress.com
User avatar
guo
Metal Slime
Posts: 749
Joined: Fri Dec 04, 2009 9:12 pm

Post by guo »

Got it! Bless the magic of IRC.
vvight.wordpress.com
Post Reply