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 04-05-2006, 03:19 PM
MegaMasterX90875 MegaMasterX90875 is offline
Retired Graalian (2009)
MegaMasterX90875's Avatar
Join Date: Feb 2006
Location: North Carolina
Posts: 132
MegaMasterX90875 is on a distinguished road
Send a message via AIM to MegaMasterX90875
Changing an NPC's X/Y Coordinates

I'm trying to make a script that tokenizes and sets X/Y coordinates according to tokenized results. This is what I have so far (Note: It's in GS1):
NPC Code:
 if (created) {
set OrigX;
set OrigY;
OrigX=this.x;
OrigY=this.y;
//This is in case it messes up.
set EditMode;
}
if (playerchats&&strequals(#c,/Editmode)) {
EditMode=1;
message EditMode On!;
sleep 2;
message ;
}
if (playerchats&&strequals(#c,/Editmode off)) {
EditMode=0;
message EditMode Off!;
sleep 2;
message ;
}
if (playerchats&&EditMode=1&&strcontains(#c,/move chair1)) {
tokenize #c;
this.x=strtofloat(#t(3));
this.y=strtofloat(#t(4));
}
if (playertouchsme&&EditMode=1) {
blockagain;
canbepushed;
canbepulled;
}
if (playertouchsme&&EditMode=0) {
dontblock;
cannotbepushed;
cannotbepulled;
player.sprite=37;
}


The /move chair1 is supposed to be like /move chair1 <NewX> <NewY>
Also, when the player chats the sprite is changed to sitting (37) even when the player is not touching the chair.
Is there a way to make this serverside and save the position of the objects?
Is this the best way to do this?
And, can I make it check to see if it's on a wall? How do I do that?
__________________
Mess with the best, Die like the rest.




Last edited by MegaMasterX90875; 04-05-2006 at 03:21 PM.. Reason: Forgot to add something
Reply With Quote
  #2  
Old 04-05-2006, 05:42 PM
Yen Yen is offline
Banned
Yen's Avatar
Join Date: Oct 2005
Location: Nova Scotia, Canada
Posts: 1,085
Yen is an unknown quantity at this point
Send a message via AIM to Yen Send a message via MSN to Yen
Well.. Using GS1 is a bad way to script anything. It's so.. Tacky!

You're going to want setshape2 w,h,{tiletypes}. You can set it's tiletype to chair tiles. Unfortunately, I don't remember what the chair tiletype is. Anyway, it would look like this:
setshape2 2,2,{7,7,7,7};

For onwall checks, you'll want to use the boolean onwall2(x,y,w,h). For example:
if (!onwall2(x,y,2,2)) will check if anyway in a 2x2 rectangle of the NPC's x and y is blocking. If it returns false, it'll keep going.
Reply With Quote
  #3  
Old 04-05-2006, 05:44 PM
Andy0687 Andy0687 is offline
Enigma
Join Date: Feb 2002
Posts: 1,072
Andy0687 is on a distinguished road
I think I will try to answer this for you

Kinda seems to me like you have a lot of fluff in the script that you dont neccessarily need, but im not going for that now, just helping you to fix up the part you want fixed.

Quote:
Originally Posted by MegaMasterX90875
I'm trying to make a script that tokenizes and sets X/Y coordinates according to tokenized results. This is what I have so far (Note: It's in GS1):
NPC Code:

if (playerchats&&EditMode=1&&strcontains(#c,/move chair1)) {
tokenize #c;
this.x = strtofloat(#t(3));
this.y = strtofloat(#t(4));
}



I think unless you have gs2 enabled on your server (Correct me If Im wrong someone) this.x and this.y will not set the x and y of the npc. just use x and y. Another thing you might want to look at to clean up your code some, is nesting your statements, makes things more readable.

NPC Code:
 
if (playerchats) {
if (strequals(#c,blah1)) {
}
else if (strequals(#c,blah2)) {
}
else if (strequals(#c,blah3)) {
}
}



The first mistake I see is if you want something to be
Quote:
The /move chair1 is supposed to be like /move chair1 <NewX> <NewY>
You probably wanted to see if it "startswith" /move chair1
Tokens start at 0 so they would be like this
/move = #t(0)
chair1 = #t(1)
xnumber = #t(2)
ynumber = #t(3)

NPC Code:

if (playerchats) {
if (startswith(/move chair1,#c)) {
tokenize #c;
x = strtofloat(#t(2));
y = strtofloat(#t(3));
}
}



You had the x as 3 and the y as 4, so you were probably moving the chair completely away from the board on the y, because there was no value.

Quote:
And, can I make it check to see if it's on a wall? How do I do that?
Try using onwall2(x,y,w,h) for checking if the tile is a blocking tile or not.

Edit: Yen got the Onwall better then I did, and setshape2
Reply With Quote
  #4  
Old 04-06-2006, 12:52 AM
MegaMasterX90875 MegaMasterX90875 is offline
Retired Graalian (2009)
MegaMasterX90875's Avatar
Join Date: Feb 2006
Location: North Carolina
Posts: 132
MegaMasterX90875 is on a distinguished road
Send a message via AIM to MegaMasterX90875
Gah, I see now! Thanks to all who helped!
__________________
Mess with the best, Die like the rest.



Reply With Quote
  #5  
Old 04-06-2006, 01:28 AM
Projectshifter Projectshifter is offline
The David
Projectshifter's Avatar
Join Date: Apr 2002
Location: USA
Posts: 912
Projectshifter is an unknown quantity at this point
Send a message via ICQ to Projectshifter Send a message via AIM to Projectshifter Send a message via MSN to Projectshifter Send a message via Yahoo to Projectshifter
You don't need to initialize variables in Graal, and if you're just trying to set them true/false you can just do var = true/var = false;
__________________
Who has time for life these days?
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 08:48 PM.


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