Class - gambet_movablefurniture
PHP Code:
//Movable Furniture System
//By: Gambet
function onActionMove()
{
if (this.furniture == NULL)
{
this.furniture = 1;
attr[1] = this.furniture;
this.furniturex = params[0] - x;
this.furniturey = params[1] - y;
move(this.furniturex,this.furniturey,0.5,8);
}
}
function onMovementFinished()
{
this.furniture = NULL;
attr[1] = this.furniture;
attr[2] = x;
attr[3] = y;
}
//#CLIENTSIDE
function onCreated()
{
this.movemode = "Off";
dontblock();
drawunderplayer();
setTimer(0.05);
attr[2] = x;
attr[3] = y;
}
function onMouseDown()
{
if (params[0] == "left")
{
if (this.movemode == "On")
{
setTimer(0.05);
this.tomove = 1;
}
}
}
function onTimeOut()
{
if (player.x+1.5 in |x,x+2| && player.y+2 in |y,y+2|) //Assumes the object is supposed to be sat on
{
if (attr[1] == NULL)
setani("sit","");
}
if (this.tomove == 1)
{
if (this.movemode == "On")
{
if (onwall(mousex,mousey))
{
changeimgcolors(200,2,0,0,1);
this.onwall = "true";
} else
{
changeimgcolors(200,1,1,1,1);
this.onwall = "";
}
showimg(200,image,mousex,mousey);
GraalControl.makefirstresponder(true);
}
}
this.start_x = attr[2];
this.start_y = attr[3];
setTimer(0.05);
}
function onMouseUp()
{
if (this.movemode == "On")
{
if (this.onwall == "true")
{
x = this.start_x;
y = this.start_y;
this.tomove = this.onwall = "";
hideimg(200);
player.chat = "You may not place furniture on walls!";
} else
{
triggeraction(x+0.5,y+0.5,"move",mousex,mousey);
this.tomove = NULL;
hideimg(200);
}
}
}
function onKeyPressed()
{
if (keydown2(keycode(z),true))
{
if (player.chat == this.id)
{
if (this.owner == player.account)
{
if (this.movemode == "Off")
{
this.movemode = "On";
chat = "Move Mode: " @ this.movemode;
HideChat();
} else
{
this.movemode = "Off";
chat = "Move Mode: " @ this.movemode;
HideChat();
}
}
}
}
}
function onPlayerChats()
{
switch(player.chat)
{
case "/furnitureid":
if (this.owner == player.account)
{
chat = "Furniture ID #: " @ this.id;
HideChat();
}
break;
case "/movemode":
if (this.owner == player.account)
{
chat = "Move Mode: " @ this.movemode;
HideChat();
}
break;
case "/furnitureowner":
chat = "My owner is: " @ this.owner;
HideChat();
break;
}
}
function HideChat()
{
sleep(3);
chat = "";
}
Example level NPC:
PHP Code:
join("gambet_movablefurniture");
//#CLIENTSIDE
function onCreated()
{
this.owner = "Gambet";
}
How it works:
Each NPC has its own specific ID, in which case would be the furnitureid of a certain NPC. In order to work this system, you must know the furnitureid of the furniture you own.
To view all furnitureid's of all furniture you own in the level you are currently in, simply say
/furnitureid. Saying this will prompt all furniture that you own in your level to tell you what their corresponding ID is.
Now that you've gotten the basics down on acquiring the furnitureid, you can check to see the 'move mode' of all of your furniture in your level by saying
/movemode. Saying this will promt all furniture that you own in your level to tell you whether or not they are currently in 'move mode'. If the furniture
is in 'move mode', then all you simply have to do is state its corresponding furniture ID (make sure you don't clear your chat, your chat MUST be the furniture ID in order for it to work), and then simply click an area and hold down the mouse to view a replicate image on your mouse to make it easier to position your furniture somewhere. Let go of your held down mouse and the image will move itself to your desired position.
If 'move mode'
isn't activated when you check the furniture's 'move mode', then you can activate it by stating the furniture ID, and then pressing the 'z' key. This will toggle 'move mode' on and off.
As an addition, I made it possible for you to view who owns what furniture in a level. By saying
/furnitureowner, all furniture in the level that joins this system will prompt you with its corresponding owner, showing you who owns what.
Oh, and I currently made it so you can sit on the furniture. I commented that section of the code so that you can adjust it depending on the size of the image and/or whether or not the player should be able to sit on it or not.
I do believe that's all, if I've forgotten to mention something or something is unclear then please ask me and I will clarify a bit more.
Enjoy.
