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
