Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Moving objects (https://forums.graalonline.com/forums/showthread.php?t=134259209)

xAndrewx 05-16-2010 11:32 PM

Moving objects
 
Pretty straight forward- a way to move objects (serverside). Checks for the players new position on a wall, the npc's new position on a wall & detects over NPC's that the object has been moved.

HTML Code:

function onCreated() {
    //Players are not counted as a wall (in the onwall)
  this.noplayeronwall();

    //Let's just set the shape clientside, I used 0 as the tokenize
    //For some weird reason, it wouldn't allow anything but numbers?
    //Maybe convert to an attribute if causes any problems (shouldn't...)
  temp.d = this.n_shape[0] @ "0" @ this.n_shape[1];
  save[1] = temp.d;
 
  this.setShape(1, 16 * this.n_shape[0], 16 * this.n_shape[1]);
}

  //If it's been pulled
function onActionPulled(dir) {
  this.onMove(temp.dir);
}

  //If it's been pushed
function onActionPushed(dir) {
  this.onMove(temp.dir);
}

  //If it's been hit (was testing)
function onWa****() {  //Change to  Was Hit  (Doesn't seem to be working correctly)
  this.onMove(player.dir);
}

function onMove(dir) {
  temp.dir = (wa****? player.dir: temp.dir);
 
    //Is the npc pulled by the player?
  temp.pulled = (player.ani == "pull"? 0.4:0);
   
    //Find the position of the player once moved
  if (temp.dir in {1, 3}) {
    temp.p_x = player.x + vecx(temp.dir) * (0.6 + temp.pulled);
    temp.p_y = player.y;
  } else {
    temp.p_x = player.x;
    temp.p_y = player.y + vecy(temp.dir) * (0.6 + temp.pulled);
  }
 
   
    //Player's on a wall, if so don't move!
  if (onwall2(temp.p_x, temp.p_y, 2, 3)) return;


    //Let's find the new position for the npc
  temp.n_x = this.x + vecx(temp.dir) * 1;
  temp.n_y = this.y + vecy(temp.dir) * 1;
 
    //Check if there is a wall there (we don't want that)
  if (!onwall2(temp.n_x, temp.n_y, this.n_shape[0], this.n_shape[1])) {

      //Change the position of the object
    this.x = temp.n_x;
    this.y = temp.n_y;
   
      //Do the direction stuff (to move the object)
    player.x = temp.p_x;
    player.y = temp.p_y;
   
       
      //Find the other npc's it's around
      //This is to find if you need to move the object
      //over a certain area.
      //Make sure the class is called "temp_moveablecheck"
    for (temp.i: level.findareanpcs(this.x, this.y, 1, 1)) {
      if (!temp.i.isinclass("temp_moveablecheck")) continue;
     
      temp.i.trigger("onObjectOver", this);
        //Inside this (temp_moveablecheck), you add the function
        //  function onObjectOver(npc) {
        //You can do funky cool stuff to, so if you wanted
        //a specific npc to be over a specific area, you'd add
        //the flag to this npc when you join it, something like
        //    this.object_name = "MiddlePiller";
        //You can then from the class (temp_moveablecheck) check
        //to see if that specific object is over

        //  function onObjectOver(npc) {
        //    if (temp.npc.object_name == "MiddlePiller") {
       
    }


   
  }
}

//#CLIENTSIDE
function onCreated() {
  temp.s = save[1].pos(0);
  this.setShape(1, 16 * save[1].substring(0, temp.s), 16 * save[1].substring(temp.s + 1));
}

To add this, just create an NPC with this script

HTML Code:

function onCreated() {
  this.n_shape = {2, 2}; //32x32
  this.join("npc name here");
}

have fun ^^

DrakilorP2P 05-17-2010 04:55 PM

I don't understand what it does.
And your code was censored.

fowlplay4 05-17-2010 05:16 PM

Looks like a push/pull block basically, which I think would require a custom push/pull system.

xAndrewx 05-17-2010 06:30 PM

Quote:

Originally Posted by fowlplay4 (Post 1576878)
Looks like a push/pull block basically, which I think would require a custom push/pull system.

Nope- uses default :)

fowlplay4 05-17-2010 07:09 PM

Quote:

Originally Posted by xAndrewx (Post 1576885)
Nope- uses default :)

Neat.

coreys 05-17-2010 07:36 PM

Yeah, you gotta replace the censored function names with the 'was hit' event name, since the forums censor it. (It's not swear evasion, I promise, don't give me an infraction Darlene!)

xAndrewx 05-17-2010 07:38 PM

Quote:

Originally Posted by coreys (Post 1576909)
Yeah, you gotta replace the censored function names with the 'was hit' event name, since the forums censor it. (It's not swear evasion, I promise, don't give me an infraction Darlene!)

Haha, doh I saw the first post and replied, forgot to mention it :(
dur snk dur dur


All times are GMT +2. The time now is 06:57 AM.

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