Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   help with onwall (https://forums.graalonline.com/forums/showthread.php?t=33740)

IAMNOTAFREAK 07-18-2002 06:54 AM

help with onwall
 
NPC Code:

if (created) {toweapons walking;}
if (playerenters){this.m=.1;this.oldx = playerx;this.oldy = playery;}
if (isweapon||timeout){this.mx=0;this.my=0;this.ok=1;
this.dir=10*this.my+this.mx;this.rx=1;this.ry=1;
if (playerx<this.oldx) {this.mx=this.m;}
if (playery<this.oldy) {this.my=this.m;}
if (playerx>this.oldx) {this.mx=-1*this.m;}
if (playery>this.oldy) {this.my=-1*this.m;}
if (this.mx<0) {this.rx=4-1;}
if (this.mx>0) {this.rx=-1.5-1;}
for (i=1;i<=2;i+=.25; ) {this.rx+=.25;
for (this.ry=1;this.ry<=2.5;this.ry+=.5) {
if (onwall(playerx+this.rx+this.mx,playery+this.ry)) {this.ok=0;}}}
if (this.ok==1) {playerx-=this.mx;}
if (this.my<0) {this.ry=4.5-1.5;}
if (this.my>0) {this.ry=-1-1.5;}
for (i=1;i<=3;i+=.25; ) {this.ry+=.25;
for (this.rx=.75;this.rx<=2.5;this.rx+=.5) {
if (onwall(playerx+this.rx,playery+this.ry+this.my)) {this.ok=0;}}}
if (this.ok==1) {playery-=this.my;}
this.oldx = playerx;
this.oldy = playery;
timeout=.05;
}



the scripts works fine, i just need some help with the onwall for playerdir 1 (to the left)

Python523 07-18-2002 07:50 AM

no offense but the format is like unreadable, format your scripts like this
if(stuff){
commands here;
}

Falcor 07-18-2002 08:24 AM

Everyone has their own preference in formating. If you wanna be anal retentative (sp?) it should acually be like

NPC Code:

if(this)
{
commands;
if(this)
{
commands;
}
}



I acualy like this way more, since you can see the acual code blocks. but it is faster to type it in one line. Which is how most people do it. Duno why I posted this. But their are many ways to format. I'm more concerned with his lack of commenting. Commenting will help you and everyone else emmensly (sp?). Telling yourself and other what you are doing in the code, what the variables do and stuff. So comming back to your code weeks/months later, doesn't confuse you.

Python523 07-18-2002 08:36 AM

i use to formatlike that, but I changed when my friends wanted me to use the other way for some reason, don't know why, as long as its not like all on one line I try not to complain too much

adam 07-18-2002 09:25 AM

My format.

NPC Code:


if (playerenters) {
do this stuff;
do that stuff;
if (this == that) {
do this stuff too;
} else {
do this stuff instead;
}
}



omg wow my screen just flashed blue

screen_name 07-18-2002 10:30 AM

that code was pretty unreadable Xx

dont include every command on one line please

but you could use onwall2 if going to use NPC Server



:) - to you CheeTos

IAMNOTAFREAK 07-19-2002 11:40 AM

any experienced scripter would be able to read that with no problem...or maybe im just special :D

anyway, here:
NPC Code:

if (created) {
toweapons walking;
}
if (playerenters){
this.m=.1;
this.oldx = playerx;
this.oldy = playery;
}
if (isweapon||timeout){
this.mx=0;
this.my=0;
this.ok=1;
this.dir=10*this.my+this.mx;
this.rx=1;this.ry=1;
if (playerx<this.oldx) {
this.mx=this.m;
}
if (playery<this.oldy) {
this.my=this.m;
}
if (playerx>this.oldx) {
this.mx=-1*this.m;
}
if (playery>this.oldy) {
this.my=-1*this.m;
}
if (this.mx<0) {
this.rx=4-1;
}
if (this.mx>0) {
this.rx=-1.5-1;
}
for (i=1;i<=2;i+=.25; ) {
this.rx+=.25;
for (this.ry=1;this.ry<=2.5;this.ry+=.5) {
if (onwall(playerx+this.rx+this.mx,playery+this.ry)) {
this.ok=0;
}
}
}
if (this.ok==1) {
playerx-=this.mx;
}
if (this.my<0) {
this.ry=4.5-1.5;
}
if (this.my>0) {
this.ry=-1-1.5;
}
for (i=1;i<=3;i+=.25; ) {
this.ry+=.25;
for (this.rx=.75;this.rx<=2.5;this.rx+=.5) {
if (onwall(playerx+this.rx,playery+this.ry+this.my)) {
this.ok=0;
}
}
}
if (this.ok==1) {
playery-=this.my;
}
this.oldx = playerx;
this.oldy = playery;
timeout=.05;
}



there, gosh that's so much longer...
well, anyway, here, now it's readable, please help, all i need is some help with onwall, not too much to ask...i'm just no good with it...:(
and, by the way, it's not for an npc server, but how do you use onwall2, for future reference...


All times are GMT +2. The time now is 10:23 AM.

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