Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 08-08-2011, 08:50 PM
blackbeltben blackbeltben is offline
Registered User
Join Date: Aug 2011
Posts: 83
blackbeltben is on a distinguished road
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);
}
Reply With Quote
  #2  
Old 08-08-2011, 08:52 PM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
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.
__________________
Reply With Quote
  #3  
Old 08-08-2011, 09:16 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by Emera View Post
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;
  }

__________________
Quote:
Reply With Quote
  #4  
Old 08-08-2011, 09:26 PM
blackbeltben blackbeltben is offline
Registered User
Join Date: Aug 2011
Posts: 83
blackbeltben is on a distinguished road
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;
}
}
Reply With Quote
  #5  
Old 08-08-2011, 09:30 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
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.
__________________
Quote:
Reply With Quote
  #6  
Old 08-08-2011, 09:44 PM
blackbeltben blackbeltben is offline
Registered User
Join Date: Aug 2011
Posts: 83
blackbeltben is on a distinguished road
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.
Reply With Quote
  #7  
Old 08-08-2011, 10:15 PM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
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 View Post
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".
__________________
MEEP!
Reply With Quote
  #8  
Old 08-08-2011, 10:22 PM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
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.
__________________
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 02:47 AM.


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