Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 06-24-2003, 02:55 PM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
Onwall(x, y) question.

Does anybody seriously have a clue what the onwall(x, y) function actually checks?

Yes, well, it checks for walls, but where exactly?

I think the first picture is the most exact one, and I seriously doubt that the others are right, but it seems not to be actually working like that in my movement script.
Perhaps it checks for the top left corner of the pixel in picture 1? Scary, isn't it?
Reply With Quote
  #2  
Old 06-24-2003, 03:08 PM
Kaimetsu Kaimetsu is offline
Script Monkey
Kaimetsu's Avatar
Join Date: May 2001
Posts: 18,222
Kaimetsu will become famous soon enough
I don't think Graal tends to care much about pixels (abstraction from display mechanism, yo), but that's another story. I always thought onwall was purely tile-based, as in the second picture.
__________________
Reply With Quote
  #3  
Old 06-24-2003, 03:32 PM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
Usage:
onwalltest npcx npcy width height testx testy
All parameters in pixels.
It will move the first NPC to npcx, npcy and make it go width*height pixels large. Then the other NPC checks the given point.
NPC Code:
//#CLIENTSIDE
if (created) {
x = 0;
y = 0;
}
if (playerchats) {
if (startswith(onwalltest, #c)) {
tokenize #c;
x = strtofloat(#t(1))/16;
y = strtofloat(#t(2))/16;
setshape 1, strtofloat(#t(3)), strtofloat(#t(4));
showpoly 0,{x,y,
x+strtofloat(#t(3))/16,y,
x+strtofloat(#t(3))/16,y+strtofloat(#t(4))/16,
x,y+strtofloat(#t(4))/16};
}
}


NPC Code:
//#CLIENTSIDE
if (created) {
x = 0.5;
y = 0;
}

if (playerchats) {
if (startswith(onwalltest, #c)) {
tokenize #c;
sleep 0.2;
if (onwall(strtofloat(#t(5))/16,strtofloat(#t(6))/16)) {
say2 ONWALL;
} else say2 NOT ON WALL;
}
}


I believe using it like onwalltest 1 1 15 15 0 0 (Making it fill a whole tile minus the top and most left line of pixels, and checking for the topleft pixel) proves that it is pixel exact.

And just for the sake of posting code, here is a simplified version of my movement script.

NPC Code:
//#CLIENTSIDE
if (created || timeout) {
disabledefmovement;
speed = 8; // Pixels to move in 0.05 secs
setarray wall, 6; // To store all the onwall checks around the player
for (d = 0; d < 4; d ++) if (keydown(d)) {
for (m=0; m < speed; m ++) {
// We need to check all around the player for sidemoving.
// Two tiles for three sides -> 6
for (i=0; i < 6; i++) {
wall = 0;
// Lots of pixelexact math stuff
// First, set up directions to check in
checkdir = (d-int(i/2)+1)%4;
checkdir2 = (checkdir+1)%4;
// Set the "centre" of the player, the very center, more than pixelexact
mx = this.x+23.5/16;
my = this.y+31.5/16;
// Modificators based on the direction
modx = vecx(checkdir2)*(15.5/16-i%2) + vecx(checkdir)*16.5/16;
mody = vecy(checkdir2)*(15.5/16-i%2) + vecy(checkdir)*16.5/16;
for (p=0; p < 2; p++) {
// Two points for each pixels (the corners which are close to the player)
pmodx = p*vecx(checkdir2)*15/16;
pmody = p*vecy(checkdir2)*15/16;
// Finally, the pixel we need to check
tx = mx+modx-pmodx;
ty = my+mody-pmody;
// If the test point is on a wall, save that
wall += onwall(tx,ty);
}
// If one test point is on a wall, this position is blocked
wall[i] = (wall > 0);
}
// Check if you need to move to the side instead of straigh forwards
if (!(1 in {wall[2],wall[3]})) mod = 0;
else if (!(1 in {wall[2],wall[0],wall[1]})) mod = 1;
else if (!(1 in {wall[3],wall[4],wall[5]})) mod = -1;
else mod = 20; // No movement allowed
if (mod in {-1,0,1}) {
// Figure out how to move
mx = vecx((d+mod)%4)*1/16;
my = vecy((d+mod)%4)*1/16;
playerx += mx;
playery += my;
// Stop movement, so you only move 2 pixels when sidemoving
if (mod!=0 && m>0) m = speed;
} else m = speed; // If completely blocked, we may as well stop checking
}
}
timeout = 0.05;
}


(Only to be used for educational purposes. If you really really have to use it or derived work on your PW, gimme credit at least.)

Last edited by Loriel; 06-24-2003 at 05:08 PM..
Reply With Quote
  #4  
Old 06-24-2003, 04:14 PM
adam adam is offline
http://wiki.graal.us/
adam's Avatar
Join Date: Nov 2001
Posts: 2,247
adam has a spectacular aura aboutadam has a spectacular aura about
Send a message via AIM to adam
Quote:
Originally posted by Kaimetsu
I don't think Graal tends to care much about pixels (abstraction from display mechanism, yo), but that's another story. I always thought onwall was purely tile-based, as in the second picture.

I used to think onwall was tile based, then I tried to use onwall. It doesn't seem to be so. seems to be 16ths of a tile


But in any case, it's confusing and difficult to do things with it. >.<
__________________
Rogue Shadow (TCN)(NAT)(Global Development Team)

For development help, contact the patrons of the #graaldt irc channel below, I am usually there.
Click Here to Join IRC Chat Now! -- irc.freenode.net Channel: #graaldt
Quote:
<Dustyshouri> no, RogueShadow is always talking about scripts lol
<Dustyshouri> in fact, he pretty much brought Graal back as a topic single-handedly
Reply With Quote
  #5  
Old 06-24-2003, 04:35 PM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
Quote:
Originally posted by adam
seems to be 16ths of a tile
== 1 pixel
Reply With Quote
  #6  
Old 06-24-2003, 05:11 PM
YoungTwist YoungTwist is offline
Registered User
Join Date: Feb 2003
Location: MASS
Posts: 44
YoungTwist is an unknown quantity at this point
Send a message via AIM to YoungTwist
OMG!!! How can you guys look at this. This hurts my head when i try to look at it. lol I dont think i could ever under stand scripting, its too much and too much to rember, i guess ill stay makeing levels and going on my way :-P
Reply With Quote
  #7  
Old 06-25-2003, 01:20 AM
Kaimetsu Kaimetsu is offline
Script Monkey
Kaimetsu's Avatar
Join Date: May 2001
Posts: 18,222
Kaimetsu will become famous soon enough
In any case, isn't onwall pretty much superseded by onwall2 (at least for this kind of thing)? It makes movement scripts so much simpler.
__________________
Reply With Quote
  #8  
Old 06-25-2003, 03:16 AM
wonderboysp2p wonderboysp2p is offline
Registered User
wonderboysp2p's Avatar
Join Date: Sep 2002
Location: -Wonderboy
Posts: 537
wonderboysp2p is on a distinguished road
Send a message via AIM to wonderboysp2p
onwall is pixel based (1/16 of a tile) thats the smallest and most accurate way of measuring in graal

yay i actually know something worth while!
__________________

we are the llama FORUms!!!EWQ Ce13d5423f23!! 2e1 @$6tgv3uy65!
Reply With Quote
  #9  
Old 06-25-2003, 03:51 AM
adam adam is offline
http://wiki.graal.us/
adam's Avatar
Join Date: Nov 2001
Posts: 2,247
adam has a spectacular aura aboutadam has a spectacular aura about
Send a message via AIM to adam
Quote:
Originally posted by Kaimetsu
In any case, isn't onwall pretty much superseded by onwall2 (at least for this kind of thing)? It makes movement scripts so much simpler.

Has onwall2 been released for clientside yet?
__________________
Rogue Shadow (TCN)(NAT)(Global Development Team)

For development help, contact the patrons of the #graaldt irc channel below, I am usually there.
Click Here to Join IRC Chat Now! -- irc.freenode.net Channel: #graaldt
Quote:
<Dustyshouri> no, RogueShadow is always talking about scripts lol
<Dustyshouri> in fact, he pretty much brought Graal back as a topic single-handedly
Reply With Quote
  #10  
Old 06-25-2003, 03:52 AM
adam adam is offline
http://wiki.graal.us/
adam's Avatar
Join Date: Nov 2001
Posts: 2,247
adam has a spectacular aura aboutadam has a spectacular aura about
Send a message via AIM to adam
Quote:
Originally posted by wonderboysp2p
onwall is pixel based (1/16 of a tile) thats the smallest and most accurate way of measuring in graal

yay i actually know something worth while!
As others have pointed out

1/16 of a tile == 1 pixel.
__________________
Rogue Shadow (TCN)(NAT)(Global Development Team)

For development help, contact the patrons of the #graaldt irc channel below, I am usually there.
Click Here to Join IRC Chat Now! -- irc.freenode.net Channel: #graaldt
Quote:
<Dustyshouri> no, RogueShadow is always talking about scripts lol
<Dustyshouri> in fact, he pretty much brought Graal back as a topic single-handedly
Reply With Quote
  #11  
Old 06-25-2003, 03:45 PM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
I figure onwall2 would only make my script two or three lines shorter.
Reply With Quote
  #12  
Old 07-31-2003, 03:04 AM
tlf288 tlf288 is offline
Registered User
tlf288's Avatar
Join Date: Nov 2001
Location: new account: Trevor
Posts: 0
tlf288 is on a distinguished road
Send a message via AIM to tlf288 Send a message via Yahoo to tlf288
I can't seem to get this to work at all. None of the indeces in the array wall are ever set to 1. If you could tell me why that onwall detection snippet doesn't work it would help me out a lot, Loriel.
__________________
new account: Trevor
Reply With Quote
  #13  
Old 07-31-2003, 03:19 AM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
You sure you actually touch walls?
Last I checked the thingie, it worked, but I cannot right now. ICQ me?
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 06:34 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.