PDA

View Full Version : Class Placer/Manipulator


warmaster70229
03-04-2008, 04:19 PM
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)


: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):

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: "@[email protected]"!";
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 "@[email protected]"!");
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):

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

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
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
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
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.