WordJumbleBotv2......Word game
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

WordJumbleBotv2......Word game

Started by XPMAN, 17 January, 2004, 23:30:40

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

XPMAN

I downloaded this out of the scripts that Optimus is so nice to host. It runs fine except the   a.hint   command does not work at all. Was trying to figure out how to add a auto 2nd hint , say 30 secs after the first one  to add one more letter in it too. The manual hint like I said is not working at all. If someone could help me figure it out i would appreciate it.

Seems to be a really nice script , it might be cause i am beta testing the new PtokaX and there is some incompatibility there.

here is the config file for it:     Jumble.cfg



-- JumbleFever
-- Author: RabidWombat

-- This is the config file to set values.
-- Do so at your own risk.

sBotName = "JumbleFever";

sTranslator = "Your name here";
-- NOTE: this file is a lua file. JumbleFever calls dofile on it. So
-- you can do anything in here that you would want to occur in the
-- PtokaX Main event.

sJumbleWordsFile = "Jumble\\English.txt";
sJumbleScoresFile = "JumbleScores.txt";

sHintChar = "?"

iDisplayScores = 10; --  displays top 10 scores
-- iDisplayScores = nil; -- displays all scores

-- In seconds
iPauseTime = 10;
iHintTime = 60;
iGameEndTime = 120;
iBonusTimeLimit = 10;

-- FORMULA SYSTEM --
-- Scores and Hint are now formula strings that have variables:
-- iLength = length of phrase (minus spaces)
-- iBonusTime = bonus time remaining
-- additional math functions such as min, max, floor, etc can be used
-- If you're not a scripter, don't change this.
-- Cause I don't want to help 20 people with nil problems :-P

sScoreFormula = "6"; -- score equals 6
-- sScoreFormula = "$iLength"; -- score equals length of phrase
-- sScoreFormula = "2 * $iLength + 3" -- score equals length of phrase times 2 plus 3
-- sScoreFormula = "min($iLength - 5, 0) * 2 + 6"; -- score equals 6 plus 2 for every letter beyond 5
sBonusFormula = "$iBonusTime"; -- bonus score equals bonus time
sHintFormula = "floor(.4 * $iLength + .5)";

-- Command table.
-- Format: ["cmdname"] = { FunctionName, OperatorOnly, "Description"}

tCommands = {
   [strlower("a.start")]   = { StartJumbleGame,      0,   "Start the jumble game. Can be used with language selction (a.start language)"},
   [strlower("a.stop")]   = { StopJumbleGame,      0,   "Stop the jumble game."},
   [strlower("a.phrase")]   = { DisplayJumblePhrase,   0,   "Display the current jumble phrase."},
   [strlower("a.help")]   = { DisplayJumbleHelp,      0,   "Display this message."},
   [strlower("a.scores")]   = { DisplayJumbleScores,   0,   "Display current scores."},
   [strlower("a.myscore")]   = { DisplayMyJumbleScore,    0,   "Display your score."},
   [strlower("a.hint")]   = { DisplayJumbleHint,       0,   "Display the hint."},

   [strlower("a.join")]   = { JoinJumble,       0,   "Join the private jumble game."},
   [strlower("a.leave")]   = { LeaveJumble,      0,   "Leave the private jumble game."},

   [strlower("a.private")]   = { SetPrivateJumbleGame,    1,   "Set Jumble to be private."},
   [strlower("a.public")]   = { SetPublicJumbleGame,   1,   "Set Jumble to be public."},
}

-- This string table is dynamic. You define GLOBAL variables with $varname. To define "$"
-- user $$. All above values are considered globals. All others in this table have easy
-- names so I hope everyone understands without an explaination. Try to use common sense
-- when selecting global variables in a string. If you don't think it will be set at the
-- time the string is displayed, it probably isn't :-P

