PDA

View Full Version : Advanced Control-NPC


cbk1994
11-29-2007, 05:21 AM
Here is an advanced (sorta) Control-NPC script I made that is easy to customize for your server. I'll go threw the steps (below the code).

If you notice anythnig that is still specific to my server, please tell me and I will remove it! I think I got everything.

Here is the code:

Code of DB-NPC Control-NPC

function onCreated()
{
this.logPlayer = true; // Log logging in and out
this.announcePlayer = false; // Announce in RC logging in and out
this.joinFile = "control/serverJoin.txt"; // File that contains classes to join player to
this.weaponsFile = "control/serverWeapons.txt"; // File that contains list of weapons to add
this.notifyFile = "control/serverNotify.txt"; // List of players that are on notify
this.pmFile = "control/serverMessage.txt"; // The PM the npc-server sends you

this.joinMessage = "This message appears in RC when you log in!";

/*
Vars to reset when you log in.
For example, { clientr.disconnected, false } would set
clientr.disconnected to false. It's really quite handy.
For player. vars, don't include the player.
*/
this.resetVars = {
{ "clientr.gun_id", 0 },
{ "client.frozen", false }
};
}
// Nothing you need to change here.
function onActionPlayerOnline()
{
if ( this.joinFile != NULL )
{
for ( temp.a : getJoin() )
{
player.join( temp.a );
}
}
if ( this.joinMessage != NULL )
{
echo( this.joinMessage );
}
if ( this.logPlayer )
{
savelog2( "login.txt", "Player" SPC player.account SPC "logged in!" );
}
if ( this.announcePlayer )
{
sendToRC( player.account SPC "logged in!" );
}
if ( this.resetVars != NULL )
{
for ( temp.a : this.resetVars )
{
makevar( "player." @ temp.a[0] ) = temp.a[1];
}
}
if ( this.weaponsFile != NULL )
{
for ( temp.a : getWeapons() )
{
player.addweapon( temp.a );
}
}
temp.n = getNotify();
if ( temp.n.index( @ player.account ) > -1 )
{
echo( "Notify:" SPC player.account SPC "has logged on!" );
savelog2( "notify.txt", "Player" SPC player.account SPC "logged on." );
}

if ( this.pmFile != NULL )
{
sendPM( getPM() );
}
specialLogin();
}
function onPlayerLogOut( pl )
{
if ( pl.level.name == NULL )
{
return;
}
if ( this.logPlayer )
{
savelog2( "login.txt", "Player" SPC pl.account SPC "logged out!" );
}
if ( this.announcePlayer )
{
sendToRC( pl.account SPC "logged out!" );
}
}
function specialLogin()
{
// Special things you need to do to the player on login.
// for example,
// player.login();
// or player.unstick();
}
function getWeapons()
{
temp.lines.loadLines( this.weaponsFile );
for ( temp.a : temp.lines )
{
temp.i.add( temp.a );
}
return temp.i;
}
function getNotify()
{
temp.lines.loadLines( this.notifyFile );
for ( temp.a : temp.lines )
{
temp.i.add( temp.a );
}
return temp.i;
}
function getJoin()
{
temp.lines.loadLines( this.joinFile );
for ( temp.a : temp.lines )
{
temp.i.add( temp.a );
}
return temp.i;
}
function getPM()
{
temp.lines.loadLines( this.pmFile );
for ( temp.a : temp.lines )
{
temp.i @= temp.a @ "\n";
}
return temp.i;
}


Steps to Install the code:
1) Set this.logPlayer and this.announcePlayer to what you prefer. logPlayer logs when a player logs in or out. announcePlayer announces in RC when a player logs in or out.

2) Set all the different files. joinFile is the list of classes to be joined to the player. weaponsFile is a list of the weapons to be added to the player. notifyFile is a list of players that when logged in display a notice on RC, hence the name. Are also logged. pmFile is the pm that the NPC-server sends on logon. You can leave any one of these blank to disable it.

3) Set this.joinMessage. This is displayed in RC when a player logs on. You could do something like "STOP WATCHING RC! GO DEVELOP!". Leave blank to disable.

