Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-16-2010, 11:32 PM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
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
__________________

Last edited by xAndrewx; 05-17-2010 at 07:46 PM..
Reply With Quote
  #2  
Old 05-17-2010, 04:55 PM
DrakilorP2P DrakilorP2P is offline
Registered User
DrakilorP2P's Avatar
Join Date: Apr 2006
Posts: 755
DrakilorP2P is just really niceDrakilorP2P is just really nice
I don't understand what it does.
And your code was censored.
Reply With Quote
  #3  
Old 05-17-2010, 05: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
Looks like a push/pull block basically, which I think would require a custom push/pull system.
__________________
Quote:
Reply With Quote
  #4  
Old 05-17-2010, 06:30 PM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
Quote:
Originally Posted by fowlplay4 View Post
Looks like a push/pull block basically, which I think would require a custom push/pull system.
Nope- uses default
__________________
Reply With Quote
  #5  
Old 05-17-2010, 07:09 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 xAndrewx View Post
Nope- uses default
Neat.
__________________
Quote:
Reply With Quote
  #6  
Old 05-17-2010, 07:36 PM
coreys coreys is offline
N-Pulse Assistant Manager
coreys's Avatar
Join Date: Mar 2005
Posts: 2,180
coreys has a spectacular aura about
Send a message via AIM to coreys Send a message via MSN to coreys Send a message via Yahoo to coreys
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!)
__________________

Quote:
*SlikRick: so should I even ask about your aim status?
*Xor: well if you want to
*Xor: but i am LARPING
*SlikRick: While on a computer?
*Xor: yes
*Xor: in my living room
*SlikRick: ahh
*Xor: i have a fort setup to hide from beasts
Reply With Quote
  #7  
Old 05-17-2010, 07:38 PM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
Quote:
Originally Posted by coreys View Post
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
__________________
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 07:25 PM.


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