Falling boulder 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

Falling boulder script

Post by guo »

Greetings script wizards.

I have a script that makes a boulder fall on your head when you trigger a step on NPC. The boulder is always situated 6 squares above the step on NPC that triggers the script. There are 4 instances of the same NPC for "boulder", which happens to be NPC 5 in the list. Therefore, the 4 boulders are NPC 5,0 5,1 5,2 & 5,3. The step on NPCs that trigger the script sends an argument to the script based on the instance number of the boulder that I wish to fall. Here is what the scripts look like:

Code: Select all

script, hurtplayer, amount, begin
	variable (damage)
	damage := amount
	#will hurt the player without killing them, reducing them to a minimum of 1 hp
	if &#40; &#40;get hero stat &#40;me, stat&#58;life, current stat&#41; &#41; <= damage&#41; #if players health is already less than the amount of damage to be dealt, reduce player's health to 1 
		then &#40;
			set hero stat&#40;find hero &#40;0&#41;, stat&#58;life, &#40;get hero stat &#40;find hero &#40;0&#41;, stat&#58;life, current stat&#41; -- &#40;get hero stat &#40;find hero &#40;0&#41;, stat&#58;life, current stat&#41; -- 1&#41; &#41; , current stat&#41; 
		&#41;		
		else &#40;
			#subtract damage amount of life from player
			set hero stat&#40;find hero &#40;0&#41;, stat&#58;life, &#40;get hero stat &#40;find hero &#40;0&#41;, stat&#58;life, current stat&#41;--&#40;damage&#41; &#41;, current stat&#41; 
		&#41;
end
	

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

plotscript, rockfall, arg, begin
	#variable &#40;npcinstance&#41;
	#npcinstance &#58;= arg
	suspend player
	suspend NPCs
	set NPC ignores walls &#40;NPC reference &#40;5, arg&#41;, true&#41;
	set NPC obstructs &#40;NPC reference &#40;5, arg&#41;, false&#41;
	#stop everything moving, allow the rock to fall through walls/other npcs/the hero
		play sound &#40;22, false, false&#41;
		walk npc &#40;NPC reference &#40;5, arg&#41;, down, 3&#41;
		wait for npc &#40;NPC reference &#40;5, arg&#41; &#41;
	#do the check to see if you avoid the falling rock when it is halfway down
		if &#40;get hero stat &#40;me,stat&#58;agility, current stat&#41; <= random &#40;1,25&#41; &#41;
			then &#40; 
				walk hero &#40;me, right, 1&#41;
				walk npc &#40;NPC reference &#40;5, arg&#41;, down, 3&#41;
				wait for npc &#40;NPC reference &#40;5, arg&#41; &#41;
				play sound &#40;21, false, false&#41;
				delete npc &#40;NPC reference &#40;5, arg&#41; &#41;
				show text box &#40;331&#41;
				wait for textbox
				resume player
				resume NPCs

			&#41;
			else &#40;
				walk npc &#40;NPC reference &#40;5, arg&#41;, down, 3&#41;
				wait for npc &#40;NPC reference &#40;5, arg&#41; &#41;
				play sound &#40;23, false, false&#41;
				delete npc &#40;NPC reference &#40;5, arg&#41; &#41;
				show text box &#40;332&#41;
				wait for textbox
				hurtplayer &#40;10&#41;
				resume player
				resume NPCs
			&#41;

end
	
The problem is, sometimes the script works fine, whereas other times it doesn't appear to be having the right argument sent to it. I will paste a screenshot of the error message I am receiving for clarity. The last time I checked it, the first boulder fell fine and then, when triggered from the other 3 NPCs, no boulder fell - but I have had it work ok before that. It seems a little random. The SFX still plays, the text box & damage are still applied where necessary but the boulder doesn't move.

Any help muchly appreciated!
Attachments
1
1
Bale0000.png (11.73 KiB) Viewed 384 times
2
2
Bale0001.png (20.11 KiB) Viewed 384 times
3
3
Bale0002.png (9.44 KiB) Viewed 382 times
Last edited by guo on Tue Sep 06, 2016 12:28 pm, edited 1 time in total.
vvight.wordpress.com
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7660
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

