Author Topic: Well, the board IS named Coding Help...  (Read 946 times)

Just wondering if someone could give me some tips for basic scripting.

I've been looking through others' scripts, add-ons, etc. and I think I'm ready to make an "ignore" script.
Here it is so far.

Code: [Select]
//------ ------- ------
//Ethos' Ignore Script
//------ ------- ------

function clientCmdignorehelp(%client)
 {
   messageclient(%client,'',"\c2V9 Ignore functions are as follows");
    messageclient(%client,'',"\c3/Ignore Playername ");
    messageclient(%client,'',"\c3/Listen Playername ");
}

function clientCmdignore(%client)(%victim)
 {
   if(!%victim.isAdmin);
   {
   messageclient(%client,'',"\c3 You can't ignore Admins or Super Admins");
   }
   else
   {

I'm sort of stuck there. If you can help in any way, or if my code is already forgeted up, PM me or post here and let me know.

Regards,

~Ethos[/s]

User was banned for this post
« Last Edit: September 13, 2008, 07:03:14 AM by Badspot »

Let me tell you you're barking up the wrong tree, for a start. An ignore script should be client-side and it should allow you to ignore super admins or admins because half the time they're the ones spamming crap.

Let me tell you you're barking up the wrong tree, for a start. An ignore script should be client-side and it should allow you to ignore super admins or admins because half the time they're the ones spamming crap.

Okay. So how would I go about making it clientside? Thank you much for helping :)

EDIT: You know what? I'm asking stupid questions. I should just Google "torquescript guide".

But that always seems different than Blockland scripting to me.

Eh.

For clientside mods, put the code in a client.cs file instead of server.cs. You cannot use server commands (/commands) or functions that affect existing objects (e.g. move a player around) clientsided.

You'll need to be able to intercept incoming chat messages (package newChatSO::addLine(%this,%line)), use string functions to decide whether it's a player chat message or something else (e.g. death messages shouldn't be ignored) and find the player's name. If it matches one on your ignore list, exit the function, otherwise call Parent::addLine to add the message to the chat.

For the list itself, try packaging NMH_Type::send(%this) and checking the first word of %this.getValue() and see whether it's something like "/ignorename" - if it is, add the rest of that message to the Ignore list, and exit the function instead of sending /ignorename as a normal /command.

Look up on the Internet how Torquescript packages work, you'll need them. Also note that an "ignore" done in this style might break with servers that have mods editing the chat.

For clientside mods, put the code in a client.cs file instead of server.cs. You cannot use server commands (/commands) or functions that affect existing objects (e.g. move a player around) clientsided.

You'll need to be able to intercept incoming chat messages (package newChatSO::addLine(%this,%line)), use string functions to decide whether it's a player chat message or something else (e.g. death messages shouldn't be ignored) and find the player's name. If it matches one on your ignore list, exit the function, otherwise call Parent::addLine to add the message to the chat.

For the list itself, try packaging NMH_Type::send(%this) and checking the first word of %this.getValue() and see whether it's something like "/ignorename" - if it is, add the rest of that message to the Ignore list, and exit the function instead of sending /ignorename as a normal /command.

Look up on the Internet how Torquescript packages work, you'll need them. Also note that an "ignore" done in this style might break with servers that have mods editing the chat.

So, in plain English:

Clientside mods can only do things that affect you
What I'm going to want to do is find out if it's a chat message from a player, then if that player if on my list.
If he/she is, the message doesn't go through.
If he/she is NOT, it does.

Thanks. I'll begin working. Any other tips would be appreciated.

~Ethos

For clientside mods, put the code in a client.cs file instead of server.cs. You cannot use server commands (/commands) or functions that affect existing objects (e.g. move a player around) clientsided.

You'll need to be able to intercept incoming chat messages (package newChatSO::addLine(%this,%line)), use string functions to decide whether it's a player chat message or something else (e.g. death messages shouldn't be ignored) and find the player's name. If it matches one on your ignore list, exit the function, otherwise call Parent::addLine to add the message to the chat.

For the list itself, try packaging NMH_Type::send(%this) and checking the first word of %this.getValue() and see whether it's something like "/ignorename" - if it is, add the rest of that message to the Ignore list, and exit the function instead of sending /ignorename as a normal /command.

Look up on the Internet how Torquescript packages work, you'll need them. Also note that an "ignore" done in this style might break with servers that have mods editing the chat.
I've tried packaging addline and send before, and usually just makes my chat break. Here's how I did it:

Code: [Select]
//Find Scripts
function findnamebyplayerlist(%ID) {
for(%i=0;%i <= NPL_List.rowcount()-1; %i++) {
%list = NPL_List.getrowtext(%i);
%name = getField(%list,1);
//echo("Name: " @ %name);
%pid = getField(%list,3);
//echo("ID: " @ %pid);
if(%id == %pid)
return %name;
}
}
function findnamefromchat(%string) {
createnamelist();
%lowf = 0;
for(%i=0;%i <= NPL_List.rowcount()-1; %i++)
if(strstr(%string, $names[%lowf]) > -1)
if(strstr(%string, $names[%i]) < strstr(%string, $names[%lowf]))
%lowf = %i;
return $names[%lowf];
}
function checkIgnore(%message) {
for(%i=0;%i<=$Ignore::num;%i++)
if(findnamebyplayerlist($Ignore::ID[%i]) $= findnamefromchat(%message) && findnamefromchat(%message) !$= "Badspot")
return %i;
return -1;
}
function createnamelist() {
for(%i=0;%i <= NPL_List.rowcount()-1; %i++)
$names[%i] = getField(NPL_List.getrowtext(%i),1);
}

//Used to make new ignores
function NMH_Type::send(%this) {
%text = trim(cleanStringemot(%this.getValue()));
if(strstr(strlwr(%text),"cmd ") == 0) {
%text = getSubStr(%text, 4, strlen(%text));
if(strstr(strlwr(%text),"ignore ") == 0) {
%text = trim(getSubStr(%text, 7, strlen(%text)));
commandtoserver('messagesent',"ID " @ trim(%text) @ " added to Ignore-List.");
$Ignore::ID[$Ignore::num++] = trim(%text);
ignoreSave();
canvas.popdialog(NewMessageHud);
return;
}
else if(strstr(strlwr(%text),"unignore ") == 0) {
%text = trim(getSubStr(%text, 9, strlen(%text)));
if(checkIgnore(trim(%text))) {
commandtoserver('messagesent',"ID " @ $Ignore::ID[checkIgnore(trim(%text))] @ " removed to Ignore-List.");
$Ignore::ID[checkIgnore(trim(%text))] = "";
ignoreSave();
}
canvas.popdialog(NewMessageHud);
return;
}
}
if(strstr(%text,"/") == 0) {
%command = getsubstr(getword(%text,0),1,strlen(getword(%text,0)));
if(getwordcount(%text)>=2) {
%var = getSubStr(%text,strlen(getword(%text,0))+1,strlen(%text));
if(getwordcount(%text)>=2) {
for(%i = 0; %i <= getWordCount(%var); %i++)
%vars[%i] = "\"" @ getWord(%var, %i) @ "\"";
%varlist = %vars0;
for(%i = 1; %i < getWordCount(%var); %i++)
%varlist = %varlist @ ", " @ %vars[%i];
}
else
%varlist = "\"" @ getWord(%var, 0) @ "\"";
eval("commandtoserver(\'"@%command@"\'," @ %varlist @ ");");
}
else
eval("commandtoserver(\'"@%command@"\');");
canvas.popdialog(NewMessageHud);
return;
}
else if(%text !$= "") {
if(NewMessageHud.channel $= "TEAM")
commandToServer('teamMessageSent',%text);
else if(NewMessageHud.channel $= "SAY")
commandToServer('MessageSent',%text);
else
commandToServer('MessageSent',%text);
}
canvas.popdialog(NewMessageHud);
}

//Ignoewa
function onChatMessage(%message, %voice, %pitch) {
if(getWordCount(%message))
if(checkIgnore(%message) <= -1)
newChatHud_addLine(%message);
}

//Ignore save system
function ignoreSave() {
if(!isObject(IgnoreFile))
new FileObject(IgnoreFile);
IgnoreFile.openForWrite("config/client/ignoreList.cs");
%cor=0;
for(%i=0; %i<=$Ignore::num; %i++) {
if ($Ignore::ID[%i]$="")
%cor++;
else
IgnoreFile.writeLine("$Ignore::ID["@%i-%cor@"]="@$Ignore::ID[%i]@";");
}
IgnoreFile.writeLine("$Ignore::num = "@$Ignore::num-%cor@";");
IgnoreFile.close();
}

Obviously that presents problems, but as I said, parenting those GUI commands doesn't seem to work. Also, instead of packaging addline, I overwrote onChatMessage, which sends the info to addline, so it doesn't stuff addLine.
« Last Edit: September 12, 2008, 04:41:15 PM by MegaScience »