4) Set this.resetVars. This is handy for setting vars on login, such as clientr.frozen and clientr.disconnect. The format is { VAR, VALUE }. For player. vars, leave out the player., so it would be fullhearts, x, y, z, etc.

5) Leave everything alone until you get down to specialLogin() function.

6) Here put custom login things. For example, you may want to warp the player to a certain level when they login. Add that here. Maybe you need to do something special with a DB NPC when they log in. Add that here.

7) Add all of this in the DB-NPC Control-NPC. If you need help with that, ask me!


If you have any questions about any of this, please tell me and I will be happy to help! If I find bugs I will fix the code. Thank you!

Please, please, PLEASE, leave me feedback, this is my first useful script I've released since my return, so I'm wondering if it is any good.

Thank you!
Chris Zakuto

PS: Don't tell MiZZo (Jave), he'll freak out. He doesn't like me giving away scripts on [CENSORED UNTIL LATER NOTICE] that I make. Oh well.

Kyranki
11-29-2007, 05:31 AM
Good job here Chris to help servers customize everything in their NPC Control when they've got a wealth of information. ++ rep

cbk1994
11-29-2007, 01:40 PM
Good job here Chris to help servers customize everything in their NPC Control when they've got a wealth of information. ++ rep

Thank you! <3

pokeSMOT
02-10-2008, 06:52 AM
Wow. I'm impressed ^_^ Perhaps when I'm able to log in, I can try this out :P

Inverness
02-10-2008, 07:34 AM
I personally don't like the idea of using files to store info that could simply be placed in arrays.

Twinny
02-10-2008, 07:52 AM
I personally don't like the idea of using files to store info that could simply be placed in arrays.

Agreed. This can (and really should be) a really simple script.

cbk1994
02-10-2008, 08:22 AM
Agreed. This can (and really should be) a really simple script.

It's easier to use files to manage things than arrays because they are easier to edit - for example, you don't have to give someone NC to edit server messages, etc.

Also, imagine a long login message that was in the control NPC. Would simply get messy.

This is just an effective way of storing information so that it can easily be changed. Also eventually it would be easier to access through other scripts, but there's really no need in this particular application.

Tigairius
02-10-2008, 08:25 AM
Kind of unneeded, but I like the idea if you want people to be able to edit the control npc without giving NC.

coreys
02-10-2008, 08:30 AM
Kind of unneeded, but I like the idea if you want people to be able to edit the control npc without giving NC.

Same here.

Man, this makes me think of how unorganized every NPC Server I work with ends up being. :(

Twinny
02-10-2008, 08:54 AM
You have a weapons list in a text file....

Anyhoo, I split the Control-NPC up into the dbnpc and a class to keep it organised. The class contained (what became) the bigass onRcChat() event as well as the onPM() event. I always have login message handled by another weapon which did use text files and also a quick edit for staff ^^. Big PMs piss me off :whatever:

zokemon
02-10-2008, 10:08 AM
NPC Server PMs = Poop.
onLogin GUIs are so much cooler.

Chompy
02-10-2008, 03:02 PM
NPC Server PMs = Poop.
onLogin GUIs are so much cooler.

I agree xD, there's like a 25 percent that I'll even notice that the npc server has pm'ed me, and another 5 percent that I'll read it..

cbk1994
02-10-2008, 04:25 PM
NPC Server PMs = Poop.
onLogin GUIs are so much cooler.

Which is why I made the companion :) I only had server PMs in there because a lot of servers seem to use it. It's easy enough to disable and then install some form of login message.

http://forums.graalonline.com/forums/showthread.php?t=77694 - My companion

(for those of you who aren't going to click that, it's my Login Message GUI--same one used on Utopia)

Skyld
02-10-2008, 06:35 PM
Hmm, I don't see why you don't just put the player initialisation/logon stuff into the onCreated() function of a player-joined class. My Control-NPC on Rudora is scripted to do nothing but join classes to the player, and forward some events onto other NPCs. That way, it's very easy to see what should be doing what, while keeping things separated and organised.