tStringTable = {
[1] = "\r\n$sBotName designed by: $sAuthor Email: $sEmail\r\n"..
   "Play word jumble with your hub mates! Any text in the main chat is \r\n"..
   "considered a guess for the jumble phrase. Here are the commands:\r\n",
[2] = "$sCmd\t- $sDesc\r\n",
[3] = "10 seconds left!!!",
[4] = "$sUserName recieves $iScore points and $iBonus time bonus. Rank $iRank/$iRankTotal (Score: $iUserScore)",
[5] = "$sUserName recieves $iScore points. Rank $iRank/$iRankTotal (Score: $iUserScore)",
[6] = "$sUserName has started a new $sBotName game!!!",
[7] = "Type \"$sJumbleHelp\" for help.",
[8] = "$sUserName has stopped the $sBotName game. :-(",
[9] = "The Jumble Phrase is: $sJumblePhrase", -- fix
[10] = "Rank: $iRank/$iRankTotal Score: $iUserScore",
[11] = "You don\'t have a score! Loser. :-)",
[12] = "$sUserName has joined the jumble game.",
[13] = "Hello $sUserName",
[14] = "$sUserName has left the jumble game.",
[15] = "The Jumble Phrase was: $sActualPhrase",
[16] = "Top $iDisplayScores $sBotName Players\r\n\r\n",
[17] = "All $sBotName Players\r\n\r\n",
[18] = "No Scores",
[19] = "$iPos) Name: $sUserName - Score: $iUserScore\r\n",
[20] = "Here\'s a hint: $sHint",
[21] = "The $sBotName has stopped automatically. :-("
};









XPMAN

part 2



Here is the lua file:  Jumble.lua


sAuthor = "RabidWombat";
sEmail = "cbarber@dwc.edu";

bGameRunning, bGamePaused = nil, nil;
sJumblePhrase, sActualPhrases, NoSpacePhrase = nil,nil,nil;
iLength, iBonusTime = 0, 0;
sScoreOutput, sHintOutput, sHelpOutput, sOpHelpOutput = nil, nil, nil, "";
iTimeCount, iGameNoReplyCount = 0, 0;
tScores, tScoresByName  = { n = 0 }, {};
tChannelUsers, iChannelCount = {}, nil;

-- PtokaX Events --

function Main()
   dofile("jumble.cfg");

   sScoreFormula = "return "..sScoreFormula;
   sBonusFormula = "return "..sBonusFormula;
   sHintFormula  = "return "..sHintFormula;

   frmHub:RegBot(sBotName);

   sHelpOutput = StrReplace(tStringTable[1]);

   for cmd,tTemp in tCommands do
      if(tTemp[1] == DisplayJumbleHelp) then
         sJumbleHelp = cmd;
      end

      sCmd, sDesc = cmd, tTemp[3];

      if(tTemp[2] == 0) then
         sHelpOutput = sHelpOutput..StrReplace(tStringTable[2]);
      else
         sOpHelpOutput = sOpHelpOutput..StrReplace(tStringTable[2]);
      end
   end

   OldSendToAll = SendToAll;
   UserDisconnected = LeaveJumble;
   OpDisconnected = LeaveJumble;

   SetTimer(1000);

   ReadScoresFromFile();
   SetScores();
end

function OnTimer()
   if(bGamePaused) then
      iTimeCount = iTimeCount + 1;

      if(iTimeCount >= iPauseTime) then
         StartJumblePhrase();
      end
   elseif(bGameRunning) then
      iTimeCount = iTimeCount + 1;

      if(iTimeCount == iHintTime) then
         SendToAll(sBotName, sHintOutput);
      elseif (iTimeCount == iGameEndTime - 10) then
         SendToAll(sBotName, StrReplace(tStringTable[3]));
      elseif (iTimeCount == iGameEndTime) then
         StopJumblePhrase();
         if(iGameNoReplyCount >= 3) then
            StopJumbleGame();
         end
      else

      end
   else

   end
end

