Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-22-2007, 01:40 AM
DrakilorP2P DrakilorP2P is offline
Registered User
DrakilorP2P's Avatar
Join Date: Apr 2006
Posts: 755
DrakilorP2P is just really niceDrakilorP2P is just really nice
Point n click movement system

This script implements a Diablo 2 style movement system. You click on a location and the player will attempt to move there. Included is acceleration and friction, which are configurable from onCreated().
This script used to have stamina and walking/running, but I removed it since most people would probably want to implement their own such system anyway (And to avoid bloating the script with features no one will use which only make it harder to read.).

Here's some documentation to help you expand it if necessary.

onCreated():
  • Variable initialisation.
onTimeout():
  • Acceleration, friction and movement.
SetTarget(x, y):
  • Properly sets this.target.[x/y] which is where the player will accelerate towards.
Accelerate(xspeed, yspeed, maxspeed):
  • Properly increases this.speed.[x/y] to avoid accelerating further than maxspeed.
Move(x, y):
  • Moves the player with block detection.
Distance(x, y):
  • Helper function; returns distance between (0, 0) and (x, y).

Installation: Used as a weapon.
PHP Code:
//#CLIENTSIDE

//**************************************************
function onCreated()
{
  
this.baseSpeed 8;
  
this.acceleration 4;
  
this.baseFriction 0.5;
  
  
this.target.player.1.5;
  
this.target.player.2;
  
  
onTimeout();
}


