PDA

View Full Version : Chat system


Chandler
04-05-2007, 01:28 AM
function onActionServerside(currentOption, messageData)
if (temp.currentOption == "sendMessage")
{
findPlayer(temp.messageData[0]).addWeapon(this.name);
findPlayer(temp.messageData[0]).triggerclient("weapon", this.name, "receiveMessage", {temp.messageData[1], player.account, player.nick});
}
//#CLIENTSIDE
function onPlayerChats()
{
if (player.chat.starts(":sendim"))
{
if (client.textAccounts.size() <= 3)
this.startConversation(player.chat.substring(7).tr im());
}
elseif (player.chat.starts(":viewblocked"))
{
temp.newMessage = "Currently Blocked accounts:\n";
for (temp.currentBlocked: client.cIgnore)
temp.newMessage @= (client.cIgnore.index(temp.currentBlocked) + 1) @",)" SPC temp.currentBlocked @"\n";
sendrpgmessage(temp.newMessage);
player.chat = "Read your console log! [F2]";
}
elseif (player.chat.starts(":unblock"))
{
if (client.cIgnore.index(player.chat.substring(8).tri m()) == -1)
player.chat = "That player isn't blocked!";
else
{
client.cIgnore.remove(player.chat.substring(8).tri m());
player.chat = "You've unblocked" SPC player.chat.substring(8).trim() @"!";
}
}
}

function startConversation(playersAccount)
{
if (client.textAccounts.index(temp.playersAccount) != -1)
return false;

if (!findPlayer(temp.playersAccount).account)
{
player.chat = "That player isn't online!";
return false;
}
client.textAccounts.add(temp.playersAccount);
if (ChatBar.visible)
ChatBar.visible = false;

temp.cimButtons = {
{"Clear", 6, 142, 96, 22},
{"Block", 101, 142, 96, 22},
{"Close", 197, 142, 97, 22}
};

("main_" @ temp.playersAccount).destroy();
new GuiWindowCtrl("main_" @ temp.playersAccount)
{
profile = "GuiBlueWindowProfile";

position = {0, 0};
extent = {300, 170};

text = "CIM -:" SPC temp.playersAccount;
canclose = canfalse;

new GuiScrollCtrl("messages_"@ temp.playersAccount)
{
position = {6, 23};
extent = {288, 100};

profile = "GuiBlueScrollProfile";

horizSizing = "width";
hScrollBar = "alwaysOff";

new GuiMLTextCtrl("messageBox_"@ temp.playersAccount)
{
position = {0, 0};
extent = {250, 100};

profile = "GuiBlueMLTextProfile";
addText("<b>Starting conversation!</b>", true);
}
}
new GuiTextEditCtrl("textBox_"@ temp.playersAccount)
{
profile = GuiBlueTextEditProfile;
position = {6, 123};
extent = {288, 20};
thiso.catchEvent(this, "onAction", "sendMessage");
}
for (temp.currentButton: temp.cimButtons)
new GuiButtonCtrl("buttons_"@ temp.playersAccount @"-"@ temp.currentButton[0])
{
profile = "GuiBlueButtonProfile";
position = {temp.currentButton[1], temp.currentButton[2]};
extent = {temp.currentButton[3], temp.currentButton[4]};
text = temp.currentButton[0];
thiso.catchevent(this.name, "onAction", "buttonPressed");
}
}
}
function sendMessage(objectName)
{
temp.accountWindow = temp.objectName.substring(8);
this.drawText(temp.accountWindow, player.nick SPC "says:");
this.drawText(temp.accountWindow, " "@ ("textBox_"@ temp.accountWindow).text);
triggerserver("weapon", this.name, "sendMessage", {temp.accountWindow, ("textBox_"@ temp.accountWindow).text});
("textBox_"@ temp.accountWindow).text = "";
("messageBox_"@ temp.accountWindow).scrollToBottom();
}
function drawText(accountSend, messageText)
("messageBox_"@ accountSend).addText("\n"@ temp.messageText, true);

function onActionClientside(curOption, messageData)
if (temp.curOption == "receiveMessage")
if (client.cIgnore.index(temp.messageData[1]) == -1)
{
if (!("main_" @ temp.messageData[1]).visible)
this.startConversation(temp.messageData[1]);
this.drawText(temp.messageData[1], "<b>"@ messageData[2] SPC "</b>says:");
this.drawText(temp.messageData[1], messageData[0]);
("messageBox_"@ temp.messageData[1]).scrollToBottom();
}
function buttonPressed(objectName)
{
temp.buttonName = objectName.tokenize("-")[1];
temp.accountName = objectName.tokenize("_")[1].tokenize("-")[0];
switch(temp.buttonName)
{
case "Clear": ("messageBox_"@ temp.accountName).settext("<b>Cleared conversation!</b>"); break;
case "Block":
client.cIgnore.add(temp.accountName);
client.textAccounts.remove(temp.accountName);
("main_" @ temp.accountName).destroy();
player.chat = "You've blocked" SPC temp.accountName @"!";
break;
case "Close":
client.textAccounts.remove(temp.accountName);
("main_" @ temp.accountName).destroy();
break;
}
}

Here's how it works:
:sendim [Account Name]
--Sends an IM to that account name
:viewBlocked
--shows the people that you've blocked
:unBlock [Account Name]
--Unblocks the account.

Here's a snapshot, will probably be released on Era.

Thinking of adding more features, but here's a basic that you can use! :p

Rapidwolve
04-05-2007, 01:35 AM
Haha, this makes me feel like "why didn't i think of that"

killerogue
04-05-2007, 01:39 AM
It really and truly does ^....

Good work Chandler!

Rapidwolve
04-05-2007, 01:44 AM
Look what you did Chandler, now I wanna go script a more advanced one. Like AIM =]

Also, never knew findPlayer worked clientside

Inverness
04-05-2007, 01:46 AM
Graal is an extremely good development platform for beginners like myself.

Gambet
04-05-2007, 01:48 AM
I think Joey made something similar or was working on something similar?


It's not the first time it's been done, but nice work!

Rapidwolve
04-05-2007, 01:49 AM
Graal is an extremely good development platform for beginners like myself.

Whoa, I thought you were Yen for a minute...

Chandler
04-05-2007, 08:55 AM
thank you!

MysticX2X
04-05-2007, 02:37 PM
Nice work =o.