function DataArrival(curUser, sData)
   local s, e, sNewData, chat, cmd, args = strfind(sData, "(%b<>%s+((%S+)%s*([^%|]*)))%|$");
   local s, e, sTo = strfind(sData, "^%$To: (%S+)");

   if(cmd == nil or (sTo and sTo ~= sBotName)) then return 0; end

   sUserName = curUser.sName;

   if(sTo) then
      curUser.SendData = curUser.SendPM;
   end

   cmd = strlower(cmd);

   if(tCommands[cmd] and (tCommands[cmd][2] == 0 or curUser.bOperator)) then
      curUser:SendData(sData);
      tCommands[cmd][1](curUser, args);
      return 1;
   else
      if (not(iChannelCount) and strsub(sData,1,1) == "<") then
         iGameNoReplyCount = 0;
      end

      if(iChannelCount and strfind(sData, "$To: "..sBotName, 1, 1) == 1 and cmd == "!me") then
         sNewData = "* "..sUserName..strsub(chat, 4);
      end

      if(bGameRunning and bGamePaused == nil and strfind(strupper(chat), sActualPhrase, 1, 1)) then
         SendToAll(sNewData);

         iBonusTime = max(iBonusTimeLimit - iTimeCount, 0);

         iScore = dostring(StrReplace(sScoreFormula));
         iBonus = dostring(StrReplace(sBonusFormula));

         if(tScoresByName[sUserName]) then
            tScoresByName[sUserName][2] = tScoresByName[sUserName][2] + iScore + iBonus;
         else
            tScoresByName[sUserName] = {sUserName, iScore + iBonus};
            tinsert(tScores, tScoresByName[sUserName]);
         end

         iRank = SetScores(sUserName);
         iRankTotal = getn(tScores);
         iUserScore = tScoresByName[sUserName][2];

         WriteScoresToFile();

         StopJumblePhrase();

         if(iBonusTime ~= 0) then
            SendToAll(sBotName, StrReplace(tStringTable[4]));
         else
            SendToAll(sBotName, StrReplace(tStringTable[5]));
         end

         iGameNoReplyCount = 0;

         return 1;
      else
         if(iChannelCount and strfind(sData, "^$To: "..sBotName, 1, 1) == 1) then
            if(tChannelUsers[sUserName] == nil) then
               JoinJumble(curUser);
            else
               SendToAll(sNewData);
               iGameNoReplyCount = 0;
            end

            return 1;
         end
      end

   end
end

-- Command Functions --

function StartJumbleGame(curUser, args)
   if(bGameRunning) then return; end

   if(args ~= "") then
      local s, e, args = strfind(args, "([%w%s]+)$");
      args = "Jumble\\"..args..".txt";
      if(readfrom(args)) then
         sJumbleWordsFile = args;
         readfrom();
      end
   end

   OldSendToAll(sBotName, StrReplace(tStringTable[6]));
   StartJumblePhrase();
   SendToAll(sBotName, StrReplace(tStringTable[7]));

   iGameNoReplyCount = 0;
end

function StopJumbleGame(curUser)
   if not(bGameRunning) then return; end

   if not(bGamePaused) then
      StopJumblePhrase();
   end

   if(curUser) then
      OldSendToAll(sBotName, StrReplace(tStringTable[8]));
   else
      OldSendToAll(sBotName, StrReplace(tStringTable[21]));
      -- TODO: fix numbers
   end

   bGameRunning, bGamePaused = nil, nil;
   iBonusTime, iLength = 0, 0;
   StopTimer();
end

function DisplayJumblePhrase(curUser)
   if(bGameRunning and not bGamePaused) then
      if(curUser == nil) then
         SendToAll(sBotName, StrReplace(tStringTable[9]));
      else
         curUser:SendData(sBotName, StrReplace(tStringTable[9]));
      end
   end
end

function DisplayJumbleHelp(curUser)
   if(curUser.bOperator) then
      curUser:SendData(sBotName, sHelpOutput..sOpHelpOutput);
   else
      curUser:SendData(sBotName, sHelpOutput);
   end
end

function DisplayJumbleScores(curUser)
   curUser:SendData(sBotName, sScoresOutput);
end

