Graal Forums

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

callimuc 03-07-2011 11:23 PM

disable onPlayerTouchsMe()
 
When I want a script to do something I simply use:
PHP Code:

function onPlayerTouchsMe() {
//dostuff


but how can I make it that if the player doesnt touch the npc anymore, it will stop? Like:
PHP Code:

function onPlayerTouchsMe() {
setcharani("walk",null);
}
//Now the command/script I would need here. Invented one for example
function onPlayerStopsTouchingMe() {
setcharani("idle",null);


I just know the
PHP Code:

function onPlayerTouchsOther() {
//dostuff


but than it will make it only, if I touch other NPC´s.

xAndrewx 03-07-2011 11:29 PM

Quite vague, what're you wanting it to do exactly? You do know if you touch it, you touch it alot of times? I don't know of this would work...

HTML Code:

function onPlayerTouchsMe() {
  this.ani = "walk";
 
  cancelevents("onFinishTouch");
  scheduleevent(0.2, "onFinishTouch", "");
}

function onFinishTouch() {
  this.ani = "idle";
}

It will run "onFinishTouch" 0.2 seconds after the NPC was touched. Reduce time if needed- don't use it serverside (if possible)

fowlplay4 03-07-2011 11:30 PM

There is no "Stops Touching Me" event, depending on the situation I would do something like this:

PHP Code:

function onPlayerTouchsMe() { 
  if (
this.ani != "walk"this.setcharani("walk",null);
  
setTimer(0.25); 
}

function 
onTimeout() {
  
this.setcharani("idle""");


Provided the player continues to touch the NPC it won't timeout (because it will keep getting reset to 0.25) and go to the idle position. Maybe adjust the timer to suit your needs though.

Edit: Well... Timeout, scheduleevent, same difference.

callimuc 03-07-2011 11:45 PM

Hmm well both won´t work.

Quote:

Originally Posted by xAndrewx (Post 1635118)
Quite vague, what're you wanting it to do exactly

I´m trying to make a railroad script :). I´m sure there is a way more easier way, but I wanted to do it like when the player touches it, it will move the playerx, and if the player doesn´t touch it anymore, it will stop moving the player :/

Or is there maybe an easier way with the moving of the player?

cbk1994 03-07-2011 11:52 PM

Sounds like you want to disable default movement and rescript it using GraalControl.onKeyDown/onKeyUp or if (keydown(key)).

callimuc 03-07-2011 11:54 PM

Quote:

Originally Posted by cbk1994 (Post 1635125)
Sounds like you want to disable default movement and rescript it using GraalControl.onKeyDown/onKeyUp or if (keydown(key)).

jea

MrOmega 03-08-2011 12:01 AM

use a timeout and use checks

PHP Code:

function onCreated()
{

  
this.width = <WIDTH>; //In Tiles
  
this.height = <HEIGHT>; //In Tiles
  
onTimeout();

}

function 
onTimeout()
{

  if ( 
player.1.5 in this.xthis.width| &&
       
player.2.0 in this.ythis.height| &&
       !
this.touch)
  {

    
this.touch true;
    
//Touch Actions

  
}

  if ( !( 
player.1.5 in this.xthis.width|) &&
       !( 
player.2.0 in this.ythis.height|) &&
       
this.touch)
  {

    
this.touch false;
    
//Stop Touch Actions

  
}

  
setTimer0.1);



replace <WIDTH> and <HEIGHT> with the NPCs width and height in tiles, not pixels. ( 1 pixel would equal ( 1 / 16), btw)

callimuc 03-08-2011 12:04 AM

Hmm I guess I found something similiar. Didn´t test it yet but from looking around in the forums I got this idea (first off player moves from alone to the right):
PHP Code:

//#CLIENTSIDE
function onCreated() {
this.image "myimage.png";
}
function 
onPlayerTouchsme() {
  if (
player.dir 2) {
    if (
playerx in |getimgwidththis.image)| && playery in |getimgheightthis.image)|) {
    
settimer("0.1");
    }
if (!
playerx in |getimgwidththis.image)| && !playery in |getimgheightthis.image)|) {
    
settimer("0");
    }
  }
}
function 
onTimeout() {
  
playerx += 1;
  
settimer("0.1");


EDIT: added if the player isn´t inside the picture

fowlplay4 03-08-2011 12:28 AM

Keep in mind:

player.x is a tile-based coordinate, and getimgwidth is by pixels. 1 tile width/height = 16 pixels.

therefore... tile width = (pixels / 16)

callimuc 03-08-2011 01:03 AM

Quote:

Originally Posted by fowlplay4 (Post 1635135)
Keep in mind:

player.x is a tile-based coordinate, and getimgwidth is by pixels. 1 tile width/height = 16 pixels.

therefore... tile width = (pixels / 16)

and what about:

getimgwidth( this.image)/16 :confused:

fowlplay4 03-08-2011 01:08 AM

Quote:

Originally Posted by callimuc (Post 1635148)
getimgwidth( this.image)/16 :confused:

That's how you would do it. Honestly your script isn't making much sense.

callimuc 03-08-2011 01:30 AM

Hehe I´m testing around with commands and so on.


All times are GMT +2. The time now is 11:42 AM.

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