Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Class Placer/Manipulator (https://forums.graalonline.com/forums/showthread.php?t=78931)

warmaster70229 03-04-2008 04:19 PM

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();



cbk1994 03-04-2008 11:12 PM

Interesting, though generally not needed much.

I made a 30-line or so one for Utopia just so I could drop things and remove them quickly, got sick of making levels.

However, what you did seems to be overkill.

Still, nice job :)

warmaster70229 03-05-2008 12:05 AM

Made it when i was half asleep >:P

But thanks Chris :)

Codein 03-05-2008 12:23 AM

It's nice :) Now that you've got the framework, maybe you could improve this by using a menu instead of commands? That'd be a lot easier and would look better :)

cbk1994 03-05-2008 01:06 AM

Quote:

Originally Posted by Codein (Post 1377967)
It's nice :) Now that you've got the framework, maybe you could improve this by using a menu instead of commands? That'd be a lot easier and would look better :)

Only thing is it's already overkill--wasting more time on staff things like this is just waste.

warmaster70229 03-05-2008 02:21 AM

Agreed, but i think it's cool because i don't have to open up the level editor, which is a HUGE pain in the ass on my PC, just to place an NPC.

DustyPorViva 03-05-2008 02:28 AM

Level NPC's != putnpc's
You shouldn't treat them as such or vice versa. One day an LAT is gonna upload a level or something, or someone is gonna update a gmap or level and all those NPC's that are supposed to be part of a level(which you placed, to save time) are gonna poof.

napo_p2p 03-05-2008 03:45 AM

Quote:

Originally Posted by DustyPorViva (Post 1377999)
Level NPC's != putnpc's
You shouldn't treat them as such or vice versa. One day an LAT is gonna upload a level or something, or someone is gonna update a gmap or level and all those NPC's that are supposed to be part of a level(which you placed, to save time) are gonna poof.

I'm pretty sure that putnpc2s still stay when you update the level. However, I still agree that "layed" images should only be temporary.

DustyPorViva 03-05-2008 03:59 AM

Hmm... maybe... but I know they're far from permanent like level npcs are.

xXziroXx 03-05-2008 04:03 AM

putnpcs stay until clearnpcs is used on that level, or, someone deletes them from the npcs/ folder.

cbk1994 03-05-2008 04:04 AM

Quote:

Originally Posted by napo_p2p (Post 1378012)
I'm pretty sure that putnpc2s still stay when you update the level. However, I still agree that "layed" images should only be temporary.

Yes they stay when the level is updated, however there can be cases where when the NPC-Server is restart, it will wipe some.

I strongly recommend level NPCs.

If you really wanted to use putnpcs, make a DB NPC that goes through each level every so often to place them (after checking if they have died etc)

warmaster70229 03-05-2008 06:20 PM

I did that at one point, but lost my work when my PC crashed when i was typing it, and once again, just a little snippet to show how putnpc can be used and manipulated, could be the ground for a better system.


All times are GMT +2. The time now is 06:40 AM.

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