 |
Castle Paradox
|
| View previous topic :: View next topic |
| Author |
Message |
bis_senchi

Joined: 08 Jun 2004 Posts: 460 Location: Reims, France
|
Posted: Sun Mar 11, 2007 6:28 am Post subject: make an npc says something different with the d key |
|
|
I would like that when you press the d key and when you are near a npc the npc says something (as if we had press the space bar)
To do so, I would need the following scripts
| Code: |
script, myonkeypress, begin
if (key is pressed(Key:d)), then, begin
set variable (MyX,herox(me)) # store our X, Y location
set variable (MyY,heroy(me))
#store npcs that have been pre selected and with whom we can speak.
set variable (npc9x, npc x (9))
set variable (npc9y, npc y (9))
set variable (npc2x, npc x (2))
set variable (npc2y, npc y (2))
set variable (npc14x, npc x (14))
set variable (npc14y, npc y (14))
set variable (npc15x, npc x (15))
set variable (npc15y, npc y (15))
end
My problem is the following. I would like to make compare the npcs locations with the hero and them deduce what npc is near us (we are suppose to be near him (or her)) so that the appropriate text box is shown?
As always thanks very much for the help!
|
_________________ It's time to make games! |
|
| Back to top |
|
 |
msw188
Joined: 02 Jul 2003 Posts: 1041
|
Posted: Sun Mar 11, 2007 5:49 pm Post subject: |
|
|
There is a command called "NPC at spot(x,y)" that you will want to use. Then in your keypress script, it would look like more or less like this:
| Code: |
if(key is pressed(key:d)),then
begin
variable(myX,myY,myDirection,Xcheck,Ycheck)
myX:=herox(me)
myY:=heroy(me)
myDirection:=herodirection(me)
if(myDirection==north),then
begin
Xcheck:=myX
Ycheck:=(myY--1)
end
#similar things for the other directions, where Xcheck and Ycheck are going to define which tile is directly in front of your hero
if(NPC at spot (Xcheck,Ycheck) == 9), then
begin
#do whatever for npc 9
end
#and so on for other npc IDs
end |
Does this make sense? _________________ 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 Mar 12, 2007 3:03 am Post subject: |
|
|
I don't think that's what was intended, or attaching textboxes to the npcs would have worked.
Use a script like this to find the Manhattan distance between to points.
| Code: | script, abs, val, begin
if (val >> 0) then (return (val)) else (return (0 -- val))
end
script, distance, x1, y1, x2, y2, begin
return (abs (x1 -- x2) + abs (y1 -- y2))
end |
Also look at '3rd Party HSI Code' _________________ "It is so great it is insanely great." |
|
| Back to top |
|
 |
msw188
Joined: 02 Jul 2003 Posts: 1041
|
Posted: Mon Mar 12, 2007 8:41 am Post subject: |
|
|
I think the problem was that he wanted to trigger something different out of the NPC by using the 'd' key rather than the space bar. But a generalized 'Manhatten' distance script is nice to have. Hamsterspeak doesn't have absolute value itself? I think that this ought to be included in plotscr and so put into the plotscripting library; sure its simple, but that's not a good reason not to have it there. _________________ 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: Tue Mar 13, 2007 10:06 pm Post subject: |
|
|
Would be best to make it builtin for speed.
This is my favourite absolute script, though it's probably not as fast:
| Code: | script, abs, val, begin
return (val * (val >> 0) -- val * (val << 0))
end |
_________________ "It is so great it is insanely great." |
|
| Back to top |
|
 |
bis_senchi

Joined: 08 Jun 2004 Posts: 460 Location: Reims, France
|
Posted: Tue Mar 13, 2007 10:46 pm Post subject: I've made some tests |
|
|
I've made some tests with msw188's script and it didn't work. Here are my scripts. Anyone see something wrong? (Bad use of the suspend commands may be...)
| Code: |
define script (21, mykeypressed,none)
define script (autonumber, talkwithD,none)
Global variable (13, mydirect)
#hero's current direction, north, east, west...
Global variable (14, Xcheck)
Global variable (15, Ycheck)
#---------------------------------------------------------------------
script, mykeypressed, begin
if (key is pressed(Key:d)), then, begin
talkwithD
end
end# end of the plotscript
#---------------------------------------------------------------------
script, talkwithD, begin
suspend npcs
suspend player
set variable (MyX,herox(me)) # on enregistre notre position dans le jeu
set variable (MyY,heroy(me))
set variable (MyDirect, herodirection(me))
if(myDirect==north),then
begin
Xcheck:=myX
Ycheck:=(myY--1)
end
if(myDirect==south),then
begin
Xcheck:=myX
Ycheck:=(myY--1)
end
if(myDirect==east),then
begin
Xcheck:=myX
Ycheck:=(myY--1)
end
if(myDirect==west),then
begin
Xcheck:=myX
Ycheck:=(myY--1)
end
#similar things for the other directions, where Xcheck and Ycheck are going to define which tile is directly in front of your hero
if(NPC at spot (Xcheck,Ycheck) == 9), then
begin
#do whatever for npc 9
resume player
resume npcs
show text box (78)
wait for text box
end
if(NPC at spot (Xcheck,Ycheck) == 2), then
begin
#do whatever for npc 2
resume player
resume npcs
show text box (61)
wait for text box
end
#and so on for other npc IDs
resume player
resume npcs
end #end of the plotscript
#---------------------------------------------------------------------
|
As always, thanks in advance for the help! _________________ It's time to make games! |
|
| Back to top |
|
 |
