| View previous topic :: View next topic | 
	
	
		| Author | Message | 
	
		| binoal 
 
 
  
 Joined: 20 Jun 2009
 Posts: 123
 Location: My Own Little World
 
 | 
			
				|  Posted: Sun Aug 23, 2009 2:53 pm    Post subject: plotscripting issue |   |  
				| 
 |  
				| this isnt a problem i ran into in any particular game, i have been bugged by it several times. How would i get a X Y coordinate for create NPC from hero direction? i want to create the npc directly in front of the character, and the only succesful way i have found is to use multiple if commands. Is there any way to do this in a less bulky fashion? _________________
 Resident Evil RPG Demo
 
 http://www.castleparadox.com/gamelist-display.php?game=963
 
 Legend Of Zelda: Reptilian Warlord Demo
 
 http://www.castleparadox.com/gamelist-display.php?game=961
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| msw188 
 
 
 
 Joined: 02 Jul 2003
 Posts: 1041
 
 
 | 
			
				|  Posted: Sun Aug 23, 2009 5:49 pm    Post subject: |   |  
				| 
 |  
				| That's pretty much the only way to do it.  You can make the script appear less 'bulky' by using a switch command instead of a bunch of if commands: 
 
  	  | Code: |  	  | switch(herodirection(me)),do begin
 case(north),do
 (createnpc(55,herox(me),heroy(me)--1))
 case(east),do
 (createnpc(55,herox(me)+1,heroy(me))
 case(south),do
 #and so on...
 
 | 
 _________________
 My first completed OHR game, Tales of the New World:
 http://castleparadox.com/gamelist-display.php?game=161
 
 This website link is for my funk/rock band, Euphonic Brew:
 www.euphonicbrew.com
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| TMC On the Verge of Insanity
 
 
 
 
 Joined: 05 Apr 2003
 Posts: 3240
 Location: Matakana
 
 | 
			
				|  Posted: Mon Aug 24, 2009 4:51 am    Post subject: |   |  
				| 
 |  
				| There is a short way. I use these scripts all the time: 
 
  	  | Code: |  	  | script, dir X, dir, begin switch (dir) do (
 case (up, down) do (return (0))
 case (right) do (return (1))
 case (left) do (return (-1))
 )
 end
 
 script, dir Y, dir, begin
 switch (dir) do (
 case (left, right) do (return (0))
 case (down) do (return (1))
 case (up) do (return (-1))
 )
 end
 
 # return the distance of a point in the specified direction from the origin
 script, directional dist, x, y, dir, begin
 switch (dir) do (
 case (up) do (return (0 -- y))
 case (right) do (return (x))
 case (down) do (return (y))
 case (left) do (return (0 -- x))
 )
 end
 | 
 
 Using these, you can write this:
 
 
  	  | Code: |  	  | dir := hero direction(me) createnpc(55, hero X(me) -- dir X(dir), hero X(me) -- dir Y(dir))
 | 
 
 Normally you would multiply dirX, dirY by the desired distance; I've implicitly multiplied by -1.
 _________________
 "It is so great it is insanely great."
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Moogle1 Scourge of the Seas
 Halloween 2006 Creativity Winner
 
  
 
  
 Joined: 15 Jul 2004
 Posts: 3377
 Location: Seattle, WA
 
 | 
			
				|  Posted: Mon Aug 24, 2009 8:01 am    Post subject: |   |  
				| 
 |  
				|  	  | The Mad Cacti wrote: |  	  | There is a short way. I use these scripts all the time: | 
 
 Argh, I wish I'd thought of something like that years ago. I can't tell you how many if-statements I have dedicated to handling four directional cases.
 _________________
 
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Bob the Hamster OHRRPGCE Developer
 
 
 
  
 Joined: 22 Feb 2003
 Posts: 2526
 Location: Hamster Republic (Southern California Enclave)
 
 | 
			
				|  Posted: Mon Aug 24, 2009 10:44 am    Post subject: |   |  
				| 
 |  
				| I used something similar in Baconthulhu. it saved worlds of trouble. |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Spoon Weaver 
 
 
  
 Joined: 18 Nov 2008
 Posts: 421
 Location: @home
 
 | 
			
				|  Posted: Mon Aug 24, 2009 2:07 pm    Post subject: |   |  
				| 
 |  
				| I heart IF statements |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| binoal 
 
 
  
 Joined: 20 Jun 2009
 Posts: 123
 Location: My Own Little World
 
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		|  |