Author Topic: Modified version of Port's chat emotes  (Read 2831 times)

http://forum.blockland.us/index.php?topic=191873.0
^ the addon

I would like for some scripter out there to turn this method [](/whatever) into this method :whatever:

So instead of using a / command, you want it to use a :command: system

So instead of using a / command, you want it to use a :command: system

They're not commands, and they don't really use /'s.

That's why i was clarifying, i was not at all sure what he meant. But i understand what he meant now. I am not yet certain how to make a chat message checking mechanism that works good enough for this. Maybe someone else can jump on this?

I am not yet certain how to make a chat message checking mechanism that works good enough for this. Maybe someone else can jump on this?

First for this system we have to figure out where exactly it determines the emote in the message string. So we start with the message sent command.
Code: [Select]
package chatEmotesServer
{
function serverCmdMessageSent( %cl, %msg )
{
if ( strPos( %msg, "[]" ) >= 0 )
{
%msg = peReplace( %msg );
}

parent::serverCmdMessageSent( %cl, %msg );
}
};
Obviously it's packaged, and we find out it uses the peReplace function.
Code: [Select]
function peReplace( %str )
{
if ( strPos( %str, "[]" ) < 0 )
{
return %str;
}

%new = "";

while( ( %pos = strPos( %str, "[]" ) ) >= 0 )
{
%new = %new @ getSubStr( %str, 0, %pos );
%str = getSubStr( %str, %pos, strLen( %str ) );

if ( getSubStr( %str, 2, 1 ) !$= "(" )
{
%new = %new @ getSubStr( %str, 0, 2 );
%str = getSubStr( %str, 2, strLen( %str ) );

continue;
}

%end = strPos( %str, ")" );

if ( %end < 4 )
{
%new = %new @ getSubStr( %str, 0, 2 );
%str = getSubStr( %str, 2, strLen( %str ) );

continue;
}

%code = getSubStr( %str, 3, %end - 3 );
%str = getSubStr( %str, %end + 1, strLen( %str ) );
%new = %new @ peParse( %code );
}

%new = %new @ %str;
return %new;
}
If you notice this function has nothing to do with the "/" character, so we move on to the next unknown function being called. peParse
Code: [Select]
function peParse( %code )
{
if ( getSubStr( %code, 0, 1 ) $= "/" )
{
%code = getSubStr( %code, 1, strLen( %code ) );
}

%path = $PE::Path @ %code @ ".png";

if ( !isFile( %path ) )
{
return "[](/" @ %code @ ")";
}

return "<bitmap:" @ $PE::Path @ %code @ ">\c6";
}
Okay, we found out where it does the whole /emote part. If we wanted to do a :emote: system then we need to change the "/" as well as the getSubStr we also need to add a check to make sure the last character is in fact a :

Now Dannu, I've seen you get better and better at coding, so I want you to try to solve this with the given information.

Now Dannu, I've seen you get better and better at coding, so I want you to try to solve this with the given information.
??? Why do you want to make this a lesson? If you know how to edit the script, why don't you edit the script?

I'll give it my best shot in the morning. My ADHD methylphenidate wore off a long time ago and i have a feeling i'll need a good nights sleep before doing this.

-tutorial-

I'm grateful for your tutorial, but i'd much rather appreciate the modification I asked for :/

I'm currently reverse engineering the code, but a few things are leaving me confused. I'll edit this to include any new things, since you obviously can't immediately anwer
Code: [Select]
if ( strPos( %msg, "[]" ) >= 0 ) //If string pos [] in message equals or is greater than 0 (?) I'm guessing it means, if there is [] anywhere in message
{
%msg = peReplace( %msg );
}
...
This seems to go to this function, but right at the start of peReplace is:
Code: [Select]
if ( strPos( %str, "[]" ) < 0 ) //If string position is lower than 0, return string (%str)? I'm guessing if it doesn't exist?
{
return %str;
}
Why include this code, if it does what i think it does. Is there any functionality or is this just double-redundancy?

Also, as far as i know, continue; ignores all code left in the current block ({}), so why is it put in the end of every if statement block?

I'm currently reverse engineering the code, but a few things are leaving me confused. I'll edit this to include any new things, since you obviously can't immediately anwer
Code: [Select]
if ( strPos( %msg, "[]" ) >= 0 ) //If string pos [] in message equals or is greater than 0 (?) I'm guessing it means, if there is [] anywhere in message
{
%msg = peReplace( %msg );
}
...
This seems to go to this function, but right at the start of peReplace is:
Code: [Select]
if ( strPos( %str, "[]" ) < 0 ) //If string position is lower than 0, return string (%str)? I'm guessing if it doesn't exist?
{
return %str;
}
Why include this code, if it does what i think it does. Is there any functionality or is this just double-redundancy?
Just double redundancy. You could just as easily replace the second piece of code by putting an else statement in the first piece of code.
Also, as far as i know, continue; ignores all code left in the current block ({}), so why is it put in the end of every if statement block?
It does not ignore all code left in the current block. It ignores all code left in the for or while statement and continues to the next iteration.

Some old quotes I found.
Quote
It tells the game to immediately continue to the next iteration in while and for loops.
Quote
You can have code after the continue that will be ignored if whatever triggers that continue is true, if you need to do that. I've used it in a bunch of places but can't think of a good example right now though.
Quote
for(%i=0;%i<10;%i+=1)
{
   if(%i == 5)
      continue;
  
   echo(%i);
}

Notice that it skips 5 because of the continue:
Quote
1
2
3
4
6
7
8
9

It's similar to putting a return if a check returns false at the state of a function.
I don't think continue; is used very much in while statements though.

Thanks for clearing that up for me. I was stumped


Oh stuff, i completely forgot about this. Weekend about to come up, i'll pick it up again.

Just go inside the zip file then replace the photos with others

make sure it has the same name as the before you replaced them, it has to be Absolutely the same, without a mistake

Just go inside the zip file then replace the photos with others

make sure it has the same name as the before you replaced them, it has to be Absolutely the same, without a mistake
Read the OP