Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   move() (https://forums.graalonline.com/forums/showthread.php?t=74255)

Deadly_Killer 05-28-2007 09:16 AM

move()
 
PHP Code:

function onMovementFinished()
{
  
temp.newx vecx(this.dir) * this.walkspeed;
  
temp.newy vecy(this.dir) * this.walkspeed;
  
this.runcounter--;
  
  if (
this.runcounter 0)
  {
    
setcharani("walk"NULL);
    
    
temp.testx this.temp.newx 1.5 vecx(this.dir);
    
temp.testy this.temp.newy 2.0 vecy(this.dir);
    
    if (
onwall(temp.testxtemp.testy))
    {
      
this.dir = (dir 2) % 4;
      
this.runcounter int(random(060));
      
      
this.onMovementFinished();
    }
      else
    {
      
dist = (temp.newx temp.newy 2) ^ 0.5;
      
move(temp.newxtemp.newydist 168);
    }
  }
    else
  {
    
this.runcounter int(random(1040));
    
    
setcharani("idle"NULL);
    
this.dir = (dir int(random(02)) * 2) % 4;
    
    
this.onMovementFinished();
  }
  
  if (
this.runcounter <= 0)
  {
    
this.runcounter 20;
  }


The movement on this is very.. well, the gani is wierd. Unsure why, I tried messing with it. If someone could help, much appreciated.

P.S. Yeah, I basically rescripted offline movement to GS2 with move(). And yeah, anyone could use this script for there own server.. assuming it worked correctly =[.

Deadly_Killer 05-28-2007 08:00 PM

/bump

help please =[

Tigairius 05-28-2007 08:01 PM

We need more details, what do you mean "weird"?

Deadly_Killer 05-28-2007 08:29 PM

The gani keeps setting because it isn't finishing the movement. I even tried setting walk only once, still happens.

DustyPorViva 05-28-2007 08:49 PM

You mean the gani is 'stuck' on the first frame?
Probably because it's being set in a timeout, try doing something like:
if (this.gani!="walk") setcharani("walk",);
or however it'd be done in GS2.

Deadly_Killer 05-28-2007 09:44 PM

Quote:

Originally Posted by DustyPorViva (Post 1312712)
You mean the gani is 'stuck' on the first frame?
Probably because it's being set in a timeout, try doing something like:
if (this.gani!="walk") setcharani("walk",);
or however it'd be done in GS2.

Quote:

Originally Posted by Deadly_Killer (Post 1312707)
The gani keeps setting because it isn't finishing the movement. I even tried setting walk only once, still happens.

As in, only in onCreated();

Angel_Light 05-28-2007 11:20 PM

I made a move() tutorial awhile back, I'll upload it when I find it, it's in another move() thread I believe.

Found it. It was for making a baddy move but it may help, here you go.

move(x,y,time,options);

x = move how far from current position horizontally

y = move how far from current position vertically

time = time it takes to get from starting point to ending point

options = cachtype(0,1,2) blockcheck(4) eventwhendone(8) applydir(16)

blockcheck = test to see if the tile is blocking or not
eventwhendone = stops moving after one movement. other wise the NPC
will move forever in that direction.
applydir = if the the char current gani has 4 dir it will apply it when it moves


Here's a NPC I use for a townsfolk randomly move

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
onTimeOut();
}

function 
onTimeOut() {
  
temp.rx random(-3,3);
  
temp.ry random(-3,3);
  
temp.r  random(3,5);
  
temp.rr random(0,5);
  
setcharani("walk",NULL);
  
move(rx,ry,r,4+8+16);
  
sleep(r);
  
setcharani("idle",NULL);
  
setTimer(rr);


I have more stuff in the script of course but there is the movement part. Also remember the movement is still in the Quadrant IV (Grid Wise)

Deadly_Killer 05-29-2007 12:33 AM

Quote:

Originally Posted by Angel_Light (Post 1312731)
I made a move() tutorial awhile back, I'll upload it when I find it, it's in another move() thread I believe.

Found it. It was for making a baddy move but it may help, here you go.

move(x,y,time,options);

x = move how far from current position horizontally

y = move how far from current position vertically

time = time it takes to get from starting point to ending point

options = cachtype(0,1,2) blockcheck(4) eventwhendone(8) applydir(16)

blockcheck = test to see if the tile is blocking or not
eventwhendone = stops moving after one movement. other wise the NPC
will move forever in that direction.
applydir = if the the char current gani has 4 dir it will apply it when it moves


Here's a NPC I use for a townsfolk randomly move

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
onTimeOut();
}

function 
onTimeOut() {
  
temp.rx random(-3,3);
  
temp.ry random(-3,3);
  
temp.r  random(3,5);
  
temp.rr random(0,5);
  
setcharani("walk",NULL);
  
move(rx,ry,r,4+8+16);
  
sleep(r);
  
setcharani("idle",NULL);
  
setTimer(rr);


I have more stuff in the script of course but there is the movement part. Also remember the movement is still in the Quadrant IV (Grid Wise)

uhm.., option 8 allows the function onMovementFinished() which is what I am using

xXziroXx 05-29-2007 12:40 AM

Quote:

Originally Posted by Deadly_Killer (Post 1312746)
uhm.., option 8 allows the function onMovementFinished() which is what I am using

eventwhendone(8)

That's what he said.

Deadly_Killer 05-29-2007 01:07 AM

eventwhendone = stops moving after one movement. other wise the NPC
will move forever in that direction.

?

xXziroXx 05-29-2007 01:09 AM

No..

eventwhendone = true; onMovementFinished() will be called.
eventwhendone = false; onMovementFinished() will NOT be called.

Angel_Light 05-29-2007 01:30 AM

Quote:

Originally Posted by Deadly_Killer (Post 1312776)
eventwhendone = stops moving after one movement. other wise the NPC
will move forever in that direction.

?

This is true it will keep moving in the direction for infinity, putting 8 will make it stop after one movement.

xXziroXx 05-29-2007 01:31 AM

Quote:

Originally Posted by Angel_Light (Post 1312796)
This is true it will keep moving in the direction for infinity, putting 8 will make it stop after one movement.

*beeeep* Wrong, try again.

killerogue 05-29-2007 01:34 AM

Also, the definition you posted for the time param is wrong as well. That param is reserved for how many tiles it moves per a certain amount of time I am not sure of at the moment.

Angel_Light 05-29-2007 03:07 AM

Quote:

Originally Posted by xXziroXx (Post 1312798)
*beeeep* Wrong, try again.

True, without 8 in the options the NPC keeps moving forever in that direction both in GS1 and GS2 o.O it also calls the onMovementFinished() too.

Quote:

Originally Posted by killerogue (Post 1312802)
Also, the definition you posted for the time param is wrong as well. That param is reserved for how many tiles it moves per a certain amount of time I am not sure of at the moment.

My definition is correct look in the commands.rtf

xXziroXx 05-29-2007 03:08 AM

Quote:

Originally Posted by Angel_Light (Post 1312827)
True, without 8 in the options the NPC keeps moving forever in that direction both in GS1 and GS2 o.O it also calls the onMovementFinished() too.

No it doesnt -_-

What do you think the two first parameters are for? Just for looks? They decide how FAR it will move.

Angel_Light 05-29-2007 03:10 AM

Test it >_> the x and y are like the slope of the direction to move, the npc goes on forever without 8 in the options part.

DustyPorViva 05-29-2007 03:19 AM

From newfeatures2001:
PHP Code:

- New script commandmove dx,dy,time,options;
  
dx delta x
  dy 
delta y
  time 
time in seconds
  options 
cachingmode (0,or 2) + blockcheck (or 0) +
    
informmewhendone (or 0) + applydirection (16 or 0)
  
This moves the npc without needing you to update the
  position of the npc 
'manually' by changing x and y.
  
To move an npc 10 tiles to the rightthen 10 tiles to
  the left 
and againjust do following:
  if (
created) {
    while (
true) {
      
move 10,0,4,0;
      
sleep 4;
      
move -10,0,4,0;
      
sleep 4;
    }
  }
  
This moves the npc 10 tiles to the rightthen waits 4
  seconds
then moves it 10 tiles to the leftthen waits
  4 seconds
, and repeats this endlessly.
  
The good thing is that this also works with server-side
  npcs 
and makes them look like they are moved on client-side.
  
There are also nice options to makes things very simple:
  - 
cachingmode:
    - 
0previous movements will be finished immediatelly
    
1movements will be cachedthe previous movements
         will only be finished when the cache is too large
         
(distance to go >5);
         
this caching can be used on server-side npcs to
         make the movement look like non
-laggy even when
         there are little delays sometimes
    
2the movement will just be appended to the movement
         
list; you can add up to 100 movements
  
blockcheckadd 4 to the options when you want the
    npc to stop when there is a wall blocking the npc
  
informmewhendone: if you add 8 to the options then the
    script will be called with a 
'movementfinished' flag
    when the the npc has stopped walking
; catch this event
    with
    
if (movementfinished) {...}
    if 
you want to do something when the npc has stopped
    
(e.gwalking in a different direction)
  - 
applydirectionadd 16 to the options if you want the
    game to automatically set the direction of the npc
    depending on the movement direction 
(can be good
    when using movement caching


While the first two parameters ARE the delta, they also give a destination, so when they are reached the NPC will stop. Option 8, like it says, simply sends the event 'movementfinished'.

Deadly_Killer 05-29-2007 04:05 AM

Quote:

Originally Posted by xXziroXx (Post 1312778)
No..

eventwhendone = true; onMovementFinished() will be called.
eventwhendone = false; onMovementFinished() will NOT be called.

That is what I said. I was quoting what he called it because you said he was right originally.

Quote:

Originally Posted by Angel_Light (Post 1312830)
Test it >_> the x and y are like the slope of the direction to move, the npc goes on forever without 8 in the options part.

Then why the timeout in your example?

Angel_Light 05-29-2007 05:15 AM

Quote:

Originally Posted by Deadly_Killer (Post 1312846)
Then why the timeout in your example?

Because I have 8 in it which stops it so I can renew the x y values. Just leave the 8 out it will go in the slope give forever.

Deadly_Killer 05-29-2007 05:39 AM

Quote:

Originally Posted by Angel_Light (Post 1312880)
Because I have 8 in it which stops it so I can renew the x y values. Just leave the 8 out it will go in the slope give forever.

You are so off it isn't even FUNNY.

Inverness 05-29-2007 06:38 AM

I haven't used move() in like 2 years, I couldn't comment.

zokemon 05-29-2007 06:43 AM

Quote:

Originally Posted by Angel_Light (Post 1312880)
Because I have 8 in it which stops it so I can renew the x y values. Just leave the 8 out it will go in the slope give forever.

You might have an error somewhere. Maybe post what you have? I am 140% positive that a npc will stop after its time and distance has been covered when the '8' bit flag is not included.

xXziroXx 05-29-2007 06:44 AM

Quote:

Originally Posted by zokemon (Post 1312902)
You might have an error somewhere. Maybe post what you have? I am 140% positive that a npc will stop after its time and distance has been covered when the '8' bit flag is not included.

So am I. Always has, always will. I've used move() enough times to know.

Deadly_Killer 05-29-2007 06:45 AM

Well it was in a timeout, that's what kept it going.

xXziroXx 05-29-2007 06:50 AM

Quote:

Originally Posted by Deadly_Killer (Post 1312904)
Well it was in a timeout, that's what kept it going.

.. duh, no wonder it would never stop then x_x

cbk1994 05-29-2007 01:27 PM

Why are people even using move()? Seems like a custom move() scripting would be simpler, and much more effective ...

DustyPorViva 05-29-2007 06:27 PM

Move keeps the movement of the NPC smooth on the serverside, I don't think there's a way to replicate that.

xAndrewx 05-29-2007 06:39 PM

HTML Code:

    else
  {
    this.runcounter = int(random(10, 40));
   
    setcharani("idle", NULL);
    this.dir = (dir + 1 + int(random(0, 2)) * 2) % 4;
   
    scheduleevent(0.5, "movementFinished", "");
  }

Use scheduleevent

Deadly_Killer 05-29-2007 09:25 PM

But that isn't the problem.

For some reason, when a move() resets.. the gani resets. This should be fixed by stefan, if anything.

xAndrewx 05-29-2007 09:38 PM

no it doesn't...?

HTML Code:

function onCreated()
{
  this.showCharacter();
  move(2, 2, 0.8, 8);
  this.ani = "walk";
}
function onMovementFinished()
{
  sleep(5);
  this.destroy();
}


Deadly_Killer 05-29-2007 11:41 PM

Quote:

Originally Posted by xAndrewx (Post 1313049)
no it doesn't...?

HTML Code:

function onCreated()
{
  this.showCharacter();
  move(2, 2, 0.8, 8);
  this.ani = "walk";
}
function onMovementFinished()
{
  sleep(5);
  this.destroy();
}


Reschedule a move() when onMovementFinished() is called.

DustyPorViva 05-30-2007 01:16 AM

You'll probably have to change the gani's outside of the move.

Cloven 05-31-2007 04:45 AM

Quote:

Originally Posted by Deadly_Killer (Post 1313142)
Reschedule a move() when onMovementFinished() is called.

And 'sleep' is the devil. :mad:

Kristi 06-01-2007 04:41 PM

Quote:

Originally Posted by DustyPorViva (Post 1312994)
Move keeps the movement of the NPC smooth on the serverside, I don't think there's a way to replicate that.

Yes there is, if you understand what is happening exactly.
What move actually does, like shoot, is run a clientside effect. You are not actually seeing the npcs current position serverside. Many of the new scripts in classic that we do achieve the same thing. The actual visual movement is scripted clientside (to appear smooth), but positioning and other such things are kept serverside. It makes for a much more visuably pleasing effect, and cuts down processing power on this server.

The npc's acutal x,y, after doing a series of moves in the same tic, will be the end result. if you try to get the position in the same tic (cycle, function, whatever) you used move, it will still be at the origin until the next tic.

DustyPorViva 06-01-2007 06:45 PM

How do you keep it synced with the serverside data though?

Deadly_Killer 06-01-2007 09:02 PM

Quote:

Originally Posted by Cloven (Post 1313658)
And 'sleep' is the devil. :mad:

Yeah.

P.S. How do you send serverside data to a client for a specific npc?

Kristi 06-01-2007 09:25 PM

Quote:

Originally Posted by DustyPorViva (Post 1314123)
How do you keep it synced with the serverside data though?

That would depend on what you want synced ^_^

DustyPorViva 06-01-2007 09:32 PM

Well definitely would be the actual coordinates of the NPC, so players aren't seeing the NPC in two different locations because of local lag.

Kristi 06-01-2007 09:38 PM

Quote:

Originally Posted by DustyPorViva (Post 1314200)
Well definitely would be the actual coordinates of the NPC, so players aren't seeing the NPC in two different locations because of local lag.

even if you were moving it manually, the players dont always see it in the same position due to local lag. you have to go under the good faith assumption that if a player is lagging, then he gets other player data & npc server data at relatively the same time.


All times are GMT +2. The time now is 04:11 PM.

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