//**************************************************
function onTimeout()
{
  
// *****Set target position so we know where to move
  
if (leftmousebutton) {
    
SetTarget(mousexmousey);
  }
  
  
// *****Friction (We aren't walking on ice)
  
this.speed.*= this.baseFriction;
  
this.speed.*= this.baseFriction;
  
  
// *****Accelerate so we'll eventually reach that target position.
  
if (Distance(this.target.player.1.5this.target.player.2) > && !this.stopped) {
    
temp.angle getangle(this.target.player.1.5this.target.player.2);
    
temp.speed.cos(temp.angle) * this.acceleration;
    
temp.speed.= -sin(temp.angle) * this.acceleration;
    
    
Accelerate(temp.speed.xtemp.speed.ythis.baseSpeed);
    
    
setani("walk""");
  }
  else
  {
    if (
this.speed.0.5 && this.speed.> -0.5this.speed.0;
    if (
this.speed.0.5 && this.speed.> -0.5this.speed.0;
    
this.stopped true;
    
setani("idle""");
  }
  
  
// *****Actually move the player according to current speed.
  
Move(this.speed.xthis.speed.y);
  if (
this.speed.!= && this.speed.!= 0player.dir getdir(this.speed.xthis.speed.y);

  
setTimer(0.05);
}


//**************************************************
function onMouseDown(button)
{
  
// Set target position so we know where to move.
  
if (button == "left") {
    
SetTarget(mousexmousey);
  }
}


//**************************************************
// Set the position the system will try to reach.
function SetTarget(targetxtargety)
{
    if (
Distance(targetx player.1.5targety player.2) > 1) {
      
this.target.targetx;
      
this.target.targety;
      
this.stopped false;
    }
}


//**************************************************
// Increase the speed in pixels per frame.
function Accelerate(xSpeedySpeedmaxSpeed)
{
  if (
Distance(this.speed.xthis.speed.y) < maxSpeed || (Distance(this.speed.xSpeedthis.speed.ySpeed) - Distance(this.speed.xthis.speed.y)) <= 0) {
    
this.speed.+= xSpeed;
    
this.speed.+= ySpeed;
    
    if (
Distance(this.speed.xthis.speed.y) > maxSpeed) {
      
temp.angle getangle(this.speed.xthis.speed.y);
      
this.speed.cos(temp.angle) * maxSpeed;
      
this.speed.= -sin(temp.angle) * maxSpeed;
    }
  }
}


//**************************************************
// Move the player by specified amount of pixels.
function Move(xSpeedySpeed)
{
  if (!
isapplicationactive) return;
  
  
xSpeed xSpeed<0?int(xSpeed)+1:int(xSpeed);
  
ySpeed ySpeed<0?int(ySpeed)+1:int(ySpeed);
  
  
// --- 'x' movement of the player --- \\
  
if (xSpeed != 0) {
    
temp.int(player.16);
    
temp.xDir = (abs(xSpeed) / xSpeed);
    for (
i=0i<abs(xSpeed); i++) {
      if (!
onwall2(temp.16 temp.xDir * (1/16), player.211)) temp.+= temp.xDir;
      else break;
    }
    
player.temp.16;
  }
  
  
// --- 'y' movement of the player --- \\
  
if (ySpeed != 0) {
    
temp.int(player.16);
    
temp.yDir = (abs(ySpeed) / ySpeed);
    for (
i=0i<abs(ySpeed); i++) {
      if (!
onwall2(player.1temp.16 temp.yDir * (1/16), 11)) temp.+= temp.yDir;
      else break;
    }
    
player.temp.16;
  }
  
  
//Hack
  
if (tiletype(player.1.5player.2) == 3) {
    
setani("sit""");
  }
}


//**************************************************
//Calculate the distance between (0, 0) and (dx, dy).
function Distance(dxdy)
{
  return ((
dx)^+ (dy)^2)^0.5

Reply With Quote
  #2  
Old 03-22-2007, 02:35 AM
Angel_Light Angel_Light is offline
Varia Developer
Angel_Light's Avatar
Join Date: Nov 2005
Location: Knoxville, TN
Posts: 1,684
Angel_Light is on a distinguished road
Send a message via AIM to Angel_Light Send a message via MSN to Angel_Light
awesome ^_^
__________________
Deep into the Darkness peering...
Reply With Quote
  #3  
Old 03-22-2007, 02:48 AM
Rapidwolve Rapidwolve is offline
Registered User
Join Date: Jul 2006
Posts: 1,241
Rapidwolve is an unknown quantity at this point
Nice
Reply With Quote
  #4  
Old 03-22-2007, 03:15 AM
theHAWKER theHAWKER is offline
**FLIP OUT**
theHAWKER's Avatar
Join Date: Mar 2006
Location: canada, vancouver
Posts: 768
theHAWKER is an unknown quantity at this point
where do u put this script? in weapons?
__________________
**FLIP OUT**
Reply With Quote
  #5  
Old 03-22-2007, 03:49 AM
Switch Switch is offline
o.o
Switch's Avatar
Join Date: Jan 2007
Location: Philadelphia
Posts: 3,038
Switch has a spectacular aura about
Send a message via MSN to Switch
It looks good. Doesn't work on servers O.o
__________________
Oh squiggly line in my eye fluid. I see you lurking there on the peripheral of my vision.
But when I try to look at you, you scurry away.
Are you shy, squiggly line?
Why only when I ignore you, do you return to the center of my eye?
Oh, squiggly line, it's alright, you are forgiven.
Reply With Quote
  #6  
Old 03-22-2007, 04:12 AM
killerogue killerogue is offline
Registered Omega
killerogue's Avatar
Join Date: Apr 2006
Location: United States
Posts: 1,920
killerogue is on a distinguished road
Send a message via AIM to killerogue Send a message via MSN to killerogue
Quote:
Originally Posted by theHAWKER View Post
where do u put this script? in weapons?
Damn, GS1 using....UIGGGHGHGSDNGSK

Quote:
Originally Posted by Switch View Post
It looks good. Doesn't work on servers O.o
It works on Mythic so YOU must've ****ed it up.
__________________


REMEMBER, IF YOU REP ME, LEAVE A NAME!

Quote:
Originally Posted by haunter View Post
Graal admins don't die. They go to hell and regroup.
Quote:
Originally Posted by Inverness View Post
Without scripters, your graphics and levels wouldn't do anything but sit there and look pretty.
Reply With Quote
  #7  
Old 03-22-2007, 04:37 AM
Twinny Twinny is offline
My empire of dirt
Twinny's Avatar
Join Date: Mar 2006
Location: Australia
Posts: 2,422
Twinny is just really niceTwinny is just really nice
Send a message via AIM to Twinny
Quote:
Originally Posted by DrakilorP2P View Post
You click on a location and the player will attempt to move there.
Haha one part of my master plan has been taken . I wanted to make a point and click styled system like Monkey Island.
Reply With Quote
  #8  
Old 03-22-2007, 09:47 AM
DrakilorP2P DrakilorP2P is offline
Registered User
DrakilorP2P's Avatar
Join Date: Apr 2006
Posts: 755
DrakilorP2P is just really niceDrakilorP2P is just really nice
More precise installation instructions:
1. Get access to a server using GS2.
2. Insert the script as a "weapon". For example: System/Movement.
3. Add the weapon to your account, or add a script that automatically adds it when a player connect.

Quote:
Originally Posted by Twinny View Post
Haha one part of my master plan has been taken . I wanted to make a point and click styled system like Monkey Island.
You can view it in two ways:
1. Part of your master plan was taken.
or 2. Someone wrote the script for you.
Reply With Quote
  #9  
Old 03-22-2007, 11:01 AM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Thats right folks! Now YOUR server can have a small part of Mythic on them!
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #10  
Old 03-22-2007, 03:13 PM
Twinny Twinny is offline
My empire of dirt
Twinny's Avatar
Join Date: Mar 2006
Location: Australia
Posts: 2,422
Twinny is just really niceTwinny is just really nice
Send a message via AIM to Twinny
Quote:
Originally Posted by DrakilorP2P View Post
You can view it in two ways:
1. Part of your master plan was taken.
or 2. Someone wrote the script for you.
I'd have to write a pretty damn good pathfinding system for mine...or get some unlucky LAT to map out possible paths in each level . I suppose you could write a spider to scan all possible paths then save them to a database...hmm...
Reply With Quote
  #11  
Old 03-22-2007, 10:20 PM
Angel_Light Angel_Light is offline
Varia Developer
Angel_Light's Avatar
Join Date: Nov 2005
Location: Knoxville, TN
Posts: 1,684
Angel_Light is on a distinguished road
Send a message via AIM to Angel_Light Send a message via MSN to Angel_Light
Links don't work with this, nor does onPlayerTouchsMe() :| Gotta make some checks and so forth, works well on a gmap =D
__________________
Deep into the Darkness peering...
Reply With Quote
  #12  
Old 03-22-2007, 10:37 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Quote:
Originally Posted by Switch View Post
It looks good. Doesn't work on servers O.o
Pretty nice script! I checked it, looks pretty cool. I got no server to test it atm though :/

Edit: Correction: I actually got one, but my RC seems to be totally ****ed up.

Last edited by Skyld; 03-22-2007 at 11:52 PM.. Reason: Now now, children.
Reply With Quote
  #13  
Old 03-22-2007, 11:19 PM
Switch Switch is offline
o.o
Switch's Avatar
Join Date: Jan 2007
Location: Philadelphia
Posts: 3,038
Switch has a spectacular aura about
Send a message via MSN to Switch
Quote:
Originally Posted by Crow View Post
Pretty nice script! I checked it, looks pretty cool. I got no server to test it atm though :/

Edit: Correction: I actually got one, but my RC seems to be totally ****ed up.
I happen to OWN a server and I put it on to test it and it DIDN'T work. AND I had one of my GATs test it RIGHT now. It ALSO didn't work.
__________________
Oh squiggly line in my eye fluid. I see you lurking there on the peripheral of my vision.
But when I try to look at you, you scurry away.
Are you shy, squiggly line?
Why only when I ignore you, do you return to the center of my eye?
Oh, squiggly line, it's alright, you are forgiven.

Last edited by Skyld; 03-22-2007 at 11:51 PM.. Reason: Now now, children.
Reply With Quote
  #14  
Old 03-22-2007, 11:41 PM
Twinny Twinny is offline
My empire of dirt
Twinny's Avatar
Join Date: Mar 2006
Location: Australia
Posts: 2,422
Twinny is just really niceTwinny is just really nice
Send a message via AIM to Twinny
Did you add the weapon to yourselves?
Reply With Quote
  #15  
Old 03-23-2007, 12:48 AM
Angel_Light Angel_Light is offline
Varia Developer
Angel_Light's Avatar
Join Date: Nov 2005
Location: Knoxville, TN
Posts: 1,684
Angel_Light is on a distinguished road
Send a message via AIM to Angel_Light Send a message via MSN to Angel_Light
Quote:
Originally Posted by Switch View Post
I had one of my GATs test it RIGHT now. It ALSO didn't work.
GAT != NAT

lol

EDIT: How would I reset setTarget()? I've tried a few different method but the player spazzes out or just head north east. :/ Also I tried to make it so the players normal movement isnt afftected by this aswell and failed... any pointers to get me started?
__________________
Deep into the Darkness peering...

Last edited by Angel_Light; 03-23-2007 at 01:17 AM..
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:09 AM.


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