Author Topic: Some questions  (Read 492 times)

Alright, suppose I want a client to announce(); something using his or her chat, and /eval.
This would be easy with one word, but I want multiple words to show up if the client types a multi-word announcement.
How would this be done?
Is what I have here anything near correct?
Quote
package announce{
   function servercmdmessagesent(%client, %message) {
      if(!%client.isAdmin) {
         return;
      }
      if(%message.getsubstr(0,1) == /eval) {
         announce(%message);
      }
      return;
   }
};
activatepackage(announce);

And, some other questions:
-What exactly is getwords(); and what is it's usage?
-If I wanted servercmd to execute a client-sided script, how can I do this?
-How can I trigger a function when a player chats a specific word on a server? How can I do this with a client-sided add-on?
-Is there any easy way to add tools to a player that doesn't involve a big function?
-How can I get words from a .txt file? How can I get the data from them line-by-line, separately?
« Last Edit: April 12, 2015, 10:34:01 PM by -Setro- »

You need to change == /eval to $= "/eval"
%message.getSubStr(0,1) should be getSubStr(%message,0,5)
You also need to call the parent function or else chat will be broken
« Last Edit: April 12, 2015, 10:38:38 PM by Headcrab Zombie »

You need to change == /eval to $= "/eval"
You also need to call the parent function or else chat will be broken
I'm assuming the parent function can be called with %client.commandtoserver(messagesent, %message); ?
« Last Edit: April 12, 2015, 10:37:07 PM by -Setro- »

If you want to allow multiple words, you can just add more arguments. If a client types in "/eval sifawkljfalwkgjawg," it won't go through serverCmdMessageSent; the client just uses commandToServer for the command entered.

function serverCmdDingus(%client, %a0, %a1, %a2, %a3, %a4, ..., %a15) don't remember off the top of my head what the argument limit is

a quick way to turn them into one string:
Code: [Select]
for(%i = 0; %i < 16; %i++)
   %msg = %msg SPC %a[%i];
%msg = ltrim(%msg); //ltrim removes the first space which shouldn't happen HAHA!!

not sure if it's more efficient processing-wise to just use a ternary operator or something to avoid the space at the beginning but that's possibly SCARY!! and also i don't think it's ridiculously imperative to get the extra milliseconds it would give you



getWords(sourceString, startIndex, endIndex) - returns words startIndex-endIndex in the string
e.g. getWords("a b c d e f", 2, 3); //returns "c d"



to execute a client-sided script with a serverCmd, you would need a clientCmd on the client-side which the server would activate with commandToClient(client, 'command', args...);



to trigger something when a word is said, it would be similar to what you're doing with the code in the OP; you would search the message for the string and call w/e function. on the client, you can do the same thing packaging a function related to sending chat (not quite sure what the best one is off the top of my head)

I'm assuing the parent function can be called with %client.commandtoserver(messagesent, %message); ?
Parent::serverCmdMessageSent(%client,%message);

getWords(sourceString, startIndex, endIndex) - returns words startIndex-endIndex in the string
e.g. getWords("a b c d e f", 2, 3); //returns "c d"
Also note that endIndex is optional; if not supplied it will go to the end of the string

ou can do the same thing packaging a function related to sending chat (not quite sure what the best one is off the top of my head)
NMH_Type::send

4. I believe there's an addtool event you can check the source of

5. Use search and search for "fileobject"

« Last Edit: April 12, 2015, 10:50:13 PM by Headcrab Zombie »