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 04-06-2007, 08:08 PM
Rapidwolve Rapidwolve is offline
Registered User
Join Date: Jul 2006
Posts: 1,241
Rapidwolve is an unknown quantity at this point
Mailing System

NPC: Mail
PHP Code:
function onCreated()
 
createVariables();

function 
createVariables(){
  
setVars();
  
calcMostSent();
  
this.mailIDs = {"Example Box""Mailbox 1""the Bank",
                      
"etc"}; // Add as many as you wish
}


function 
setVars(){
  for (
iallplayers){
    
temp.player findPlayer(i);
      if (
temp.player != null){
        
this.sentmail.(@temp.player) = temp.player.clientr.sentmailamt;
    }
  }
}

public function 
calcMostSent(){
  
setVars();
  
temp.keys getstringkeys("this.sentmail.");
  
setarray(temp.mostsent2);
    for (
temp.0temp.temp.keys.size(); temp.++) {
      
temp.current makevar("this.sentmail." temp.keys[temp.i]);
        if (
temp.current temp.mostsent[1]) {
          
temp.mostsent[1] = temp.current;
          
temp.mostsent[0] = temp.keys[temp.i];
      }
}
   
serverr.mail.mostsent = {temp.mostsent[0],temp.mostsent[1]};
   return 
temp.mostsent[0];  

Class: postoffice-getmail
PHP Code:
function onCreated(){
  
setshape(1,32,32);
}

function 
onActionGrabbed(){
  if (
clientr.sentmail == false)
  {
    if (
clientr.sendmailto == null)
    {
      
findNPC("Mail").calcMostSent();
      
temp.num findNPC("Mail").mailIDs.size();
      
temp.mailID findNPC("Mail").mailIDs[random(0,temp.num)];
      
clientr.sendmailto temp.mailID;
      
temp.msg "Hmm... this letter is for someone at " clientr.sendmailto;
      
player.chat temp.msg;
      return;
    }
    else
    {
    
temp.msg clientr.sendmailto " is expecting a letter from you!";
    
player.chat temp.msg
    
return;
    }
  }
  
    if (
clientr.sentmail == true)
  {
    
findNPC("Mail").calcMostSent();
    
temp.paydol int(random(4,6));
    
player.rupees += temp.paydol;
    
clientr.sendmailto null;
    
clientr.sentmail false;
    
player.chat format("Recieved %i rupees"temp.paydol);
    return;
  }
}

//#CLIENTSIDE
function onCreated() {
  
setshape(1,32,32);

Class: postoffice-stats
PHP Code:
/* 
Post Office System
    by RW*
    */
//#CLIENTSIDE

function onCreated()
  
onTimeout();

function 
onTimeout(){
  
showText(2xy"Tahoma""b"format("%s has the most sent letters with %s"serverr.mail.mostsent[0],serverr.mail.mostsent[1]));
  
changeimgzoom(2.60);
  
showText(3xy+1"Tahome""b"format("You have sent %s letter(s)"clientr.sentmailamt));
  
changeimgzoom(3.60);
  
setTimer(.1);

Class: mailbox
PHP Code:

function onCreated(){
  
setimg("oakdale_mailbox-1.gif"); // replace with your mailbox image
}

function 
onActionGrabbed(acc){
  if (
player.dir == 0){
    if (
clientr.sendmailto == nullsay2(this.mailboxID);
      if (
clientr.sendmailto != null {
        if (
clientr.sendmailto == this.mailboxID){
         
findNPC("Mail").calcMostSent();
         
clientr.sentmailamt++;
         
clientr.sentmail true;
         
clientr.sendmailto null;
         
player.chat "Sent The Letter!";
    }
     else
    {
      
player.chat "Wrong Mailbox!";
      }
    }
  }

Post Office:
Create a level for the post office.

Add this code, put it againts a wall or something because it is invisible. You must grab it to get a new letter
PHP Code:
join("postoffice-getmail"); 
Add this code to show statistics.
PHP Code:
join("postoffice-stats"); 
Mailboxes:
Add this code into a level

PHP Code:
join("mailbox");
this.mailboxID "Example Box"// The mailbox ID must exist in the Mail NPC 'this.mailIDs' array 

Last edited by Rapidwolve; 04-06-2007 at 08:30 PM..
Reply With Quote
  #2  
Old 04-06-2007, 08:26 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
Style postoffice-stats, and maybe turn the timeout down, to like 0.5 or even 1 sec

Looks really nice RW!
__________________
Reply With Quote
  #3  
Old 04-06-2007, 08:31 PM
Rapidwolve Rapidwolve is offline
Registered User
Join Date: Jul 2006
Posts: 1,241
Rapidwolve is an unknown quantity at this point
Quote:
Originally Posted by Chompy View Post
Style postoffice-stats, and maybe turn the timeout down, to like 0.5 or even 1 sec

Looks really nice RW!
Done and thanks.
Reply With Quote
  #4  
Old 05-27-2007, 10:12 PM
bscharff bscharff is offline
Bloo
bscharff's Avatar
Join Date: Sep 2006
Location: San Antonio, Texas
Posts: 185
bscharff has a little shameless behaviour in the past
Send a message via AIM to bscharff Send a message via MSN to bscharff Send a message via Yahoo to bscharff
My Server (playerworld141) Won't Let Me Get A Letter.
(I can grab the "join postoffice-getmail" thing all I want but I don't get any message or script flag on my attributes)
Also, the Script Compiler Gives Me Numerous Errors So It Won't Even Let Me Save class: mailbox
Reply With Quote
  #5  
Old 05-27-2007, 11: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 bscharff View Post
My Server (playerworld141) Won't Let Me Get A Letter.
(I can grab the "join postoffice-getmail" thing all I want but I don't get any message or script flag on my attributes)
Also, the Script Compiler Gives Me Numerous Errors So It Won't Even Let Me Save class: mailbox
Post the errors?

Oh, and I think RW forgot the code for onActionGrabbed()
__________________
Reply With Quote
  #6  
Old 05-27-2007, 11:14 PM
Rapidwolve Rapidwolve is offline
Registered User
Join Date: Jul 2006
Posts: 1,241
Rapidwolve is an unknown quantity at this point
Quote:
Originally Posted by bscharff View Post
My Server (playerworld141) Won't Let Me Get A Letter.
(I can grab the "join postoffice-getmail" thing all I want but I don't get any message or script flag on my attributes)
Also, the Script Compiler Gives Me Numerous Errors So It Won't Even Let Me Save class: mailbox
I tested it and it worked fine for me before I released it, can you tell us what the errors were?

Quote:
Originally Posted by Chompy View Post
Post the errors?

Oh, and I think RW forgot the code for onActionGrabbed()
Yes if you dont have a triggerAction for when a player grabs something then add it somewhere.

PHP Code:
function onKeyPressed(codekey)
{
  switch (
temp.key)
  {
     case 
"a":
       
Grab();
     break;
  }
}

function 
Grab()
{
  
frontPosition = {player.1.5 vecx(player.dir) * 2player.1.5 vecy(player.dir) * 2};
  
canGrab = (testplayer(frontPosition[0], frontPosition[1]) || testnpc(frontPosition[0], frontPosition[1]));
  if (
canGrab)
  {
    
triggerAction(frontPosition[0], frontPosition[1], "Grabbed"player.accountplayer.guild);
  }

onActionGrabbed(account, guild);
Reply With Quote
  #7  
Old 05-29-2007, 12:53 AM
bscharff bscharff is offline
Bloo
bscharff's Avatar
Join Date: Sep 2006
Location: San Antonio, Texas
Posts: 185
bscharff has a little shameless behaviour in the past
Send a message via AIM to bscharff Send a message via MSN to bscharff Send a message via Yahoo to bscharff
Script compiler output for Class mailbox:
error: unexpected symbol { at line 8: if (clientr.sendmailto != null {


I'm Using the Exact Class: mailbox code listed above except using mailbox.gif instead of oakdale_mailbox-1.gif


But the Real Problem Is that It Dosen't Assign A Letter. I'm using the EXACT script mentioned above except more mailboxes.
Reply With Quote
  #8  
Old 05-29-2007, 12:59 AM
xXziroXx xXziroXx is offline
Master of Puppets
xXziroXx's Avatar
Join Date: May 2004
Location: Sweden
Posts: 5,288
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
Send a message via AIM to xXziroXx Send a message via MSN to xXziroXx
Change the line:

PHP Code:
if (clientr.sendmailto != null 
To:

PHP Code:
if (clientr.sendmailto != null) { 

Shame on you RW!
__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto
Reply With Quote
  #9  
Old 05-29-2007, 01:10 AM
bscharff bscharff is offline
Bloo
bscharff's Avatar
Join Date: Sep 2006
Location: San Antonio, Texas
Posts: 185
bscharff has a little shameless behaviour in the past
Send a message via AIM to bscharff Send a message via MSN to bscharff Send a message via Yahoo to bscharff
Thanks ziro!

Since Some Dumbo Decided To Abuse His Staff Powers (*cough* Account: dude2020 *cough* Never Hire Him) To Delete All Vital Server Information (ServerOptions, ServerFlags)
I Can't Even Log In To The Game. I Can Login To RC, But that's It.

Would Someone please Post Their ServerOptions So I Don't Have To Contact Support & Wait A Week For A Response?
Thanks!

Anyways, For Now Just Assume I'm Copy & Pasting EXACTLY What You Posted As The Script (Exception: ziro's Fix to the mailbox class)
Reply With Quote
  #10  
Old 05-29-2007, 01:13 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 bscharff View Post
Thanks ziro!

Since Some Dumbo Decided To Abuse His Staff Powers (*cough* Account: ----- *cough* Never Hire Him) To Delete All Vital Server Information (ServerOptions, ServerFlags)
I Can't Even Log In To The Game. I Can Login To RC, But that's It.

Would Someone please Post Their ServerOptions So I Don't Have To Contact Support & Wait A Week For A Response?
Thanks!

Anyways, For Now Just Assume I'm Copy & Pasting EXACTLY What You Posted As The Script (Exception: ziro's Fix to the mailbox class)
On the Graal Bible, it has all of the options for server ops.

Don't go around spreading accounts, please edit that out! That is extremly rude, how would you like it if someone accused you of doing something without proving you did it?!

You're being rude, I bet you don't even have proof he did it!
__________________
Reply With Quote
  #11  
Old 05-29-2007, 01:20 AM
bscharff bscharff is offline
Bloo
bscharff's Avatar
Join Date: Sep 2006
Location: San Antonio, Texas
Posts: 185
bscharff has a little shameless behaviour in the past
Send a message via AIM to bscharff Send a message via MSN to bscharff Send a message via Yahoo to bscharff
Proof (See Attached)

Highlight In A Glimpse:

Time: Mon May 28 05:20:31 2007
dude2020 deleted file levels/auction.nw
Time: Mon May 28 05:20:32 2007
dude2020 deleted file levels/back_room.nw
Time: Mon May 28 05:20:33 2007
dude2020 deleted file levels/cafe.nw
Time: Mon May 28 05:20:34 2007
dude2020 deleted file levels/event_briefing.nw
Time: Mon May 28 05:20:36 2007
dude2020 deleted file levels/event_house.nw
Time: Mon May 28 05:20:37 2007
dude2020 deleted file levels/house_01.nw
Time: Mon May 28 05:20:38 2007
dude2020 deleted file levels/houses01.nw
Time: Mon May 28 05:20:40 2007
dude2020 deleted file levels/island_01.nw
Time: Mon May 28 05:20:41 2007
dude2020 deleted file levels/jail.nw
Time: Mon May 28 05:20:42 2007
dude2020 deleted file levels/jail_office.nw
Time: Mon May 28 05:20:44 2007
dude2020 deleted file levels/lounge.nw
Time: Mon May 28 05:20:45 2007
dude2020 deleted file levels/main_level.nw
Time: Mon May 28 05:20:47 2007
dude2020 deleted file levels/onlinestartlocal.graal
Time: Mon May 28 05:20:49 2007
dude2020 deleted file levels/park.graal
Time: Mon May 28 05:20:50 2007
dude2020 deleted file levels/postoffice.nw
Time: Mon May 28 05:20:52 2007
dude2020 deleted file levels/staffhangout.nw
Time: Mon May 28 05:20:53 2007
dude2020 deleted file levels/staffshangout.nw
Time: Mon May 28 05:20:55 2007
dude2020 deleted file levels/staffstatueroom.nw
Time: Mon May 28 05:20:56 2007
dude2020 deleted file levels/tavern.nw
Time: Mon May 28 05:20:57 2007
dude2020 deleted file levels/zoraafields.nw
Time: Mon May 28 05:21:04 2007
dude2020 deleted file scripts/gambet_movablefurniture.txt
Time: Mon May 28 05:21:06 2007
dude2020 deleted file scripts/gralats.txt
Time: Mon May 28 05:21:07 2007
dude2020 deleted file scripts/mailbox.txt
Time: Mon May 28 05:21:08 2007
dude2020 deleted file scripts/postoffice-getmail.txt
Time: Mon May 28 05:21:10 2007
dude2020 deleted file scripts/postoffice-stats.txt
Time: Mon May 28 05:21:11 2007
dude2020 deleted file scripts/staffsign.txt
Time: Mon May 28 05:22:08 2007
dude2020 has updated the server options
Time: Mon May 28 05:22:15 2007
dude2020 has updated the folder configuration
Time: Mon May 28 05:22:18 2007
dude2020 has updated the server flags
Time: Mon May 28 05:25:09 2007
dude2020 changed the rights of bscharff
removed rights: warptoxy,warptoplayer,warpplayers,updatelevel,disc onnectplayers,viewattributes,setattributes,setowna ttributes,resetattributes,adminmessage,changeright s,banplayers,changecomments,changestaffaccounts,se tserverflags,changeoptions,changefolderconfig,chan gefolderrights,NPC-Control
new ip range(s):
Time: Mon May 28 05:26:12 2007
dude2020 changed the rights of Admin-Playerworld141
removed rights: warptoxy,warptoplayer,warpplayers,updatelevel,disc onnectplayers,viewattributes,setattributes,setowna ttributes,resetattributes,adminmessage,changeright s,banplayers,changecomments,changestaffaccounts,se tserverflags,changeoptions,changefolderconfig,chan gefolderrights,NPC-Control
new ip range(s):
Time: Mon May 28 05:26:29 2007
RC dude2020 disconnected.
Attached Files
File Type: txt rclog.txt (167.8 KB, 206 views)
Reply With Quote
  #12  
Old 05-29-2007, 01:21 AM
bscharff bscharff is offline
Bloo
bscharff's Avatar
Join Date: Sep 2006
Location: San Antonio, Texas
Posts: 185
bscharff has a little shameless behaviour in the past
Send a message via AIM to bscharff Send a message via MSN to bscharff Send a message via Yahoo to bscharff
Oh Yeah, Thanks about the graal bible tip ;]
Reply With Quote
  #13  
Old 05-29-2007, 01:28 AM
xXziroXx xXziroXx is offline
Master of Puppets
xXziroXx's Avatar
Join Date: May 2004
Location: Sweden
Posts: 5,288
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
Send a message via AIM to xXziroXx Send a message via MSN to xXziroXx
Here's my serveroptions from Mythic:


PHP Code:
# Start location
startlevel=ml_island.gmap
startx
=62.5
starty
=52.5

# Unstick me location
unstickmelevel=ml_island.gmap
unstickmex
=62.5
unstickmey
=52.5

# Protected weapons
protectedweapons=weapon1,weapon2

# Jail levels
#jaillevels=

# Explosion restriction
noexplosions=true

# Static restriction
setbodyallowed=true
setheadallowed
=true
setbomyallowed
=false
setswordallowed
=true
setshieldallowed
=true

# Gralat loss options
mindeathgralats=0
maxdeathgralats
=0

# Staff gralat restriction
normaladminscanchangegralats=true

# Local 'staff guilds'
staffguilds=Server,Owner

# 'Bush' items
bu****ems=false

# 'Baddy' items
baddyitems=false

# 'Healing' swords
healswords=false

# Non-script timeouts
respawntime=10
horselifetime
=0
baddyrespawntime
=60

# Server scripting flags
dontaddserverflags=false

# Server maps
#bigmap=maptext,mapimage,defaultx,defaulty
#minimap=maptext,mapimage,defaultx,defaulty

# Warping (all players)
warptoforall=true
warptoforlowadmins
=true

# Warping activation
warpto=true
ignorewarpto
=false

# Ghost mode
ghostmodeenabled=false
ghostmodefornotstaff
=false

# Playerlist icons
#playerlisticons=

# Profile variables
profilevars=Server Relation:=clientr.staffrank

# Trial account limits
limitfreeplayers2=false

# AP system activation
apsystem=true

# Starting AP
startap=100

# Global guilds activation
globalguilds=true
#allowedglobalguilds=Mythic Legend

# AP timeouts
aptime0=30
aptime1
=90
aptime2
=300
aptime3
=600
aptime4
=1200

# Hearts/Sword limits
heartlimit=3
swordlimit
=1

# 'putnpc' scripting command
putnpcenabled=false

# Translation
enabletranslations=false

# Language selection
#translatedlanguages=

# Server language
serverlanguage=English

# NPC-Server 'sleep'
sleepwhennoplayers=false

# Tilesets
newtilesets=true
newtilesetlevels
=ml_,

# Staff
staff=ZOMG,SECRET,OK?

# GMAP list
gmap=ml_island

# Weapon order
weaponorder=weapon1,weapon2

# NPC-Control rights
npcrights=true

# Kill count
dontchangekills=true

# NPC-Server nickname
nickname=Mythic Legends NPC

# Speedhack tolerance
speedhacktolerance=90

# Idle disconnect
disconnectifnotmoved=false

# Save levels
savelevels=true
savelevelsmessage
=true

# Staff only
onlystaff=false

# Log script function calls
scriptlogfunctions=write player.nick,write player.guild,call sendtonc,call sendtorc

# Levels auto-save
levelsaveauto=true 
Edit: "bu****ems" is censored, should be "bush items" (remove the space).
__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto
Reply With Quote
  #14  
Old 05-29-2007, 01:40 AM
Rapidwolve Rapidwolve is offline
Registered User
Join Date: Jul 2006
Posts: 1,241
Rapidwolve is an unknown quantity at this point
Good thing this thread isn't about server options.
Reply With Quote
  #15  
Old 05-29-2007, 01:52 AM
bscharff bscharff is offline
Bloo
bscharff's Avatar
Join Date: Sep 2006
Location: San Antonio, Texas
Posts: 185
bscharff has a little shameless behaviour in the past
Send a message via AIM to bscharff Send a message via MSN to bscharff Send a message via Yahoo to bscharff
Got My Server Fixed...

Here's What I Have For NPC: Mail
PHP Code:
function onCreated()
 
createVariables();

function 
createVariables(){
  
setVars();
  
calcMostSent();
  
this.mailIDs = {"Main House""Bloos House""Events House""Cafe""Tavern" "Lounge"}; // Add as many as you wish
}


function 
setVars(){
  for (
iallplayers){
    
temp.player findPlayer(i);
      if (
temp.player != null){
        
this.sentmail.(@temp.player) = temp.player.clientr.sentmailamt;
    }
  }
}

public function 
calcMostSent(){
  
setVars();
  
temp.keys getstringkeys("this.sentmail.");
  
setarray(temp.mostsent2);
    for (
temp.0temp.temp.keys.size(); temp.++) {
      
temp.current makevar("this.sentmail." temp.keys[temp.i]);
        if (
temp.current temp.mostsent[1]) {
          
temp.mostsent[1] = temp.current;
          
temp.mostsent[0] = temp.keys[temp.i];
      }
}
   
serverr.mail.mostsent = {temp.mostsent[0],temp.mostsent[1]};
   return 
temp.mostsent[0];  

Error Received:
Script compiler output for Mail (in level main_level.nw at pos (30.5, 30)):
error: unexpected token: "Lounge" at line 7: this.mailIDs = {"Main House", "Bloos House", "Events House", "Cafe", "Tavern" "Lounge"}; // Add as many as you wish
error: missing semicolon at line 7: this.mailIDs = {"Main House", "Bloos House", "Events House", "Cafe", "Tavern" "Lounge"}; // Add as many as you wish
error: unexpected token: } at line 8: }

SEE NEXT PAGE.
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 09:56 AM.


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