Graal Forums  

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

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #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 placingclick to place.

:
endplacing End the placing process.

:
removenpcs Activate NPC removalright click to remove any NPC placed with this system.

:
endremoving Stops the removal process.

:
dragnpcs Begins draggingclick and hold over an NPCthen 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 commandit will end once the NPC is changed.) 




Weapon Code(Name it whatever you need to):

PHP Code:
function onActionServerSide(cmdmousexposmouseyposnpc)
{
  switch(
cmd)
  {
    case 
"Place":
      
temp.newnpc putnpc2(mousexposmouseyposnull);
      
newnpc.join(npc);
      
newnpc.join("npc_control");
    break;
    case 
"Remove":
      
triggeraction(mousexposmouseypos"KillNPC""rawr");
    break;
    case 
"Start Dragging":
      
this.npctodrag = { mousexposmouseypos };
    break;
    case 
"Drag":
      
triggeraction(this.npctodrag[0], this.npctodrag[1], "DragNPC"mousexposmouseypos);
    break;
    case 
"Change NPC":
      
triggeraction(mousexposmouseypos"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"mousexmousey);
  
this.placing true;
  
this.npctoplace npc;
  
setTimer(.01);
}
function 
stopPlacing()
{
  
hideimg(400);
  
this.placing false;
}
function 
onTimeout()
{
  if(
this.placing == true)
  {
    
with(findimg(400))
    {
      
mousex;
      
mousey;
    }
    
setTimer(.01);
  }
}
function 
onMousedown()
{
  if(
leftmousebutton && this.placing == true)
  {
    
player.chat "Placed: "@this.npctoplace@"!";
    
triggerServer("gui"name"Place"mousexmouseythis.npctoplace);
  }
  if(
rightmousebutton && this.removing == true)
  {
    
player.chat "Removed NPC.";
    
triggerServer("gui"name"Remove"mousexmousey);
  }
  if(
leftmousebutton && this.dragging == true)
  {
    
player.chat "Starting dragging";
    
triggerServer("gui"name"Start Dragging"mousexmousey);
  }
  if(
leftmousebutton && this.changing true)
  {
    
triggerServer("gui"name"Change NPC"mousexmouseythis.newnpc);
    
player.chat = ("Changed to "@this.newnpc@"!");
    
this.action false;
    
this.changing false;
  }
}

function 
onMouseup()
{
  if(
this.dragging true)
  {
    
triggerServer("gui"name"Drag"mousexmousey);
    
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(newxnewy)
{
  
this.newx;
  
this.newy;
}

public function 
onActionChangeNPC(newclass)
{
  
this.hide();
  
this.dontblock();
  
temp.newnpc putnpc2(this.xthis.ynull);
  
newnpc.join(newclass);
  
newnpc.join("npc_control");
  
this.destroy();

Reply With Quote
 


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 05:38 PM.


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