PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: (!(Tys?kan)=) on 17 April, 2004, 14:25:38

Title: Game Script
Post by: (!(Tys?kan)=) on 17 April, 2004, 14:25:38
Who can write game "Number's", for Example:

This number is within 0 and 100!
!n 5
5>Number
!n 3
3 !n 4
Congratulations, Nick1 you are WINNER!
Next number!


Ty
Title:
Post by: nErBoS on 17 April, 2004, 15:28:38
Hi,

Hope it helps...

--Requested by (!(Tys?kan)=)
--Made by nErBoS

sBot = "Number's Bot"

play = "off"
gNum = 0


function Main()
frmHub:RegBot(sBot)
end

function DataArrival(user, data)
if (strsub(data,1,1) == "<") then
data = strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data, "%b<>%s+(%S+)")
if (cmd == "!turn" and user.bOperator) then --## Command to active the game ##--
local s,e,opt = strfind(data, "%b<>%s+%S+%s+(%S+)")
if (opt == nil) then
user:SendData(sBot, "Syntax Error, !turn , you must write on or off.")
elseif (strlower(opt) == "on") then
if (play == "off") then
play = "on"
SendToAll(sBot, "The Number's Game as been Started.")
SendToAll(sBot, "This number is within 0 and 100! ")
SendToAll(sBot, "Use the command !n to guess which number is.")
gNum = random(1, 100)
else
user:SendData(sBot, "The Game is already in role.")
end
elseif (strlower(opt) == "off") then
if (play == "on") then
play = "off"
SendToAll(sBot, "The Number's Game as Ended.")
SendToAll(sBot, "To the one's that didn?t win, better luck in next time.")
else
user:SendData(sBot, "The Game is already stopped.")
end
end
return 1
elseif (cmd == "!n") then --## Command to play ##--
local s,e,num = strfind(data, "%b<>%s+%S+%s+(%S+)")
if (num == nil or tonumber(num) == nil) then
user:SendData(sBot, "Syntax Error, !n , you must write a number 0 - 100.")
elseif (play == "off") then
user:SendData(sBot, "The Game is stopped.")
elseif (tonumber(num) == gNum) then
SendToAll(sBot, "Congratulations, "..user.sName.." you are WINNER!")
SendToAll(sBot, "Next number!")
gNum = random(1, 100)
else
user:SendData(sBot, "Wrong number better luck next time.")
end
return 1
end
end
end

Best regards, nErBoS
Title:
Post by: (!(Tys?kan)=) on 17 April, 2004, 20:23:33
10x u very much!!! :D
Title:
Post by: [UC]Dennis on 02 May, 2004, 10:42:34
hello people , this is my first post , and rightaway its an request  :))

Well i am doing Phatty's lua course now , but i had this numbergame introduced in my hub , but6 i want some mod's in it if possible.

I tried  but i messed up the script so bad , that i had to reinstal it  X(

But can the game be played , WITHOUTH typing !n before it each time ?

And Can u have an sentense like
65
Sorry user34 , that was too high  <--- send to all
12
Sorry user34 , that was too low  <--- send to all



I would be fully pleased .... :]  :]


P.S. can i translate the game to the dutch language ?
Title:
Post by: Corayzon on 02 May, 2004, 13:45:46
here ya go (!(Tys?kan)=)

-- :: Some Game For (!(Tys?kan)=)

-- Editable Settings
sBot = "Some Bot"
sGameName = "Some Game"
cmdGameStart = "+startgame"
cmdGameEnd = "+endgame"
cmdGuess = "+guess"
msgGameStart1 = "*** #g been Started."
msgGameStart2 = "*** #g Picked a number between 0 and 100"
msgGameStart3 = "*** To have a crack at it, just type #cmd and your guess into the main chat"
msgGameStop = "*** #g has been stoped"
msgGameStarted = "You have started #g"
msgGameStoped = "*** You have stoped #g"
msgGuessHigh = "Sorry #u, that was to high!"
msgGuessLow = "Sorry #u, that was to low!"
msgCorrect = "#u has guessed the magic number! :: #n"
iGameCount = 10