msw188
Joined: 02 Jul 2003 Posts: 1041
|
Posted: Wed Mar 14, 2007 8:59 am Post subject: |
|
|
You're not grasping the directional thing. The Xcheck and Ycheck should be slightly different for each direction, indicating which way the player is facing: (this is pseudocode, really)
| Code: | if(south),then
XCheck:=myX
YCheck:=(myY + 1)
if(east),then
XCheck:=(myX + 1)
YCheck:=myY
if(west),then
XCheck:=(myX--1)
YCheck:=myY
|
See what I mean? _________________ 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 |
|
 |
TwinHamster ♫ Furious souls, burn eternally! ♫

Joined: 07 Mar 2004 Posts: 1352
|
Posted: Wed Mar 14, 2007 9:09 am Post subject: |
|
|
Why bother going into if/then commands?
I'm sure that this little tidbit of code would suffice:
| Code: |
use npc (NPC at spot (myX,myY,number))
|
|
|
| Back to top |
|
 |
Moogle1 Scourge of the Seas Halloween 2006 Creativity Winner


Joined: 15 Jul 2004 Posts: 3377 Location: Seattle, WA
|
Posted: Wed Mar 14, 2007 11:20 am Post subject: |
|
|
No, msw is right. Otherwise, you're trying to activate the NPC where you're standing. You want the one that's in front of you. _________________
|
|
| Back to top |
|
 |
TwinHamster ♫ Furious souls, burn eternally! ♫

Joined: 07 Mar 2004 Posts: 1352
|
Posted: Wed Mar 14, 2007 1:18 pm Post subject: |
|
|
| Moogle1 wrote: | | No, msw is right. Otherwise, you're trying to activate the NPC where you're standing. You want the one that's in front of you. |
Oy. I thought that the myX/Y was the location of the NPC.
I'm not sure how, but, :p |
|
| Back to top |
|
 |
TMC On the Verge of Insanity
Joined: 05 Apr 2003 Posts: 3240 Location: Matakana
|
Posted: Wed Mar 14, 2007 7:01 pm Post subject: |
|
|
Why are you using suspend player/npcs? Those statements aren't doing anything. If you want all npcs to stand still while a textbox is shown, use this instead:
| Code: | show textbox (#)
suspend npcs
wait for textbox
resume npcs |
_________________ "It is so great it is insanely great." |
|
| Back to top |
|
 |
bis_senchi

Joined: 08 Jun 2004 Posts: 460 Location: Reims, France
|
Posted: Thu Mar 15, 2007 10:57 am Post subject: I've made some tests and... |
|
|
I've include the following lines in my code but when I made tests, hspeak.exe says that there is an error because condition are always true or false.
Any suggestion to get rid of this error?
| Code: |
if(south),then
XCheck:=myX
YCheck:=(myY + 1)
if(east),then
XCheck:=(myX + 1)
YCheck:=myY
if(west),then
XCheck:=(myX--1)
YCheck:=myY
if(north),then, begin
Xcheck:=myX
Ycheck:=(myY--1)
end
|
Thanks very much for answering so quickly! _________________ It's time to make games! |
|
| Back to top |
|
 |
Camdog
Joined: 08 Aug 2003 Posts: 606
|
Posted: Thu Mar 15, 2007 11:12 am Post subject: |
|
|
You've gotten rid of the "MyDirect ==" in your if statements. Since the directions are simply constants, they always evaluate the same way, hence your error. You should write:
| Code: | if(MyDirect == south),then (
XCheck:=myX
YCheck:=(myY + 1)
)
#etc. |
msw left out that check (and the closing and opening parentheses) for sake of convenience, which is why he mentioned his example was pseudocode. |
|
| Back to top |
|
 |
TMC On the Verge of Insanity
Joined: 05 Apr 2003 Posts: 3240 Location: Matakana
|
Posted: Thu Mar 15, 2007 8:27 pm Post subject: |
|
|
| Code: | x check := hero x
y check := hero y
switch (hero direction (me)) do (
case (north) do (y check -= 1)
case (south) do (y check += 1)
case (left) do (x check -= 1)
case (right) do (x check += 1)
) |
Why the comma before all your 'then's?
EDIT: It's worth mentioning that npc at spot might not be too great, npc at pixel (x * 20 + 10, y * 20 + 10) might give better results. Doesn't matter if you don't plan to use moving npcs I guess _________________ "It is so great it is insanely great." |
|
| Back to top |
|
 |
msw188
Joined: 02 Jul 2003 Posts: 1041
|
Posted: Thu Mar 15, 2007 9:11 pm Post subject: |
|
|
Oh, look who's getting all fancy with the new toys!
Seriously, I forgot about the new switch command. That is a lot cleaner than mine, I guess this is exactly the kind of stuff that a switch command is made for. As for the commas, I seem to remember seeing somewhere a hamsterspeak syntax document that claimed the commas were needed after your conditions in all flow commands, but this was a good while ago, and its possible I just misinterpreted what the document was saying. But that is how I've done it ever since (and that was when I first began using the OHR, when I read pretty much the entire old FAQ and tutorials before even downloading the thing, somewhere over six years ago).
To bis senchi:
The Mad Cacti's script should take care of all my 'if then' junk, and then all you should have to do is have your own series of 'if' checks to see which NPC is at spot (Xcheck,Ycheck). Or maybe that could be accomplished with a switch statement, too? Something like:
| Code: | switch(NPC at spot (Xcheck,Ycheck)) do
begin
case(2) do(#stuff for npc 2)
case(7) do(#stuff for npc 7)
#etc
end |
Or does switch need its cases going up one at a time? _________________ 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 |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|