function DisplayMyJumbleScore(curUser)
   iRank = tScoresByName[curUser.sName][3];
   iRankTotal = getn(tScores);
   iUserScore = tScoresByName[sUserName][2];

   if(tScoresByName[curUser.sName]) then
      curUser:SendData(sBotName, StrReplace(tStringTable[10]));
   else
      curUser:SendData(sBotName, StrReplace(tStringTable[11]));
   end
end

function DisplayJumbleHint(curUser)
   if(iTimeCount >= iHintTime) then
      curUser:SendData(sBotName, sHintOutput);
   end
end

function JoinJumble(curUser)
   if(iChannelCount and tChannelUsers[curUser.sName] == nil) then
      SendToAll(sBotName, StrReplace(tStringTable[12]));

      curUser:SendPM(sBotName, StrReplace(tStringTable[13]));
      curUser.SendData = curUser.SendPM;

      DisplayJumblePhrase(curUser);
      DisplayJumbleHint(curUser);

      tChannelUsers[curUser.sName] = 1;
      iChannelCount = iChannelCount + 1;
   end
end

function LeaveJumble(curUser)
   if(iChannelCount and tChannelUsers[curUser.sName]) then
      sUserName = curUser.sName;
      SendToAll(sBotName, StrReplace(tStringTable[14]));

      tChannelUsers[curUser.sName] = nil;
      iChannelCount = iChannelCount - 1;

      if(iChannelCount <= 0) then
         iChannelCount = 0;
         StopJumbleGame();
      end
   end
end

function SetPrivateJumbleGame(curUser)
   if(iChannelCount == nil) then
      SendToAll = SendToAllInChannel;
      iChannelCount = 0;
   end
end

function SetPublicJumbleGame(curUser)
   if(iChannelCount) then
      SendToAll = OldSendToAll;
      tChannelUsers = {};
      iChannelCount = nil;
   end
end

-- Jumble Phrase Functions --

function JumbleString(str)
   local tStr = { n = 0; };
   local newString = "";

   gsub(str, "(.)", function(c) tinsert(%tStr, c); end);

   randomseed(clock());

   -- Fisher-Yates shuffle
   for n = getn(tStr), 1, -1 do
      local pos = random(n);
      newString = tStr[pos].." "..newString;
      tStr[pos] = tStr[n];
   end

   return newString;
end

function JumblePhrase(phr)
   return strsub(gsub(phr, "(%S+)", function (w) return JumbleString(w).."  "; end), 1, -2);
end

function StartJumblePhrase()
   local hFile = openfile(sJumbleWordsFile, "r");

   if(hFile == nil) then
      SendToAll(sBotName, "Error opening "..sJumbleWordsFile);
      return;
   end

   local _, phr = nil, nil;
   local iFileSize = seek(hFile , "end")

   randomseed(clock());

   while(phr == nil) do
      seek(hFile , "set", random(iFileSize)-1);
       _, phr = read(hFile, "*l", "*l");
   end

   closefile(hFile);

   sActualPhrase = strupper(phr);
   sNoSpacePhrase = gsub(sActualPhrase, "%s", "");
   sJumblePhrase = JumblePhrase(sActualPhrase);
   iLength = strlen(sNoSpacePhrase);

   SetJumbleHint();

   SendToAll(sBotName, StrReplace(tStringTable[9]));

   iTimeCount = 0;
   bGameRunning = 1;
   bGamePaused = nil;
   StopTimer(); StartTimer();
end

function StopJumblePhrase()
   SendToAll(sBotName, StrReplace(tStringTable[15]));
   sActualPhrase, sNoSpacePhrase, sJumblePhrase = nil, nil, nil;

   iTimeCount = 0;
   bGamePaused = 1;
   iGameNoReplyCount = iGameNoReplyCount + 1;
end

-- String Functions --

function StrReplace(sString)
   sString = gsub(sString, "%$(%w+)", function (w)
                  if(strsub(w,1,1) == "$") then
                     return strsub(w,2,-1);
                  else
                     return getglobal(w) or "nil";
                  end
               end);

   return sString;
end

-- Score Functions --

