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 05-31-2010, 12:48 PM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
IIRC chat room system

Made this with Salesman a few years ago, it's cool

HTML Code:
findplayer("Adam").addWeapon(this.name);

//#CLIENTSIDE
function onCreated() {  
  client.chat_channel = "#bravo";
  this.channels = {"#bravo", "#help", "#matches"};
  this.chatmembers = "";
  this.chatmoderators = {"xAndrewx"};
  
  sendtext("irc", "login", player.account); //3rd param doesn't appear to work?
  sendtext("irc", "join", client.chat_channel);
  //sendtext("irc", "join", this.channels[0]);
  /*for (temp.i: this.channels) {
    sendtext("irc", "part", i);
  }*/
  
  
  
  new GuiWindowCtrl("ChatSys") {
    useownprofile = true;
    profile.bitmap = "dusty_green3d_window.png";

    position = {screenwidth / 2 - 175, screenheight / 2 - 150};
    extent = {350, 275};
    text = "Server Chat System!";
    
    canClose = true;
    closeQuery = true;
    canMaximize = canMinimize = canResize = false;
    
    //Text display
    new GuiScrollCtrl("ChatSys_MLScroll") {
      useownprofile = true;
      profile.bitmap = "dusty_green_scroll.png";
      profile.border = 1;
      
      position = {7,25};
      extent = {250,215};
      
      hscrollbar = "dynamic";
      vscrollbar = "dynamic";
      

      new GuiMLTextCtrl("ChatSys_TextDisplay") {
        profile = GuiMLTextProfile;
        position = {1,1};
        allowedtags = "font,b,u,i";
        allowcolorchars = true;

        extent = {ChatSys_MLScroll.extent[0] - 10, ChatSys_MLScroll.extent[1] - 5};
      }
    }
    
    //Channel box
    new GuiScrollCtrl("ChatSys_ChanScroll") {
      useownprofile = true;
      profile.bitmap = "dusty_green_scroll.png";
      profile.border = 1;
      
      position = {6+ChatSys_MLScroll.extent[0],25};
      extent = {91,65};
      
      hscrollbar = "alwaysOff";
      vscrollbar = "dynamic";
      
      new GuiTextListCtrl("ChatSys_ChanList") {
        profile = GuiTextListProfile;
        position = {1, 1};
        fitparentwidth = true;     
        clearrows();

        temp.c = thiso.channels;
        for (temp.n: c) {
          addRow(c.index(n), n);
        }
        
        setSelectedRow(0);
        thiso.catchevent(this, "onDblClick", "onJoinChannel");
      }
    }
    
    //Join Channel button
    new GuiButtonCtrl("ChatSys_JoinChannel") {
      useownprofile = true;
      profile.bitmap = "dusty_green_button.png";
      profile.justify = "center";
      
      extent = {80, 20};      
      position = {ChatSys.extent[0] - this.extent[0] - 10, ChatSys_ChanScroll.position[1]+ChatSys_ChanScroll.extent[1]+5};
      
      text = "Join Channel";
      thiso.catchevent(this, "onAction", "onJoinChannel");
    }
    
    //Playerlist box
    new GuiScrollCtrl("ChatSys_PlayerScroll") {
      useownprofile = true;
      profile.bitmap = "dusty_green_scroll.png";
      profile.border = 1;
      
      extent = {91, 120};
      position = {6+ChatSys_MLScroll.extent[0], ChatSys.extent[1] - this.extent[1] - 35};

      hScrollBar = "dynamic";
      vScrollBar = "dynamic";
      
      new GuiTextListCtrl("ChatSys_PlayerList") {
        profile = GuiTextListProfile;
        position = {1, 1};
        fitparentwidth = true;     
        clearrows();
        thiso.catchevent(this, "onDblClick", "onPrivateMessage");
        thiso.catchevent(this, "onOpenMenu", "onStaffCommands");
      }
    }
    
    //Chat bar
    new GuiTextEditCtrl("ChatSys_TextBox") {
      useownprofile = true;
      profile.bitmap = "";
      profile.fillColor = {50,100,55};
      profile.border = 1;
      profile.fontColor = {0,0,0};
      
      extent = {250,20};
      position = {7,ChatSys.extent[1] - this.extent[1] - 10};
    }
    
    //Send text button
    new GuiButtonCtrl("ChatSys_SendText") {
      useownprofile = true;
      profile.bitmap = "dusty_green_button.png";
      profile.justify = "center";
      
      extent = {80, 20};
      position = {ChatSys.extent[0] - this.extent[0] - 10, ChatSys_TextBox.position[1]};
      
      text = "Send";
    }
  }
}

function ChatSys.onCloseQuery() {
  temp.ochan = client.chat_channel;
  this.chatmembers = "";
  sendtext("irc", "part", temp.ochan);
  ChatSys.destroy();
}

function onJoinChannel(obj, ind, chan) {
  if (temp.chan == null) 
    temp.chan = ChatSys_ChanList.getselectedtext();
  if (temp.chan != client.chat_channel ) {
    temp.ochan = client.chat_channel;
    this.chatmembers = "";
    this.onUpdatePlayerList();
    sendtext("irc", "part", temp.ochan);
    
    client.chat_channel = temp.chan;
    sendtext("irc", "join", temp.chan);   
  }
}

