Blockland Forums > Modification Help
[Source Code] Grammar Code [UPDATES ON NEW POST]
<< < (5/8) > >>
Brian Smithers:

if(isPackage(grammar))
   deactivatepackage(grammar);
package grammar
{
   function NMH_Type::send(%this)
   {
      if(strStr(NMH_Channel.getValue(),"SAY: ") == -1)
      {
         if(firstLetter(%this.getValue()) $= "/")
            return parent::send(%this);
         commandToServer('MessageSent',simpleGrammar(%this.getValue()));
         commandToSErver('stopTalking');
         canvas.popDialog(newMessageHud);
         NMH_Type.setValue("");
      }
      else
      if(strStr(NMH_Channel.getValue(),"TEAM: ") == -1)
      {
         if(firstLetter(%this.getValue()) $= "/")
            return parent::send(%this);
         commandToServer('TeamMessageSent',simpleGrammar(%this.getValue()));
         commandToSErver('stopTalking');
         canvas.popDialog(newMessageHud);
         NMH_Type.setValue("");     
      }
   }
};
ActivatePackage(grammar);

function firstLevelWords(%str)
{
   for(%i=0;%i<getWordCount(%str);%i++)
   {
      %word[%i] = getWord(%str,%i);
      switch$(%word[%i])
      {
         case "dont":
            %word[%i] = "don't";
         case "i":
            %word[%i] = "I";
         case "ive":
            %word[%i] = "I've";
         case "whatchya":
            %word[%i] = "what do you";
         case "wat":
            %word[%i] = "what";
         case "whats":
            %word[%i] = "what's";
         case "isnt":
            %word[%i] = "isn't";
         case "im":
            %word[%i] = "I'm";
         case "its":
            %word[%i] = "it's";
         case "wasnt":
            %word[%i] = "wasn't";
         case "couldnt":
            %word[%i] = "couldn't";
         case "wouldve":
            %word[%i] = "would've";
         case "kik":
            %word[%i] = "lol":
         case "ill":
            %word[%i] = "I'll";
         case "stil":
            %word[%i] = "still";
         case "probaly":
            %word[%i] = "probably";
         case "probs":
            %word[%i] = "probably";
         case "intersting":
            %word[%i] = "intresting";
         case "bord":
            %word[%i] = "bored";
         case "se":
            %word[%i] = "see";
         case "catually":
            %word[%i] = "actually";
         case "actualy":
            %word[%i] = "actually";
         case "lest":
            %word[%i] = "lets";
         case "somthig":
            %word[%i] = "something";
         case "poeple":
            %word[%i] = "people";
         case "H,,":
            %word[%i] = "Hmm";
         case "vant":
            %word[%i] = "can't";
         case "wont":
            %word[%i] = "won't";
         case "nothig":
            %word[%i] = "nothing";
         case "siht":
            %word[%i] = "stuff";
         case "letme":
            %word[%i] = "let me";
         case "tht":
            %word[%i] = "that";
         case "thta":
            %word[%i] = "that";
         case "blokc":
            %word[%i] = "block";
         case "cant":
            %word[%i] = "can't";
         case "sylvandor":
            %word[%i] = "sylvanor";
         case "hsot":
            %word[%i] = "host";
         case "alot":
            %word[%i] = "a lot";
      }
      if(%nstr $= "")
      {
         %nstr = %word[%i];
      }
      else
      {
         %nstr = %nstr SPC %word[%i];
      }
   }
   return %nstr;
}
function secondLevelWords(%str)
{
   for(%i=0;%i<getWordCount(%str);%i++)
   {
      %word[%i] = getWord(%str,%i);
      if(getSubStr(%word[%i],0,3) $= "Hmm" && lastLetter(%word[%i]) !$= "f")
         %word[%i] = "Hmm...";
      %word[%i] = nameCheck(%word[%i]);
      if(%nstr $= "")
      {
         %nstr = %word[%i];
      }
      else
      {
         %nstr = %nstr SPC %word[%i];
      }
   }
   return %nstr;
}
function firstLetter(%str)
{
   return getSubStr(%str,0,1);
}
function restLetters(%str)
{
   return getSubStr(%str,1,strLen(%str));
}
function lastLetter(%str)
{
   return getSubStr(%str,strlen(%str) - 1,strLen(%str));
}
function capitols(%str)
{
   return strUpr(firstLetter(%str)) @ restLetters(%str);
}
function nameCheck(%word)
{
   for(%i = 0; %i < NPL_List.rowCount(); %i++)
   {
      %list = NPL_List.getRowText(%i);
      %name = getField(%list, 1);
      if(%name $= %word)
         %word = strUpr(getSubStr(%word,0,1)) @ getSubStr(%word,1,strLen(%word));
   }
   return %word;
}
function butCheck(%str)
{
   if(firstWord(%str) $= "but")
      return restWords(%str);
   else
      return %str;
}
function periods(%str)
{
   if(strLen(%str) <= 3)
      return %str;
   %per = ". , ? ; \" ! * : ( )";
   for(%i=0;%i<getWordCount(%per);%i++)
   {
      if(lastLetter(%str) $= getWord(%per,%i))
         %y = 1;
   }
   %blacklist = ":D D: :( :C :) :( ;( ;) :-) 8) 8( >: <: :> :< C:";
   for(%i=0;%i<getWordCount(%blacklist);%i++)
   {
      if(lastWord(%str) $= getWord(%blacklist,%i))
         %y = 1;
   }
   if(%y == 0)
   {
      switch$(strlwr(firstWord(%str)))
      {
         case "what":
            %str = %str @ "?";
         case "why":
            %str = %str @ "?";
         case "where":
            %str = %str @ "?";
         case "how":
            %str = %str @ "?";
         case "who":
            %str = %str @ "?";
         case "lol":
            %str = %str @ "!";
         case "rofl":
            %str = %str @ "!";
         default:
            %str = %str @ ".";
      }
   }
   return %str;
}
function thirdLevelWords(%str)
{
   %fstr = strLwr(%str);
   if(%pos = strPos(%fstr,"id"))
   {
      switch$(getWord(%fstr,%pos))
      {
         case "bl":
            return;
         case "blockland":
            return;
         default:
            %str = getWords(%str,0,%pos - 1) SPC "i'd" SPC getWords(%pos + 1,strLen(%str));
      }
   }
   if(%pos = strPos(%fstr,"ill"))
   {
      if(getSubStr(periods(%str),strLen(periods(%str)) - 1,periods(%str)) !$= "?")
      {
         %str = getWord(%str,0,%pos - 1) SPC "i'll" SPC getWords(%pos, + 1,strLen(%str));
      }
   }
   return %str;
}

