Graal Forums

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

blackbeltben 08-08-2011 08:50 PM

simple movement help.
 
Hi forums. I am trying to make a simple movement system where i can move left and right. and that's it.
Ill show what i have but can some one please modify because it seems buggy and the movement is not as instant as the default one. Also, if someone could add the tile detection so he can't walk though walls that'd be great.
Please explain also, as I am trying to take not and learn.


//#CLIENTSIDE
function onCreated()
{
canmove = 1;
disabledefmovement;
}

function onKeyPressed(temp.code, temp.key, temp.scan)
{
if (canmove = 1)
{
if (keydown(3))
{
player.x +=0.3;
player.dir = 3;
setAni("walk", NULL);
setTimer(0.3);
} else if (keydown(1)){
player.x -=0.3;
player.dir = 1;
setAni("walk", NULL);
setTimer(0.3);
}
}
}

function onTimeOut()
{
setAni("idle", NULL);
}

Emera 08-08-2011 08:52 PM

PHP Code:

function onTimeOut()
{
setAni("idle"NULL);


I don't know if this is the problem, but dont you need a timer set here...
PHP Code:

function onTimeOut()
{
setAni("idle"NULL);
setTimer(0.05);


I am no expert, but I am almost completely sure you need a timer set there.

fowlplay4 08-08-2011 09:16 PM

Quote:

Originally Posted by Emera (Post 1662531)
I am no expert, but I am almost completely sure you need a timer set there.

Only if you need the loop to continue. If you don't understand what it does, you probably shouldn't give advice on it.

I've restyled your code to the same standard nearly everyone else follows on these forums and placed comments above the lines that may have been causing problems.

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
// You need to use 'this.' otherwise the variable is global
  // and may conflict with future scripts.
  
this.canmove 1;
  
// GS2-Equivalent of disabledefmovement;
  // Mixing GS2 and GS1 is bad.
  
disabledefmovement();
}

function 
onKeyPressed(temp.codetemp.keytemp.scan) {
  
// You need to use two ='s to do a comparison
  // When you use one = it is an assignment. I.e: Assigning 1 to canmove
  // The comparison checks if this.canmove equals 1.
  
if (this.canmove == 1) {
    
// The code below is fine
    
if (keydown(3)) {
      
player.+=0.3;
      
player.dir 3;
      
setani("walk"NULL);
      
setTimer(0.3);
    } else if (
keydown(1)) {
      
player.-=0.3;
      
player.dir 1;
      
setani("walk"NULL);
      
setTimer(0.3);
    }
  }
}

function 
onTimeout() {
  
setani("idle"NULL);


You can use onwall(x,y) and onwall2(x,y,width,height) to check for walls. I.e:

PHP Code:

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

function 
movePlayer() {
  
temp.new_x player.0.3;
  
temp.new_y player.y;
  if (!
onwall(temp.new_xtemp.new_y)) {
    
player.temp.new_x;
    
player.temp.new_y;
  }



blackbeltben 08-08-2011 09:26 PM

OK. So here is an update of the script. the colliding of walls does still not work. Im using onwall2 because i am using the "era" tile template. (not actually using those tiles, just the tile setup where they are) and also, there is a delay on the movement. you have to hold the key for a second for the movement to actually work.


//#CLIENTSIDE
function onCreated()
{
movePlayer();
this.canmove = 1;
disabledefmovement();
}

function onKeyPressed(temp.code, temp.key, temp.scan)
{
if (this.canmove == 1)
{
if (keydown(3))
{
player.x +=0.3;
player.dir = 3;
setAni("walk", NULL);
setTimer(0.5);
} else if (keydown(1)){
player.x -=0.3;
player.dir = 1;
setAni("walk", NULL);
setTimer(0.5);
}
}
}

function onTimeOut()
{
setAni("idle", NULL);
}

function movePlayer(){
temp.new_x = player.x +0.3;
temp.new_y = player.y;
if (!onwall2(temp.new_x, temp.new_y)) {
player.x = temp.new_x;
player.y = temp.new_y;
}
}

fowlplay4 08-08-2011 09:30 PM

My example wasn't something you could just paste in, you have to use it in your movement code. Also please put your code in PHP tags so it's easier to read.

blackbeltben 08-08-2011 09:44 PM

I didn't just paste it in :/
I'll figure it out i guess. But how do you do PHP tags, Im new to forums.

callimuc 08-08-2011 10:15 PM

1. For me it seems like you will do a detection for each arrow key you press. Probably it´s good for the beginning learning it but I´d take a look at this.
It´s an easy and short movement script where I´m sure you can learn good from.

2.
PHP Code:

onwallx)                         the specified field is blocked
onwall2
xy,width,height )        the specified field is blocked (server-side

3.
Quote:

Originally Posted by blackbeltben (Post 1662536)
do you do PHP tags

Just go to "Go advanced" next to the "Post quick reply". Than you see at the top of the text field some options and just go to the one saying (very small) php on a "sheet of paper".

Emera 08-08-2011 10:22 PM

Quote:

Only if you need the loop to continue. If you don't understand what it does, you probably shouldn't give advice on it.
Just trying to help I guess.


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

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