-- Non Editable
bPlaying, iNum, iCount = 0, 0, 0

function Main()
frmHub:RegBot(sBot)
end

function DataArrival(tUser, sData)

if strsub(sData, 1, 1) == "<" then

sData = strsub(sData,1,strlen(sData)-1)
local _,_, cmd = strfind(sData, "%b<>%s+(%S+)")
cmd = strlower(cmd)

if cmd == cmdGameStart and tUser.bOperator then

bPlaying, iNum = 1, random(1, 100)
tUser:SendData(sBot, translateString(msgGameStarted, "#g", sGameName))
SendToAll(sBot, translateString(msgGameStart1, "#g", sGameName))
SendToAll(sBot, translateString(msgGameStart2, "#g", sGameName))
SendToAll(sBot, translateString(msgGameStart3, "#g", sGameName, "#cmd", cmdGuess))
return 1

elseif cmd == cmdEndGame and tUser.bOperator then

bPlaying, iNum = 0, 0
tUser:SendData(sBot, translateString(msgGameStoped, "#g", sGameName))
return 1

elseif cmd == cmdGuess then

local _,_,sUsername, iGuess = strfind(sData, "<(%S+)>%s+%S+%s+(%S+)")
iGuess = tonumber(iGuess) or nil
if iGuess == nil then return end

if iGuess == iNum then

SendToAll(sBot, msgCorrect)
iCount = iCount + 1

if iCount > iGameCount then
bPlaying, iNum = 0, 0
SendToAll(sBot, translateString(msgGameStop, "#g", sGameName))
else
bPlaying, iNum = 1, random(1, 100)
SendToAll(sBot, translateString(msgGameStart1, "#g", sGameName))
SendToAll(sBot, translateString(msgGameStart2, "#g", sGameName))
SendToAll(sBot, translateString(msgGameStart3, "#g", sGameName))
end

elseif iGuess >= iNum then
SendToAll(sBot, translateString(msgGuessHigh, "#g", sGameName, "#u", sUsername))

elseif iGuess <= iNum then
SendToAll(sBot, translateString(msgGuessLow, "#g", sGameName, "#u", sUsername))
end
end
end
end

function translateString(sString, s1, sr1, s2, sr2, s3, sr3)

if s1 ~= nil then if strfind(sString, s1) then sString,_ = gsub(sString, s1, sr1 or "nothing") end end
if s2 ~= nil then if strfind(sString, s2) then sString,_ = gsub(sString, s2, sr2 or "nothing") end end
if s3 ~= nil then if strfind(sString, s3) then sString,_ = gsub(sString, s3, sr3 or "nothing") end end
return sString

end
Title:
Post by: [UC]Dennis on 02 May, 2004, 14:46:36
yes thank you very very very much , but 1 thing
first i had to type !n to guess
now i have to type +guess to guess

QuoteBut can the game be played , WITHOUT typing !n before it each time ?

that way it will be more fun for the users  :]
Title:
Post by: nErBoS on 02 May, 2004, 19:30:28
Hi,

Here is it...

--Requested by (!(Tys?kan)=)
--Made by nErBoS

sBot = "Number's Bot"

play = "off"
gNum = 0


function Main()
frmHub:RegBot(sBot)
end

