Author Topic: Speaking gibberish  (Read 319 times)

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Speaking gibberish
« on: June 24, 2015, 07:29:42 pm »


               

I recently developed a message scrambling system that would adjust what players spoke in-game depending on their intelligence.  Since a low intelligence player typically has a score of ten or higher, this system would randomly adjust 10% of the characters in any message for these players, while higher intelligence players would have less interference.   This means that relaying exact messages (e.g. code words) is a bit more difficult, requiring some repeating.  I thought I would share the code and see if others have produced something similar.


 


void main()
{
string sMessage = GetPCChatMessage();
string sScramble = "abcdefghijklmnopqrstuvwxyz";
int iInt = GetAbilityScore(GetPCChatSpeaker(), ABILITY_INTELLIGENCE);
int iLength = GetStringLength(sMessage);
int iIndex = iLength;
while(iIndex--)
  {
  if(!Random(iInt))
    {
    sMessage = GetStringLeft(sMessage, iIndex)
       + GetStringRight(GetStringLeft(sScramble, Random(26) + 1), 1)
       + GetStringRight(sMessage, iLength - iIndex - 1);
    }
  }
SetPCChatMessage(sMessage);
}