Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 02-03-2010, 10:21 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Movement/Wall Detection for Variable sizes

A small script I threw together to show how you can create a movement system with various speeds(without skipping over walls), and more importantly: various sizes. This means you can shrink your player down to 1 tile and squeeze through cracks, or apply a better wall detection to larger players. What it is lacking is detail to anything else but those two things. It initially started as an experiment with onwall2 for a solid wall detection(instead of lots of onwall()'s), and I decided to add size support later. Lacks important things like sliding around corners, but that's not what this is focused on.

Graal Script Code:
function onCreated() {
  
clientr.movementSpeed .5;
  
clientr.movementSize 2;
}
//#CLIENTSIDE
function onCreated() {
  
showstats(1024);
  
disabledefmovement();
  
clientr.movementSpeed .5;
  
clientr.movementSize 2;
  
player.int(player.x)+.5;
  
player.int(player.y);

  
setTimer(0.05);
}

function 
onTimeout() {
  
temp.speed clientr.movementSpeed;
  
temp.size clientr.movementSize;
  
player.zoom size/2;
  for (
temp.k=0;k<4;k++) {
    if (
keydown(k)) {
      
player.dir k;

      
temp.cx = (player.x+.5)-((size 2)/2);
      
temp.cy = (player.y+1)-((size 2)/2);

      
temp.horizontalwall onwall2(cx vecx(k)*speed,cy,size-1/16,size-1/16);
      
temp.verticalwall onwall2(cx,cy vecy(k)*speed,size-1/16,size-1/16);

      if (
horizontalwall == 0player.+= vecx(k)*speed;
      else {
        for (
i=0;i<(speed client.size speed size);i+=1/16) {
          if (
onwall2(cx+vecx(k)*i,cy,size-1/16,size-1/16)) {
            
player.+= vecx(k)*i;
            
player.int(playerx+((size%== 1)*.5))+((size%== 0)*.5);
            break;
          }
        }
      }
      if (
verticalwall == 0player.+= vecy(k)*speed;
      else {
        for (
i=0;i<(speed size speed size);i+=1/16) {
          if (
onwall2(cx,cy+vecy(k)*i,size-1/16,size-1/16)) {
            
player.+= vecy(k)*i;
            
player.int(playery+((size%== 0)*.5))+((size%== 1)*.5);
            break;
          }
        }
      }
    }
  }
  
showpoly 200,{
    (
player.x+.5)-((size 2)/2),(player.y+1)-((size 2)/2),
    (
player.x+.5)-((size 2)/2)+size,(player.y+1)-((size-2)/2),
    (
player.x+.5)-((size 2)/2)+size,(player.y+1)-((size-2)/2)+size,
    (
player.x+.5)-((size 2)/2),(player.y+1)-((size 2)/2)+size,
    (
player.x+.5)-((size 2)/2),(player.y+1)-((size 2)/2),
    (
player.x+.5)-((size 2)/2),(player.y+1)-((size 2)/2)+(1/16),
    (
player.x+.5)-((size 2)/2)+size-(1/16),(player.y+1)-((size 2)/2)+(1/16),
    (
player.x+.5)-((size 2)/2)+size-(1/16),(player.y+1)-((size 2)/2)+size-(1/16),
    (
player.x+.5)-((size 2)/2)+(1/16),(player.y+1)-((size 2)/2)+size-(1/16),
    (
player.x+.5)-((size 2)/2)+(1/16),(player.y+1)-((size 2)/2)+(1/16)
  };
  
setTimer(0.05);
}

function 
onPlayerChats() {
  if (
player.chat.starts("size")) {
    
temp.newsize player.chat.substring(5);
    if (
newsize >= && newsize <= 20clientr.movementSize newsize;
    else if (
newsize 20player.chat "Seriously, are you nuts?";
    else 
player.chat "Not a compatible size!";
  } else if (
player.chat.starts("speed")) {
    
temp.newspeed player.chat.substring(6);
    if (
newspeed 0clientr.movementSpeed newspeed;
  }

Video as soon as I can get it uploaded without my internet timing out.
Attached Thumbnails
Click image for larger version

Name:	graal_1265184469.png
Views:	99
Size:	8.2 KB
ID:	50361   Click image for larger version

Name:	graal_1265184454.png
Views:	124
Size:	6.8 KB
ID:	50362   Click image for larger version

Name:	graal_1265184445.png
Views:	126
Size:	6.6 KB
ID:	50363  

Last edited by DustyPorViva; 02-04-2010 at 08:00 AM..
Reply With Quote
  #2  
Old 02-03-2010, 03:42 PM
Imperialistic Imperialistic is offline
graal player lord
Imperialistic's Avatar
Join Date: Apr 2007
Location: Florida
Posts: 1,093
Imperialistic is a jewel in the roughImperialistic is a jewel in the rough
please donate this script to UN, they need it.

Anyways great job dusty, I'm loving the work lately.
__________________
" It's been swell, but the swelling's gone down. "
Reply With Quote
  #3  
Old 02-03-2010, 04:18 PM
Chompy Chompy is offline
»\(║_o)/»
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by Imperialistic View Post
please donate this script to UN, they need it.

Anyways great job dusty, I'm loving the work lately.
Why just UN? Placing this in the code gallery would help many, instead of just one server. UN can just get the script from the code gallery, so that's not a problem if they need it.

Great script Dusty, could have an awesome use for server having interesting quests, like drinking an elixir to become smaller or something like that.
__________________
Reply With Quote
  #4  
Old 02-03-2010, 10:10 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Oh, this should be moved to the code gallery, my bad!
Reply With Quote
  #5  
Old 02-04-2010, 12:01 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
How I did the movement on Classic was by having a function that works a long a "primary axis". That could be x-axis, y-axis, or say 45deg.

Then it moves along that access, then when it encounters a wall in its path, it will slide perpendicular to the primary axis.

I made it even more complex (for the sake of efficiency), by doing a conquer-and-divide algorithm along the movement path. With built-in onwall() and onwall2() it literally had 0% impact on CPU. With our scripted onwall (i.e., loop through every player, npc, blocking tile and check if they are blocking & intersect), it matched default performance.

Getting it pixel perfect was a little annoying, but the script came out nicely in the end (probably about 200 lines if all the extra documentation and lines were removed). It supports variable speeds and sizes as well.

I might release it in Code Gallery at some point, but it'd require some cleaning up so it wouldn't rely on some of the other systems we have on Classic, so that is a project for when I have free time.
Reply With Quote
  #6  
Old 02-04-2010, 12:10 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Well making sliding isn't that hard, especially in GS2 since I can use passing parameters to simply make a function that checks for a wall in a given direction, making it much simpler to do accurate wall sliding. Maybe I'll add that later.
Reply With Quote
  #7  
Old 02-04-2010, 07:27 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
I <3 you Dusty....saved me a hell of alot of effort.

p.s.
Graal Script Code:
     else if (newsize 20player.chat "Seriously, are you nuts?" 
needs a semicolon

p.p.s

If you do add sliding, I will love you even more =)

p.p.p.s

On further usage, it doesn't seem very smooth. I also found it suffered the same problem I had whereby faster speeds can cause you to jump obstacles... it was this problem that caused me to delay working on it since it was either efficiency or accuracy

Last edited by Twinny; 02-04-2010 at 07:38 AM..
Reply With Quote
  #8  
Old 02-04-2010, 07:59 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Quote:
Originally Posted by Twinny View Post
I <3 you Dusty....saved me a hell of alot of effort.

p.s.
Graal Script Code:
     else if (newsize 20player.chat "Seriously, are you nuts?" 
needs a semicolon

p.p.s

If you do add sliding, I will love you even more =)

p.p.p.s

On further usage, it doesn't seem very smooth. I also found it suffered the same problem I had whereby faster speeds can cause you to jump obstacles... it was this problem that caused me to delay working on it since it was either efficiency or accuracy
I just tested it at size 2, speed 5 and didn't even jump over a 1 tile thick wall. Though I suppose circumstance has a lot to do with it. The wall check is checking the desired position, instead of the space BETWEEN the player and the desired position. So at the speed of 10, at the size of 2, the new position is ahead 10 spaces, and the size is 2 so that's 8 tiles not being checked.

It's a fairly easy fix though, which just involves adding the speed to the size of the onwall2.
Reply With Quote
  #9  
Old 02-04-2010, 01:42 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 DustyPorViva View Post
I just tested it at size 2, speed 5 and didn't even jump over a 1 tile thick wall. Though I suppose circumstance has a lot to do with it. The wall check is checking the desired position, instead of the space BETWEEN the player and the desired position. So at the speed of 10, at the size of 2, the new position is ahead 10 spaces, and the size is 2 so that's 8 tiles not being checked.

It's a fairly easy fix though, which just involves adding the speed to the size of the onwall2.
I found I was able to jump over a tree line whilst moving diagonally but yeah it's exactly the same problem I've had before...I eventually went insane trying to create a method which would check for a wall within your speed, move you right before that wall but still allow for the other axis movement and sliding....it's beyond me
Reply With Quote
  #10  
Old 02-04-2010, 11:37 PM
12171217 12171217 is offline
Banned
Join Date: Jan 2009
Posts: 453
12171217 has a spectacular aura about
Quote:
Originally Posted by Twinny View Post
I found I was able to jump over a tree line whilst moving diagonally but yeah it's exactly the same problem I've had before...I eventually went insane trying to create a method which would check for a wall within your speed, move you right before that wall but still allow for the other axis movement and sliding....it's beyond me
Perhaps you're going so fast that you slide under and around the tree in a single frame?
Reply With Quote
  #11  
Old 02-05-2010, 02:01 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 12171217 View Post
Perhaps you're going so fast that you slide under and around the tree in a single frame?
The area I eventually got into was enclosed
Reply With Quote
  #12  
Old 02-07-2010, 12:10 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
I'm rescripting this from scratch right now. I'm instead breaking the wall detection into 4 quadrants and basing wall collisions off of that. This will make it easier to implement sliding, and easier to handle the wall data.
Reply With Quote
  #13  
Old 02-12-2010, 11:13 AM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
Must say, very impressed. Tho size doesn't show for other players, so I came up with this. Maybe you could impliment something to show size properly in your next rescript?

Graal Script Code:
function onActionServerside() {
  if ( 
params[0] == "size" ) {
    
clientr.movementSpeed .5;
    
clientr.movementSize 2;
  }
  if ( 
params[0] == "getsize" ) {
    
temp.var = findplayerbycommunityname(params[1]).clientr.movementSize;
    
triggerClient("gui"this.name"gotsize"params[1], temp.var);
  }
}
//#CLIENTSIDE
function onCreated() {
  
player.int(player.x)+.5;
  
player.int(player.y);
  
triggerserver"gui"this.name"size"null );
  
setTimer(0.05);
}

function 
onActionClientSide() {
  if ( 
params[0] == "gotsize" ) {
    
findplayerbycommunityname(params[1]).zoom params[2]/2;
  }
}

function 
onTimeout() {
  
temp.speed clientr.movementSpeed;
  
temp.size clientr.movementSize;
  
triggerserver"gui"this.name"getsize" );
  for( 
temp.pl allplayers ) {
    
triggerserver"gui"this.name"getsize"pl.communityname );
  }
  
player.zoom temp.size/2;
  for (
temp.k=0;k<4;k++) {
    if (
keydown(k)) {
      
player.dir k;

      
temp.cx = (player.x+.5)-((size 2)/2);
      
temp.cy = (player.y+1)-((size 2)/2);

      
temp.horizontalwall onwall2(cx vecx(k)*speed,cy,size-1/16,size-1/16);
      
temp.verticalwall onwall2(cx,cy vecy(k)*speed,size-1/16,size-1/16);

      if (
horizontalwall == 0player.+= vecx(k)*speed;
      else {
        for (
i=0;i<(speed client.size speed size);i+=1/16) {
          if (
onwall2(cx+vecx(k)*i,cy,size-1/16,size-1/16)) {
            
player.+= vecx(k)*i;
            
player.int(playerx+((size%== 1)*.5))+((size%== 0)*.5);
            break;
          }
        }
      }
      if (
verticalwall == 0player.+= vecy(k)*speed;
      else {
        for (
i=0;i<(speed size speed size);i+=1/16) {
          if (
onwall2(cx,cy+vecy(k)*i,size-1/16,size-1/16)) {
            
player.+= vecy(k)*i;
            
player.int(playery+((size%== 0)*.5))+((size%== 1)*.5);
            break;
          }
        }
      }
    }
  }
  
setTimer(0.05);

Would love to see some updates/addons to this
Reply With Quote
  #14  
Old 02-12-2010, 02:07 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 scriptless View Post
Must say, very impressed. Tho size doesn't show for other players, so I came up with this. Maybe you could impliment something to show size properly in your next rescript?

Graal Script Code:
 triggerserver"gui"this.name"getsize" ); 
  for( 
temp.pl allplayers ) { 
    
triggerserver"gui"this.name"getsize"pl.communityname ); 
  } 
Would love to see some updates/addons to this
You have suggested that the weapon should trigger the server every 0.05 seconds for the size of allplayers clientside... Imagine Zodiac with 100 people on the server. You would be triggering the server 1 + 100 + amount of people on your buddy list every 0.05 seconds.... bad....

A better way would be to put the players size in an attr[] and simply update the local (someone in a different gmap won't care how the player is being drawn afterall) player's size via some method clientside script (weapon/gani)....

Last edited by Twinny; 02-12-2010 at 02:20 PM.. Reason: further detail!
Reply With Quote
  #15  
Old 02-12-2010, 02:11 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Typically you will use a gani as an attr, with ganiscript in it to handle zoom. You set the script in to one attr, then the size of your player(and other visual aspects like alpha and such, if you'd like) to another attr. Use the ganiscript to parse the other attr and then set the player's effects.

However, it was not my responsibility to do this, as that's not what the script was about
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 11:46 PM.


Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Copyright (C) 1998-2008 Linux cyberjoueurs All Rights Reserved.