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 02-04-2007, 03:38 PM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
Movable Furniture

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")
    {
     
this.start_x;
     
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.

Last edited by Gambet; 02-04-2007 at 07:57 PM..
Reply With Quote
  #2  
Old 02-04-2007, 04:18 PM
Twinny Twinny is offline
My empire of dirt
Twinny's Avatar
Join Date: Mar 2006
Location: Australia
Posts: 2,422
Twinny is just really niceTwinny is just really nice
Send a message via AIM to Twinny
Should add a wall test. Get the current objects dimensions then wall test them during onMouseDown(). While being blocked, give the image a shade of red. Otherwise normal colour. You could add special block checks for things like beds and such but it would be a handy update.
Reply With Quote
  #3  
Old 02-04-2007, 04:21 PM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
Quote:
Originally Posted by Twinny View Post
Should add a wall test. Get the current objects dimensions then wall test them during onMouseDown(). While being blocked, give the image a shade of red. Otherwise normal colour. You could add special block checks for things like beds and such but it would be a handy update.

Yes, nice suggestions.


EDIT: I took Twinny's suggestion into consideration and implemented a wall-checking system which makes the image reddish when you place your mouse on top of a wall so as to move it on a wall. You will not be able to place an image on a wall anymore (in most instances, since the mouse pointer is rather small and thus it won't be perfect; feel free to use this as a basis and work your way up from here into an even better system of checking and so forth).

Last edited by Gambet; 02-04-2007 at 04:46 PM..
Reply With Quote
  #4  
Old 02-06-2007, 05:25 PM
Lao_Su2 Lao_Su2 is offline
Panda
Lao_Su2's Avatar
Join Date: Jan 2002
Location: Draper, Utah
Posts: 645
Lao_Su2 is on a distinguished road
Send a message via AIM to Lao_Su2
Great NPC
__________________
Panda
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 11:55 PM.


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