This approach is always going to be unreliable.

It will work for the first rock, but when that rock is deleted, then the instance numbers change for some of the other rocks.

hard coding instance number into the argument simply isn't going to work for a script that needs to delete the NPC instance.

However, since the rock above is always six squares above the trigger, there is another easy way to do this:

Code: Select all

plotscript, rockfall, arg, begin
   variable &#40;npc&#41;
   # Get the NPC 6 tiles above the hero
   npc &#58;= NPC at spot&#40;hero x&#40;0&#41;, hero y&#40;0&#41; -- 6&#41;
   # Check to make sure it is really a rock
   if&#40;get NPC id&#40;npc&#41; <> 5&#41; then&#40;exit script&#41;
   suspend player
   suspend NPCs
   set NPC ignores walls &#40;npc, true&#41;
   set NPC obstructs &#40;npc, false&#41;
   #stop everything moving, allow the rock to fall through walls/other npcs/the hero
      play sound &#40;22, false, false&#41;
      walk npc &#40;npc, down, 3&#41;
      wait for npc &#40;npc&#41;
   #do the check to see if you avoid the falling rock when it is halfway down
      if &#40;get hero stat &#40;find hero&#40;leader&#41;,stat&#58;agility, current stat&#41; <= random &#40;1,25&#41; &#41;
         then &#40;
            walk hero &#40;me, right, 1&#41;
            walk npc &#40;npc, down, 3&#41;
            wait for npc &#40;npc&#41;
            play sound &#40;21, false, false&#41;
            delete npc &#40;npc&#41;
            show text box &#40;331&#41;
            wait for textbox
            resume player
            resume NPCs

         &#41;
         else &#40;
            walk npc &#40;npc, down, 3&#41;
            wait for npc &#40;npc&#41;
            play sound &#40;23, false, false&#41;
            delete npc &#40;npc&#41;
            show text box &#40;332&#41;
            wait for textbox
            hurtplayer &#40;10&#41;
            resume player
            resume NPCs
         &#41;

end 
I also fixed another bug in the script. You had:

Code: Select all

get hero stat &#40;me,stat&#58;agility, current stat&#41;
"me" is a constant for 0, but 0 is only a reliable way to refet to the leader in the walkabout caterpillar. The "get hero stat" command requires battle party position, not walkabout caterpillar rank, so if you hero was not in the first slot, this command would fail.

I changed it to:

Code: Select all

get hero stat &#40;find hero&#40;leader&#41;,stat&#58;agility, current stat&#41;
Which should reliably get the agility of the leader of the caterpillar party, even if the first battle party slot happens to be empty.

If you have not seen it before, I recommend reading the wiki article that breaks down the three different ways of referring to a hero in a script http://rpg.hamsterrepublic.com/ohrrpgce ... n_a_script
User avatar
guo
Metal Slime
Posts: 749
Joined: Fri Dec 04, 2009 9:12 pm

Post by guo »

Thanks, you are a gentleman and a scholar. I use "me" to refer to the hero as the party is locked permanently (and I'm lazy). The main hero is always in slot 1, however if he is already unconscious will the damage be dealt to the next member? Also, I like your boulder check because now prudent players can remove precarious boulders in advance and save themselves a headache!

edit: I might add arguments for "distance of NPC above hero" & "boulder npc number" so that I can plug this script more easily into future maps.

Would the following work?

Code: Select all

plotscript, rockfall, distance, rocknum, begin
	variable &#40;rock&#41; 
	# Get the NPC "distance" tiles above the hero 
	rock &#58;= NPC at spot&#40;hero x&#40;0&#41;, hero y&#40;0&#41; -- distance&#41; 
	# Check to make sure it is really a rock 
	if&#40;get NPC id&#40;rock&#41; <> rocknum&#41; then&#40;exit script&#41; 
Then the script is called like so:

Code: Select all

rockfall &#40;6, 5&#41;
For instance.
Last edited by guo on Wed Sep 07, 2016 12:08 am, edited 4 times in total.
vvight.wordpress.com
Post Reply