function simpleGrammar(%str)
{
   %str = butCheck(%str);
   %str = firstLevelWords(%str);
   %str = secondLevelWords(%str);
   %str = thirdLevelWordS(%str);
   %str = periods(%str);
   %str = capitols(%str);
   return %str;
}


updated, not tested though.
PurpleMetro:

--- Quote from: Brian Smithers on May 12, 2012, 05:23:20 PM ---
if(isPackage(grammar))
   deactivatepackage(grammar);
package grammar
{
   function NMH_Type::send(%this)
   {
      if(strStr(NMH_Channel.getValue(),"SAY: ") == -1)
      {
         if(firstLetter(%this.getValue()) $= "/")
            return parent::send(%this);
         commandToServer('MessageSent',simpleGrammar(%this.getValue()));
         commandToSErver('stopTalking');
         canvas.popDialog(newMessageHud);
         NMH_Type.setValue("");
      }
      else
      if(strStr(NMH_Channel.getValue(),"TEAM: ") == -1)
      {
         if(firstLetter(%this.getValue()) $= "/")
            return parent::send(%this);
         commandToServer('TeamMessageSent',simpleGrammar(%this.getValue()));
         commandToSErver('stopTalking');
         canvas.popDialog(newMessageHud);
         NMH_Type.setValue("");     
      }
   }
};
ActivatePackage(grammar);

