View Single Post
  #1  
Old 03-04-2008, 04:19 PM
warmaster70229 warmaster70229 is offline
Banned
Join Date: Jun 2007
Location: Texas ;D
Posts: 111
warmaster70229 is on a distinguished road
Send a message via AIM to warmaster70229 Send a message via MSN to warmaster70229 Send a message via Yahoo to warmaster70229
Class Placer/Manipulator

This is my first example in this forum, it places a putnpc2 that will join any class you have set up, with a simple commands and click of the mouse. (Such as doors, to save Levelers a tad bit of time.)

Commands:
(WARNING, YOU CAN NOT USE ANY COMMANDS WHILE PLACING/CHANGING/REMOVING/DRAGGING OTHER THAN THE CORRESPONDING END COMMAND)

PHP Code:
:placenpc <classname> ~ Starts placing, click to place.

:
endplacing ~ End the placing process.

:
removenpcs ~ Activate NPC removal, right click to remove any NPC placed with this system.

:
endremoving ~ Stops the removal process.

:
dragnpcs ~ Begins dragging, click and hold over an NPC, then release somewhere else and it will move :).

:
enddragging ~ Ends the dragging process.

:
changenpc <newclassname> ~ Changes the class of the clicked NPC to the newclassname parameter. (Does not have an end command, it will end once the NPC is changed.) 




Weapon Code(Name it whatever you need to):

PHP Code:
function onActionServerSide(cmd, mousexpos, mouseypos, npc)
{
  switch(
cmd)
  {
    case 
"Place":
      
temp.newnpc = putnpc2(mousexpos, mouseypos, null);
      
newnpc.join(npc);
      
newnpc.join("npc_control");
    break;
    case 
"Remove":
      
triggeraction(mousexpos, mouseypos, "KillNPC", "rawr");
    break;
    case 
"Start Dragging":
      
this.npctodrag = { mousexpos, mouseypos };
    break;
    case 
"Drag":
      
triggeraction(this.npctodrag[0], this.npctodrag[1], "DragNPC", mousexpos, mouseypos);
    break;
    case 
"Change NPC":
      
triggeraction(mousexpos, mouseypos, "ChangeNPC", params[3]);
    break;
  }
}
//#CLIENTSIDE
function onPlayerchats()
{
  if(
player.chat.starts(":placenpc ") && this.action != true)
  {
    
tokens = player.chat.tokenize();
    
player.chat = "Now Placing: "@tokens[1];
    
startPlacing(tokens[1]);
    
this.action = true;
  }
  if(
player.chat == ":endplacing")
  {
    
player.chat = "Stopped Placing..";
    
stopPlacing();
    
this.action = false;
  }
  if(
player.chat == ":removenpcs" && this.action != true)
  {
    
this.removing = true;
    
player.chat = "Removing started..";
    
this.action = true;
  }
  if(
player.chat == ":endremoving")
  {
    
this.removing = false;
    
player.chat = "Removing stopped..";
    
this.action = false;
  }
  if(
player.chat == ":dragnpcs" && this.action != true)
  {
    
this.dragging = true;
    
player.chat = "Dragging!";
    
this.action = true;
  }
  if(
player.chat == ":enddragging")
  {
    
this.dragging = false;
    
player.chat = "Dragging stopped";
    
this.action = false;
  }
  if(
player.chat.starts(":changenpc ") && this.action != true)
  {
    
tokens = player.chat.tokenize();
    
this.newnpc = tokens[1];
    
player.chat = ("Changing to a "@this.newnpc);
    
this.changing = true;
    
this.action = true;
  } 
}
function 
startPlacing(npc)
{
  
showimg(400, "block.png", mousex, mousey);
  
this.placing = true;
  
this.npctoplace = npc;
  
setTimer(.01);
}
function 
stopPlacing()
{
  
hideimg(400);
  
this.placing = false;
}
function 
onTimeout()
{
  if(
this.placing == true)
  {
    
with(findimg(400))
    {
      
x = mousex;
      
y = mousey;
    }
    
setTimer(.01);
  }
}
function 
onMousedown()
{
  if(
leftmousebutton && this.placing == true)
  {
    
player.chat = "Placed: "@this.npctoplace@"!";
    
triggerServer("gui", name, "Place", mousex, mousey, this.npctoplace);
  }
  if(
rightmousebutton && this.removing == true)
  {
    
player.chat = "Removed NPC.";
    
triggerServer("gui", name, "Remove", mousex, mousey);
  }
  if(
leftmousebutton && this.dragging == true)
  {
    
player.chat = "Starting dragging";
    
triggerServer("gui", name, "Start Dragging", mousex, mousey);
  }
  if(
leftmousebutton && this.changing = true)
  {
    
triggerServer("gui", name, "Change NPC", mousex, mousey, this.newnpc);
    
player.chat = ("Changed to "@this.newnpc@"!");
    
this.action = false;
    
this.changing = false;
  }
}

function 
onMouseup()
{
  if(
this.dragging = true)
  {
    
triggerServer("gui", name, "Drag", mousex, mousey);
    
player.chat = "NPC Dragged";
  }
} 


Class Code (Name it npc_control):

PHP Code:
public function onActionKillNPC(foo)
{
  
this.chat = "Destroyed!";
  
sleep(.5);
  
this.destroy();
}

public function 
onActionDragNPC(newx, newy)
{
  
this.x = newx;
  
this.y = newy;
}

public function 
onActionChangeNPC(newclass)
{
  
this.hide();
  
this.dontblock();
  
temp.newnpc = putnpc2(this.x, this.y, null);
  
newnpc.join(newclass);
  
newnpc.join("npc_control");
  
this.destroy();
} 
Reply With Quote