function ChatSys_TextBox.onAction() {
  this.chatEntered();
}

function ChatSys_SendText.onAction() {
  this.chatEntered();
}

function chatEntered() {
  temp.chat = ChatSys_TextBox.gettext();
  if (temp.chat == nil) return;

  temp.illegal = {"font size", "img"};
  for (temp.i: temp.illegal) {
    if (temp.chat.pos("<" @ i) != -1) {
      ChatSys_TextBox.text = "Illegal Text found! not sent";
      return;
    }
  }
  if (temp.chat.starts("Illegal Text found")) {
    ChatSys_TextBox.text = "";
    return;
  }
  
  if (temp.chat.starts("/throw")) {
    temp.list = {"fish", "boot", "frog", "snail", "cat", "dog", "kitten", 
                "monster", "knife", "grenade", "fosters can", "radio",
                "clock", "plant", "tv", "car", "bus", "candle"};
    if (this.chatmembers.size() == 1) {
      temp.person = this.chatmembers[0];
    } else {
      temp.person = randomstring(this.chatmembers);
    }
    temp.chat = "/me throws a" SPC randomstring(list) SPC "at" SPC temp.person;
  }
  
  if (temp.chat.length() > 50) temp.chat = temp.chat.substring(0, 50);
  
  if (temp.chat.starts("/join")) {
    this.onJoinChannel("", "", temp.chat.substring(6));
  } else {
    sendMSG( client.chat_channel, temp.chat);
  }
    
  ChatSys_TextBox.text = "";
}

function sendMSG( chan, msg ) {
  sendtext("irc", "privmsg", {chan, {player.communityname, msg}});
}

function onReceiveText( texttype, textoptions, textlines ) {
  if ( texttype != "irc" ) return;
  
  switch( textoptions ) {
    case "join":
      ChatSys_TextDisplay.text = "You have joined the" SPC textlines[0] SPC "channel!";
    break;

    case "deletechanneluser":
    case "addchanneluser":
      temp.pl = textlines[1];
      for (temp.i: allplayers) {
        if (textlines[1].starts(i)) {
          temp.pl = i;
          break;
        }
      }
      
      if (textoptions.starts("add")) {
        temp.chat = "joined";
        if (!(temp.pl in this.chatmembers)) {
          this.chatmembers.add(temp.pl);
        }
      } else {
        temp.chat = "left";
        this.chatmembers.remove(temp.pl);
      }
      
      ChatSys_TextDisplay.addtext("\n" SPC temp.pl SPC "has" SPC temp.chat SPC "the channel!", false);
      ChatSys_TextDisplay.scrolltobottom();
      this.onUpdatePlayerList();
    break;      
              
    case "privmsg":      
      if (isMod(textlines[2][0])) {
        temp.txt = "<b><font color=cyan>" @ textlines[2][0] @ "</font></b>";
      } else {
        temp.txt = "<font color=black>" @ textlines[2][0] @ "</font>";
      }
      temp.colon = ":";
      if (textlines[2][1].starts("/me")) {
        temp.colon = " ";
        temp.txt = "<b>" @ textlines[2][0];
        textlines[2][1] = textlines[2][1].substring(4) @ "</b>";
      }      
      
      ChatSys_TextDisplay.addtext("\n" @ temp.txt @ colon @ textlines[2][1], false);
      ChatSys_TextDisplay.scrolltobottom();
    break;
  }
}


function onUpdatePlayerList() {
  ChatSys_PlayerList.clearrows();
  for (temp.i: this.chatmembers) {
    temp.ind = this.chatmembers.index(i);
    if (this.isMod(i)) {
      i = "*" @ i;
    } else {
      i = i;
    }
    ChatSys_PlayerList.addRow(temp.ind, i);
    ChatSys_PlayerList.sort();
  }
}

function isMod(i) {
  return i.account in this.chatmoderators || i in this.chatmoderators;
}

function onPrivateMessage(profile, index, pl) {
  //added a check for players with spaces in their accounts (i.e. "Marche is back")
  //Was trying to send pm to acc_ount_# instead of just account
  temp.acc = "";
  temp.toks = pl.tokenize("_");
  if ( temp.toks.size() > 2 ) {
    temp.toks.delete(temp.toks.size()-1);
    temp.acc = temp.toks[0];
    temp.toks.delete(0);
    for ( temp.str: temp.toks ) {
      temp.acc = temp.acc SPC temp.str;
    }
  }
  else {
    temp.acc = pl;
  }
  
  if (temp.acc.starts("*")) {
    temp.acc = temp.acc.substring(1);
  }
  
  ("-Playerlist").openPMWindow({findPlayer(temp.acc)},false);
}

function onStaffCommands(acc) {
  if (!(this.isMod(temp.acc))) return;
  
  new GuiPopUpMenuCtrl("Staff") {
    textprofile = GuiTextListProfile;
    scrollprofile = GuiGreenScrollProfile;
    extent = {0, 0};
    position = {-30, -30};
    
    Open(mousescreenx, mousescreeny);
    clearrows();
    addrow(0,"Kick");
    addrow(1,"Ban");
  }  
}
Attached Thumbnails
Click image for larger version

Name:	Untitled.png
Views:	508
Size:	76.3 KB
ID:	51120  
Attached Images
 
__________________
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 10:29 PM.


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