function firstLevelWords(%str)
{
   for(%i=0;%i<getWordCount(%str);%i++)
   {
      %word[%i] = getWord(%str,%i);
      switch$(%word[%i])
      {
         case "dont":
            %word[%i] = "don't";
         case "i":
            %word[%i] = "I";
         case "ive":
            %word[%i] = "I've";
         case "whatchya":
            %word[%i] = "what do you";
         case "wat":
            %word[%i] = "what";
         case "whats":
            %word[%i] = "what's";
         case "isnt":
            %word[%i] = "isn't";
         case "im":
            %word[%i] = "I'm";
         case "its":
            %word[%i] = "it's";
         case "wasnt":
            %word[%i] = "wasn't";
         case "couldnt":
            %word[%i] = "couldn't";
         case "wouldve":
            %word[%i] = "would've";
         case "kik":
            %word[%i] = "lol":
         case "ill":
            %word[%i] = "I'll";
         case "stil":
            %word[%i] = "still";
         case "probaly":
            %word[%i] = "probably";
         case "probs":
            %word[%i] = "probably";
         case "intersting":
            %word[%i] = "intresting";
         case "bord":
            %word[%i] = "bored";
         case "se":
            %word[%i] = "see";
         case "catually":
            %word[%i] = "actually";
         case "actualy":
            %word[%i] = "actually";
         case "lest":
            %word[%i] = "lets";
         case "somthig":
            %word[%i] = "something";
         case "poeple":
            %word[%i] = "people";
         case "H,,":
            %word[%i] = "Hmm";
         case "vant":
            %word[%i] = "can't";
         case "wont":
            %word[%i] = "won't";
         case "nothig":
            %word[%i] = "nothing";
         case "siht":
            %word[%i] = "stuff";
         case "letme":
            %word[%i] = "let me";
         case "tht":
            %word[%i] = "that";
         case "thta":
            %word[%i] = "that";
         case "blokc":
            %word[%i] = "block";
         case "cant":
            %word[%i] = "can't";
         case "sylvandor":
            %word[%i] = "sylvanor";
         case "hsot":
            %word[%i] = "host";
         case "alot":
            %word[%i] = "a lot";
      }
      if(%nstr $= "")
      {
         %nstr = %word[%i];
      }
      else
      {
         %nstr = %nstr SPC %word[%i];
      }
   }
   return %nstr;
}
function secondLevelWords(%str)
{
   for(%i=0;%i<getWordCount(%str);%i++)
   {
      %word[%i] = getWord(%str,%i);
      if(getSubStr(%word[%i],0,3) $= "Hmm" && lastLetter(%word[%i]) !$= "f")
         %word[%i] = "Hmm...";
      %word[%i] = nameCheck(%word[%i]);
      if(%nstr $= "")
      {
         %nstr = %word[%i];
      }
      else
      {
         %nstr = %nstr SPC %word[%i];
      }
   }
   return %nstr;
}
function firstLetter(%str)
{
   return getSubStr(%str,0,1);
}
function restLetters(%str)
{
   return getSubStr(%str,1,strLen(%str));
}
function lastLetter(%str)
{
   return getSubStr(%str,strlen(%str) - 1,strLen(%str));
}
function capitols(%str)
{
   return strUpr(firstLetter(%str)) @ restLetters(%str);
}
function nameCheck(%word)
{
   for(%i = 0; %i < NPL_List.rowCount(); %i++)
   {
      %list = NPL_List.getRowText(%i);
      %name = getField(%list, 1);
      if(%name $= %word)
         %word = strUpr(getSubStr(%word,0,1)) @ getSubStr(%word,1,strLen(%word));
   }
   return %word;
}
function butCheck(%str)
{
   if(firstWord(%str) $= "but")
      return restWords(%str);
   else
      return %str;
}
function periods(%str)
{
   if(strLen(%str) <= 3)
      return %str;
   %per = ". , ? ; \" ! * : ( )";
   for(%i=0;%i<getWordCount(%per);%i++)
   {
      if(lastLetter(%str) $= getWord(%per,%i))
         %y = 1;
   }
   %blacklist = ":D D: :( :C :) :( ;( ;) :-) 8) 8( >: <: :> :< C:";
   for(%i=0;%i<getWordCount(%blacklist);%i++)
   {
      if(lastWord(%str) $= getWord(%blacklist,%i))
         %y = 1;
   }
   if(%y == 0)
   {
      switch$(strlwr(firstWord(%str)))
      {
         case "what":
            %str = %str @ "?";
         case "why":
            %str = %str @ "?";
         case "where":
            %str = %str @ "?";
         case "how":
            %str = %str @ "?";
         case "who":
            %str = %str @ "?";
         case "lol":
            %str = %str @ "!";
         case "rofl":
            %str = %str @ "!";
         default:
            %str = %str @ ".";
      }
   }
   return %str;
}
function thirdLevelWords(%str)
{
   %fstr = strLwr(%str);
   if(%pos = strPos(%fstr,"id"))
   {
      switch$(getWord(%fstr,%pos))
      {
         case "bl":
            return;
         case "blockland":
            return;
         default:
            %str = getWords(%str,0,%pos - 1) SPC "i'd" SPC getWords(%pos + 1,strLen(%str));
      }
   }
   if(%pos = strPos(%fstr,"ill"))
   {
      if(getSubStr(periods(%str),strLen(periods(%str)) - 1,periods(%str)) !$= "?")
      {
         %str = getWord(%str,0,%pos - 1) SPC "i'll" SPC getWords(%pos, + 1,strLen(%str));
      }
   }
   return %str;
}

function simpleGrammar(%str)
{
   %str = butCheck(%str);
   %str = firstLevelWords(%str);
   %str = secondLevelWords(%str);
   %str = thirdLevelWordS(%str);
   %str = periods(%str);
   %str = capitols(%str);
   return %str;
}


updated, not tested though.

--- End quote ---
Contains an error report. You may wan't to test it out yourself,
http://dl.dropbox.com/u/79071525/Client_Grammar2.zip
Ipquarx:
whatchya =/= what do you
Treynolds416:

--- Quote from: PurpleMetro on May 12, 2012, 06:13:13 PM ---wan't

--- End quote ---
I lol'd

Also don't quote the entire text block you dummy
MARBLE MAN:
:P
tu mahnie dolan peapul hear
tish miyt bea neated

Well, This could be helpful with the dumbass people, BUT there are times with this that will make the non dumbasses look like dumbasses

Post a screenshot of it happening to you
Navigation
Message Index
Next page
Previous page

Go to full version