function SetScores(sName)
   local iCount = getn(tScores);
   iDisplayCount = iDisplayScores or iCount

   if(iDisplayScores) then
      sScoresOutput = StrReplace(tStringTable[16]);
   else
      sScoresOutput = StrReplace(tStringTable[17]);
   end

   if(iCount == 0) then
      sScoresOutput = StrReplace(tStringTable[18]);
   else
      sort(tScores, function(a, b) return a[2] > b[2]; end);

      for i = 1, iCount, 1 do
         tScores[3] = i;   -- set ranks for all users
      end

      for i = 1, min(iDisplayCount, iCount), 1 do
         iPos = i;
         sUserName = tScores[iPos][1];
         iUserScore = tScores[iPos][2];
         sScoresOutput = sScoresOutput..StrReplace(tStringTable[19]);
      end
   end

   sUserName = sName;

   if(sName) then
      return tScoresByName[sName][3];
   end
end

function ReadScoresFromFile()
   dofile(sJumbleScoresFile);

   for i = 1, getn(tScores), 1 do
      tScoresByName[tScores[1]] = tScores;
   end
end

function WriteScoresToFile()
   local hFile = openfile(sJumbleScoresFile, "w");

   write(hFile, "tScores = {\n");

   for i = 1, getn(tScores), 1 do
      write(hFile, "["..i.."] = {"..format("%q", tScores[1])..","..tScores[2].."},\n");
   end

   write(hFile, "n="..getn(tScores).."\n");

   write(hFile, "};");

   closefile(hFile);
end

-- Hint Functions --

function SetJumbleHint()
   local tRevealArray = { };

   local iReveal = dostring(StrReplace(sHintFormula));

   local iPos = nil;

   while(iReveal > 0) do
      repeat iPos = random(iLength); until tRevealArray[iPos] == nil

      tRevealArray[iPos] = 1;
      iReveal = iReveal - 1;
   end

   tRevealArray.iPos = 1;

   sHint = gsub(sActualPhrase, "(%S)", function (c)
                     if (c == nil) then return ""; end

                     local out, tTemp = nil, %tRevealArray;

                     if(tTemp[tTemp.iPos]) then
                        out = c;
                     else
                        out = sHintChar;
                     end

                     tTemp.iPos = tTemp.iPos + 1;

                     return out.." ";
                  end);
   sHint = strsub(sHint, 1, -2);

   sHintOutput = StrReplace(tStringTable[20]);
end

-- Channel Functions --

function SendToAllInChannel(sSender, sRawOutput)
   if(sSender) then
      local _;

      if(sRawOutput == nil) then
         sRawOutput = sSender;
         _, _, sSender = strfind(sRawOutput, "^%<(.-)%>");
      else
         sRawOutput = "<"..sSender.."> "..sRawOutput;
      end

      for nick, val in tChannelUsers do
         if(nick ~= sSender) then
            SendToNick(nick, "$To: "..nick.." From: "..sBotName.." $"..sRawOutput);
         end
      end
   end
end




Then there is also a folder that goes in the same dir:   Jumble

This folder includes the txt file with all the words for the game.

NotRabidWombat

The manual hint is intended for users who jumped into the game late and did not see the hint announced. It's the equivalent of a.phrase.

You didn't leave the lua tabified *sigh*

Please remove my email from the code. I don't want the web crawlers to get it.

To anyone that wants to modify it:

You'll probably want to create a second hint formula. Call the hint function on the first formula.
Wait....
Call the hint function on the second formula (by swapping the two)

You'll also have to keep track of which hint formula is where.

Conditions to consider:
1) User answers correctly before hint1
2) User answers correctly before hint2
3) User answers correctly after hint2

Thinking about... this may be easily done with a hint formula table.
{ Time, HintFormula }
Every second check the table. If current time equals the time in one of the indexes, display a hint using the HintFormula with that index. Then there could be an unlimited amount of hints.

-NotRabidWombat


I like childish behavior. Maybe this post will be deleted next.

SMF spam blocked by CleanTalk