Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 11-29-2007, 05:21 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
Advanced Control-NPC

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
PHP Code:
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"},
                     { 
"client.frozen"false }
                   };
}
// Nothing you need to change here.
function onActionPlayerOnline()
{
  if ( 
this.joinFile != NULL )
  {
    for ( 
temp.getJoin() )
    {
      
player.jointemp.);
    }
  }
  if ( 
this.joinMessage != NULL )
  {
    echo( 
this.joinMessage );
  }
  if ( 
this.logPlayer )
  {
    
savelog2"login.txt""Player" SPC player.account SPC "logged in!" );
  }
  if ( 
this.announcePlayer )
  {
    
sendToRCplayer.account SPC "logged in!" );
  }
  if ( 
this.resetVars != NULL )
  {
    for ( 
temp.this.resetVars )
    {
      
makevar"player." temp.a[0] ) = temp.a[1];
    }
  }
  if ( 
this.weaponsFile != NULL )
  {
    for ( 
temp.getWeapons() )
    {
      
player.addweapontemp.);
    }
  }
  
temp.getNotify();
  if ( 
temp.n.index( @ player.account ) > -)
  {
    echo( 
"Notify:" SPC player.account SPC "has logged on!" );
    
savelog2"notify.txt""Player" SPC player.account SPC "logged on." );
  }
  
  if ( 
this.pmFile != NULL )
  {
    
sendPMgetPM() );
  }
  
specialLogin();
}
function 
onPlayerLogOutpl )
{
  if ( 
pl.level.name == NULL )
  {
    return;
  }
  if ( 
this.logPlayer )
  {
    
savelog2"login.txt""Player" SPC pl.account SPC "logged out!" );
  }
  if ( 
this.announcePlayer )
  {
    
sendToRCpl.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.loadLinesthis.weaponsFile );
  for ( 
temp.temp.lines )
  {
    
temp.i.addtemp.);
  }
  return 
temp.i;
}
function 
getNotify()
{
  
temp.lines.loadLinesthis.notifyFile );
  for ( 
temp.temp.lines )
  {
    
temp.i.addtemp.);
  }
  return 
temp.i;
}
function 
getJoin()
{
  
temp.lines.loadLinesthis.joinFile );
  for ( 
temp.temp.lines )
  {
    
temp.i.addtemp.);
  }
  return 
temp.i;
}
function 
getPM()
{
  
temp.lines.loadLinesthis.pmFile );
  for ( 
temp.temp.lines )
  {
    
temp.@= temp."\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.
__________________
Reply With Quote
  #2  
Old 11-29-2007, 05:31 AM
Kyranki Kyranki is offline
Freelance Coder
Join Date: Aug 2007
Location: At the end of the rainbow, in the pot of gold.
Posts: 202
Kyranki is on a distinguished road
Send a message via AIM to Kyranki Send a message via MSN to Kyranki
Good job here Chris to help servers customize everything in their NPC Control when they've got a wealth of information. ++ rep
__________________
Stan.
Reply With Quote
  #3  
Old 11-29-2007, 01:40 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
Quote:
Originally Posted by Kyranki View Post
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
__________________
Reply With Quote
  #4  
Old 02-10-2008, 06:52 AM
pokeSMOT pokeSMOT is offline
Registered User
Join Date: Jun 2006
Posts: 35
pokeSMOT is on a distinguished road
Wow. I'm impressed ^_^ Perhaps when I'm able to log in, I can try this out :P
Reply With Quote
  #5  
Old 02-10-2008, 07:34 AM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
I personally don't like the idea of using files to store info that could simply be placed in arrays.
__________________
Reply With Quote
  #6  
Old 02-10-2008, 07:52 AM
Twinny Twinny is offline
My empire of dirt
Twinny's Avatar
Join Date: Mar 2006
Location: Australia
Posts: 2,422
Twinny is just really niceTwinny is just really nice
Send a message via AIM to Twinny
Quote:
Originally Posted by Inverness View Post
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.
Reply With Quote
  #7  
Old 02-10-2008, 08:22 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 Twinny View Post
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.
__________________
Reply With Quote
  #8  
Old 02-10-2008, 08:25 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Kind of unneeded, but I like the idea if you want people to be able to edit the control npc without giving NC.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #9  
Old 02-10-2008, 08:30 AM
coreys coreys is offline
N-Pulse Assistant Manager
coreys's Avatar
Join Date: Mar 2005
Posts: 2,180
coreys has a spectacular aura about
Send a message via AIM to coreys Send a message via MSN to coreys Send a message via Yahoo to coreys
Quote:
Originally Posted by Tigairius View Post
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.
__________________

Quote:
*SlikRick: so should I even ask about your aim status?
*Xor: well if you want to
*Xor: but i am LARPING
*SlikRick: While on a computer?
*Xor: yes
*Xor: in my living room
*SlikRick: ahh
*Xor: i have a fort setup to hide from beasts
Reply With Quote
  #10  
Old 02-10-2008, 08:54 AM
Twinny Twinny is offline
My empire of dirt
Twinny's Avatar
Join Date: Mar 2006
Location: Australia
Posts: 2,422
Twinny is just really niceTwinny is just really nice
Send a message via AIM to Twinny
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
Reply With Quote
  #11  
Old 02-10-2008, 10:08 AM
zokemon zokemon is offline
That one guy...
zokemon's Avatar
Join Date: Mar 2001
Location: Sonoma County, California
Posts: 2,925
zokemon is a jewel in the roughzokemon is a jewel in the rough
Send a message via ICQ to zokemon Send a message via AIM to zokemon Send a message via MSN to zokemon Send a message via Yahoo to zokemon
NPC Server PMs = Poop.
onLogin GUIs are so much cooler.
__________________
Do it with a DON!
Reply With Quote
  #12  
Old 02-10-2008, 03:02 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by zokemon View Post
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..
__________________
Reply With Quote
  #13  
Old 02-10-2008, 04:25 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
Quote:
Originally Posted by zokemon View Post
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...ad.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)
__________________
Reply With Quote
  #14  
Old 02-10-2008, 06:35 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 08:12 AM.


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