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 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
  #2  
Old 03-04-2008, 11:12 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
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
__________________
Reply With Quote
  #3  
Old 03-05-2008, 12:05 AM
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
Made it when i was half asleep >:P

But thanks Chris
Reply With Quote
  #4  
Old 03-05-2008, 12:23 AM
Codein Codein is offline
jwd
Codein's Avatar
Join Date: Oct 2005
Location: Greater Manchester
Posts: 2,423
Codein has a spectacular aura aboutCodein has a spectacular aura about
Send a message via AIM to Codein Send a message via MSN to Codein
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
Reply With Quote
  #5  
Old 03-05-2008, 01:06 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Codein View Post
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.
__________________
Reply With Quote
  #6  
Old 03-05-2008, 02:21 AM
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
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.
Reply With Quote
  #7  
Old 03-05-2008, 02:28 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
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.
Reply With Quote
  #8  
Old 03-05-2008, 03:45 AM
napo_p2p napo_p2p is offline
oh snaps
napo_p2p's Avatar
Join Date: Sep 2003
Location: Pismo Beach, California
Posts: 2,118
napo_p2p has a spectacular aura aboutnapo_p2p has a spectacular aura about
Send a message via AIM to napo_p2p Send a message via MSN to napo_p2p
Quote:
Originally Posted by DustyPorViva View Post
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.
__________________
Scito hoc super omnia.
Haec vita est tua una sola.
Dum vita superest, utere maxime quoque puncto, momento, et hora quae habes.
Tempus neminem non manet.
Noli manere tempus.
Carpe Diem

Seize the Day.
Reply With Quote
  #9  
Old 03-05-2008, 03:59 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Hmm... maybe... but I know they're far from permanent like level npcs are.
Reply With Quote
  #10  
Old 03-05-2008, 04:03 AM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
putnpcs stay until clearnpcs is used on that level, or, someone deletes them from the npcs/ folder.
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #11  
Old 03-05-2008, 04:04 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by napo_p2p View Post
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)
__________________
Reply With Quote
  #12  
Old 03-05-2008, 06:20 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
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.
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 10:39 PM.


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