function DataArrival(user, data)
if (strsub(data,1,1) == "<") then
data = strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data, "%b<>%s+(%S+)")
if (cmd == "!turn" and user.bOperator) then --## Command to active the game ##--
local s,e,opt = strfind(data, "%b<>%s+%S+%s+(%S+)")
if (opt == nil) then
user:SendData(sBot, "Syntax Error, !turn , you must write on or off.")
elseif (strlower(opt) == "on") then
if (play == "off") then
play = "on"
SendToAll(sBot, "The Number's Game as been Started.")
SendToAll(sBot, "This number is within 0 and 100! ")
SendToAll(sBot, "Use the command !n to guess which number is.")
gNum = random(1, 100)
else
user:SendData(sBot, "The Game is already in role.")
end
elseif (strlower(opt) == "off") then
if (play == "on") then
play = "off"
SendToAll(sBot, "The Number's Game as Ended.")
SendToAll(sBot, "To the one's that didn?t win, better luck in next time.")
else
user:SendData(sBot, "The Game is already stopped.")
end
end
return 1
elseif (cmd == "+guess") then --## Command to play ##--
local s,e,num = strfind(data, "%b<>%s+%S+%s+(%S+)")
if (num == nil or tonumber(num) == nil) then
user:SendData(sBot, "Syntax Error, +guess , you must write a number 0 - 100.")
elseif (play == "off") then
user:SendData(sBot, "The Game is stopped.")
elseif (tonumber(num) == gNum) then
SendToAll(sBot, "Congratulations, "..user.sName.." you are WINNER!")
SendToAll(sBot, "Next number!")
gNum = random(1, 100)
else
user:SendData(sBot, "Wrong number better luck next time.")
end
return 1
end
end
end

Best regards, nErBoS
Title:
Post by: [UC]Dennis on 02 May, 2004, 20:25:25
thank you life saver , gunna try it right now
Title:
Post by: ??????Hawk?????? on 02 May, 2004, 20:41:40
How About a Higher / Lower   Hint  .......



--Requested by (!(Tys?kan)=)
--Made by nErBoS
-- higher lower by ??????Hawk??????
sBot = "Number's Bot"

play = "off"
gNum = 0


function Main()
frmHub:RegBot(sBot)
end

function DataArrival(user, data)
if (strsub(data,1,1) == "<") then
data = strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data, "%b<>%s+(%S+)")
if (cmd == "+turn" and user.bOperator) then --## Command to active the game ##--
local s,e,opt = strfind(data, "%b<>%s+%S+%s+(%S+)")
if (opt == nil) then
user:SendData(sBot, "Syntax Error, !turn , you must write on or off.")
elseif (strlower(opt) == "on") then
if (play == "off") then
play = "on"
SendToAll(sBot, "The Number's Game as been Started.")
SendToAll(sBot, "This number is within 0 and 100! ")
SendToAll(sBot, "Use the command +guess to guess which number is.")
gNum = random(1, 100)
else
user:SendData(sBot, "The Game is already in role.")
end
elseif (strlower(opt) == "off") then
if (play == "on") then
play = "off"
SendToAll(sBot, "The Number's Game as Ended.")
SendToAll(sBot, "To the one's that didn?t win, better luck in next time.")
else
user:SendData(sBot, "The Game is already stopped.")
end
end
return 1
elseif (cmd == "+guess") then --## Command to play ##--
local s,e,num = strfind(data, "%b<>%s+%S+%s+(%S+)")
if (num == nil or tonumber(num) == nil) then
user:SendData(sBot, "Syntax Error, +guess , you must write a number 0 - 100.")
elseif (play == "off") then
user:SendData(sBot, "The Game is stopped.")
elseif (tonumber(num) == gNum) then
SendToAll(sBot, "Congratulations, "..user.sName.." you are WINNER!")
SendToAll(sBot, "Next number!")
gNum = random(1, 100)
elseif (tonumber(num) < gNum) then
SendToAll(sBot, "Higher!")
elseif (tonumber(num) > gNum) then
SendToAll(sBot, "Lower!")
end
end
end
end

Title:
Post by: Corayzon on 03 May, 2004, 03:15:59
QuoteOriginally posted by [UC]Dennis
yes thank you very very very much , but 1 thing
first i had to type !n to guess
now i have to type +guess to guess

QuoteBut can the game be played , WITHOUT typing !n before it each time ?

that way it will be more fun for the users  :]

um...if u look at the top of my script there is settings u can edit ;)

<< just change cmdguess to what u want the command to be ;) >>>

and for using it when no command prefix...i was tring to do this when i wrote it for ya...but the data in wouldnt arrive unless there was a + prefix for some reason :S