Graal Forums  

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

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 04-21-2009, 08:57 AM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
Buddy Communication System

I made a system similar to something that was suggested here: http://forums.graalonline.com/forums....php?p=1485077

Basically, the system allows you to send mass messages to only your online buddies (same server) by either the gui-based method or the chat-based method. For the gui-based method, you will need to have the scripted playerlist enabled.

To enable the scripted playerlist:

F3 --> General --> Player list Options --> Check the box that reads "Use in-game playerlist"


If you have the scripted playerlist enabled, then simply right-click on any entry in the playerlist to bring up a new option for your popup menu: Message All Buddies

Click on this button to bring up a window similar to the mass-message window. Currently, only the 'Close' and 'Send' buttons work, the 'History' button does nothing but is there to make it easier to add functionality to it in the future. Simply type your message and press send.

For the chat-based method, simply say "tobuddies: <message here>" (without the braces) and your message will have sent.

I also added two separate features, which are a cooldown system to prevent spamming (currently a 15 second cooldown in-between messages which can be easily changed) and an ignoring feature that allows you to ignore all buddy mass messages.

Command for ignoring/allowing mass buddy messages: /bmsg ignore

Important Note: This system uses the NPC-Server to send messages between players so it requires you to not have the NPC-Server on ignore. Also, when installing this system, you will need to customize the onCreated() portion to your Control-NPC for when a player logs in since the scripted playerlist automatically removes any new rows that are not a part of the default system when you first log on. It is important that you do this or else the row will not appear when the player right-clicks someone on their playerlist.

PHP Code:
/*
 *Buddy Communication System
 *@author Gambet
 *NOTE: Requires the scripted playerlist
*/

function onActionServerSide(commandbuddyListmessagesender)
{
 if (
command == "sendBuddyMessage")
  {
   for (
pallplayers)
    {
     if (
p.account in buddyList)
      {
       if (
p.level.name != NULL)
        {
         if (
p.client.bmsg_ignore == false//Send message only if user allows mass buddy messages
           
p.sendPM("\nBuddy Message From" SPC sender ":\n\n" replaceText(message"\\n""#b"));
        }
      }
    }
  }
}

function 
replaceText(txtab//replaceText parser-function by DustyPorViva
{
 if (
txt.pos(a) < 0) return txt;
 
 
temp.txtpos txt.positions(a);
 
temp.newtxt txt.substring(0txtpos[0]);
 
 for (
temp.0txtpos.size(); i++) 
  {
   
newtxt @= b;
   
newtxt @= txt.substring(txtpos[i]+a.length(), txt.substring(txtpos[i]+a.length()).pos(a));
  }
  
 return 
newtxt;
}  

//#CLIENTSIDE
function onCreated()
{
 
this.customMenuEntry "Message All Buddies"//Row title
 
 
if (PlayerList_Menu.findtext(this.customMenuEntry) == -1)
  (
"-Playerlist").addCustomMenuEntry(1this.customMenuEntry);   
}

function 
onPlayerChats()
{
 if (
player.chat == "/bmsg ignore"//Toggle between allowing and ignoring mass buddy messages
  
{
   
client.bmsg_ignore = !client.bmsg_ignore;
   
player.chat "Mass Buddy Messages: " @ (client.bmsg_ignore == false "Allowed" "Ignored"); 
  }
 else if (
player.chat.starts("tobuddies:")) //Chat-based mass buddy messages
  
{
   if (
this.bmsg_cooldown <= timevar2)
    {
     
temp.messageToSend player.chat.substring(10);   
     
triggerserver("gui"name"sendBuddyMessage"findPlayerBuddies(), messageToSendplayer.account);
     
player.chat "";
     
this.bmsg_cooldown timevar2 15;
    }
   else
    {
     
player.chat "You can't send another buddy mass for another" SPC int(this.bmsg_cooldown timevar2SPC "second(s)!";
    }
  }
}

function 
PlayerList_Menu.onSelect(entryidtext
{
 if (
text == this.customMenuEntrytoBuddyGUI(); //If user selects 'Message All Buddies'
}

function 
toBuddyGUI()
{
 new 
GuiWindowCtrl("ToBuddy_Window")  
  { 
   
profile GuiBlueWindowProfile
   
= (screenwidth/100); 
   
= (screenheight/2-100); 
   
width 425
   
height 370
   
canclose "false";
   
text "Message To Buddies"
   new 
GuiScrollCtrl("ToBuddy_Scroll")  
    { 
      
profile GuiBlueScrollProfile
      
5
      
22
      
width 413
      
height 305
      
hScrollBar "alwaysOff"
      
vScrollBar "dynamic"
     new 
GuiMLTextEditCtrl("ToBuddy_ScrollText")  
      { 
        
useownprofile true
        
profile "GuiBlueTextProfile"
        
8
        
5
        
height 40
        
width 405
      } 
    }
    new 
GuiButtonCtrl("ToBuddy_CloseButton")  
    { 
     
profile GuiBlueButtonProfile
     
20
     
335
     
width 90
     
height 25
     
text "Close"
    }  
    new 
GuiButtonCtrl("ToBuddy_HistoryButton")  
    { 
     
profile GuiBlueButtonProfile
     
117
     
335
     
width 90
     
height 25
     
text "History"
    }  
    new 
GuiButtonCtrl("ToBuddy_SendButton")  
    { 
     
profile GuiBlueButtonProfile
     
305
     
335
     
width 97
     
height 25
     
text "Send"
    }  
  }
}

function 
ToBuddy_CloseButton.onAction()
{
 
ToBuddy_Window.destroy();
}

function 
ToBuddy_SendButton.onAction()
{
 
temp.messageToSend ToBuddy_ScrollText.text;
 
ToBuddy_Window.destroy();
 
 if (
this.bmsg_cooldown <= timevar2)
  {
   
triggerserver("gui"name"sendBuddyMessage"findPlayerBuddies(), messageToSendplayer.account);
   
this.bmsg_cooldown timevar2 15;
  }
 else
  {
   
player.chat "You can't send another buddy mass for another" SPC int(this.bmsg_cooldown timevar2SPC "seconds!";
  }
}

function 
findPlayerBuddies()
{
 
temp.buddiesOnline ""
 
 for (
pallplayers)
  {
   if (
p.isbuddy)
    {
     if (
buddiesOnline.index(p.account) == -1)
      
buddiesOnline.add(p.account); //Array of user's online buddies
    
}
  }
 
 return 
buddiesOnline;


Edit: Here are some screenshots:




Feel free to customize it as you please.
Attached Thumbnails
Click image for larger version

Name:	bcsscreenshot1.png
Views:	276
Size:	11.0 KB
ID:	48188   Click image for larger version

Name:	bcsscreenshot2.png
Views:	254
Size:	43.9 KB
ID:	48189   Click image for larger version

Name:	bcsscreenshot3.png
Views:	251
Size:	45.0 KB
ID:	48190  

Last edited by Gambet; 04-21-2009 at 06:58 PM.. Reason: There is no reason to link to imageshack
Reply With Quote
 


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 04:52 AM.


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