Chilla's Games
 

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

Chilla's Games

Started by Dessamator, 14 May, 2005, 13:05:21

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Dessamator

--Lua 5 By Dessamator
--Tic Tac Toe V.02 by chill
--Best viewed with Ms Sans Serif, Size 9
--User Commands added(by Dessamator)
tbot = "-TicTacToe-"

-------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------
-- 		************* MAIN SCRIPT *************
-------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------
TPlayers = {}
curGames = {}
tInvite = {}

function Main()
	frmHub:RegBot(tbot)
	SetTimer(10*1000)
end

function OnTimer()
	table.foreach(tInvite, function(i,_)
		tInvite[i][1] = tInvite[i][1] + 1
		if tInvite[i][1] >= 6 then
			tInvite[i] = nil
		end
	end)
end

-- On Connect
function NewUserConnected(curUser)

	curUser:SendData("$UserCommand 1 2 Tic Tac Toe\\Play TicTacToe With \"User\"$$To: "..tbot.." From: %[mynick] $<%[mynick]> invite %[nick]|")
	curUser:SendData("$UserCommand 1 2 Tic Tac Toe\\Quit$$To: "..tbot.." From: %[mynick] $<%[mynick]> quit|")
	
end
OpConnected = NewUserConnected

function ToArrival(curUser,data)
	if string.sub(data,6,5+(string.len(tbot))) == tbot then
		pmmsg = string.sub(data,(18+string.len(tbot)+2*string.len(curUser.sName)),(string.len(data)-1))
		local _,_,word1 = string.find(pmmsg,"^(%S+)")
		if TFUNCS[string.lower(word1)] then
			TFUNCS[string.lower(word1)](curUser,pmmsg)
		elseif (TPlayers[string.lower(curUser.sName)]) then
			Play3T(curUser,word1)
		end
	end
end
-------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------
-- 		************* GAME FUNCTIONS *************
-------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------

-------------------------------------------------------------------------
-- 	SHOW CURRENT GAME
-------------------------------------------------------------------------
function GetCurGame(A1,A2,A3,B1,B2,B3,C1,C2,C3)

	local TicTacToeGame = "\r\n\r\n"..
	"\t\t        1              2                  3\r\n"..
	"\r\n"..
	"\tA\t        "..A1.."       l       "..A2.."        l       "..A3.."\r\n"..
	"\t\t_______________________\r\n"..
	"\r\n"..
	"\tB\t        "..B1.."       l       "..B2.."        l       "..B3.."\r\n"..
	"\t\t_______________________\r\n"..
	"\r\n"..
	"\tC\t        "..C1.."       l       "..C2.."        l       "..C3.."\r\n"..
	"\r\n"

	return(TicTacToeGame)

end

-------------------------------------------------------------------------
-- 	CREATE A GAME
-------------------------------------------------------------------------
function CreateGame(curUser1,curUser2)
	curGames[string.lower(curUser1.sName).."$"..string.lower(curUser2.sName)] = {
		toPlay = { curUser2.sName,"X" },
		game = {
			A1 = { "  ",0 },
			A2 = { "  ",0 },
			A3 = { "  ",0 },
			B1 = { "  ",0 },
			B2 = { "  ",0 },
			B3 = { "  ",0 },
			C1 = { "  ",0 },
			C2 = { "  ",0 },
			C3 = { "  ",0 },
		},
	}
	TPlayers[string.lower(curUser1.sName)] = {
		PlaysWith = curUser2,
		curGame = string.lower(curUser1.sName).."$"..string.lower(curUser2.sName),
	}
	TPlayers[string.lower(curUser2.sName)] = {
		PlaysWith = curUser1,
		curGame = string.lower(curUser1.sName).."$"..string.lower(curUser2.sName),
	}
end

-------------------------------------------------------------------------
-- 	DELETE A GAME
-------------------------------------------------------------------------
function DelGame(curUser1,curUser2)
	curGames[TPlayers[string.lower(curUser1.sName)].curGame] = nil
	TPlayers[string.lower(curUser1.sName)] = nil
	TPlayers[string.lower(curUser2.sName)] = nil
end

-------------------------------------------------------------------------
-- 	CHECK IF GAME HAS ENDED
-------------------------------------------------------------------------
function doCheckIfPlay(curGame)
	count = 0
	table.foreach(curGame, function(i,_)
		count = count + curGame[i][2]
	end)
	if count == 9 then
		count = nil
		return("STOP")
	end
	count = nil
end

-------------------------------------------------------------------------
-- 	CHECK IF SOMEONE HAS WON
-------------------------------------------------------------------------
function doCheckForWin(curGame)
	if curGame.A1[1] ~= "  " and curGame.A1[1] == curGame.A2[1] and curGame.A1[1] == curGame.A3[1] then
		return("WON")
	elseif curGame.B1[1] ~= "  " and curGame.B1[1] == curGame.B2[1] and curGame.B1[1] == curGame.B3[1] then
		return("WON")
	elseif curGame.C1[1] ~= "  " and curGame.C1[1] == curGame.C2[1] and curGame.C1[1] == curGame.C3[1] then
		return("WON")
	elseif curGame.A1[1] ~= "  " and curGame.A1[1] == curGame.B1[1] and curGame.A1[1] == curGame.C1[1] then
		return("WON")
	elseif curGame.A2[1] ~= "  " and curGame.A2[1] == curGame.B2[1] and curGame.A2[1] == curGame.C2[1] then
		return("WON")
	elseif curGame.A3[1] ~= "  " and curGame.A3[1] == curGame.B3[1] and curGame.A3[1]  == curGame.C3[1] then
		return("WON")
	elseif curGame.A1[1] ~= "  " and curGame.A1[1] == curGame.B2[1] and curGame.A1[1] == curGame.C3[1] then
		return("WON")
	elseif curGame.A3[1] ~= "  " and curGame.A3[1] == curGame.B2[1] and curGame.A3[1] == curGame.C1[1] then
		return("WON")
	end
end

-------------------------------------------------------------------------
-- 	PLAY ONE ROUND
-------------------------------------------------------------------------
function Play3T(curUser,word1)	
	local sGame = curGames[TPlayers[string.lower(curUser.sName)].curGame].game
	if (curUser.sName == curGames[TPlayers[string.lower(curUser.sName)].curGame].toPlay[1]) and sGame[word1] and (sGame[word1][2] == 0) then
		local curUser1 = TPlayers[string.lower(curUser.sName)].PlaysWith
		if GetItemByName(TPlayers[string.lower(curUser.sName)].PlaysWith.sName) then
			local sGame = curGames[TPlayers[string.lower(curUser.sName)].curGame].game
			sGame[word1] = { curGames[TPlayers[string.lower(curUser.sName)].curGame].toPlay[2],1 }
			curGames[TPlayers[string.lower(curUser.sName)].curGame].game = sGame
			if curGames[TPlayers[string.lower(curUser.sName)].curGame].toPlay[2] == "X" then
				curGames[TPlayers[string.lower(curUser.sName)].curGame].toPlay = { TPlayers[string.lower(curUser.sName)].PlaysWith.sName,"O" }
			else
				curGames[TPlayers[string.lower(curUser.sName)].curGame].toPlay = { TPlayers[string.lower(curUser.sName)].PlaysWith.sName,"X" }
			end
			curUser:SendPM(tbot,GetCurGame(sGame.A1[1],sGame.A2[1],sGame.A3[1],sGame.B1[1],sGame.B2[1],sGame.B3[1],sGame.C1[1],sGame.C2[1],sGame.C3[1]))
			curUser1:SendPM(tbot,curUser.sName.." Played, now its your turn."..GetCurGame(sGame.A1[1],sGame.A2[1],sGame.A3[1],sGame.B1[1],sGame.B2[1],sGame.B3[1],sGame.C1[1],sGame.C2[1],sGame.C3[1]))
			if doCheckForWin(sGame) == "WON" then
					curUser:SendPM(tbot,"******  YOU HAVE WON ********")
					curUser1:SendPM(tbot,"****** YOU HAVE LOST ********")
					DelGame(curUser,curUser1)
			elseif doCheckIfPlay(sGame) == "STOP" then
					curUser:SendPM(tbot,"******  GAME ENDED EVEN ********")
					curUser1:SendPM(tbot,"******  GAME ENDED EVEN ********")
					DelGame(curUser,curUser1)
			end
		else
			curUser:SendPM(tbot,"Other Player went offline.")
			DelGame(curUser,curUser1)
		end
	end
end

-------------------------------------------------------------------------
-- 	TTT TABLE FUNCS
-------------------------------------------------------------------------
TFUNCS = {
	["invite"] = function(curUser,sdata)
		local _,_,invited = string.find(sdata,"^%S+%s+(%S+)")
		if invited and (not TPlayers[string.lower(curUser.sName)]) and GetItemByName(invited) and (not TPlayers[string.lower(invited)]) then
			tInvite[string.lower(invited)] = { 0,curUser }
			curUser:SendPM(tbot,"Sending invitation to "..invited..".")
			GetItemByName(invited):SendPM(tbot,curUser.sName.." invites you to a session of Tic,Tac Toe, Type: Accept or Deny.")
		else
			curUser:SendPM(tbot,"Either you already got a game going on or the user you wanted to invite is not online.")
		end
	end,
	["quit"] = function(curUser,sdata)
		if TPlayers[string.lower(curUser.sName)] then
			curUser:SendPM(tbot,"Game has been quit.")
			TPlayers[string.lower(curUser.sName)].PlaysWith:SendPM(tbot,curUser.sName.." has left the game.")
			DelGame(curUser,TPlayers[string.lower(curUser.sName)].PlaysWith)
		end
	end,
	["accept"] = function(curUser,sdata)
		if tInvite[string.lower(curUser.sName)] then
			if GetItemByName(tInvite[string.lower(curUser.sName)][2].sName) then
				local curUser2 = tInvite[string.lower(curUser.sName)][2]
				CreateGame(curUser,curUser2)
				curUser2:SendPM(tbot,curUser.sName.." has accepted your request.")
				curUser2:SendPM(tbot,GetCurGame("  ","  ","  ","  ","  ","  ","  ","  ","  "))
				curUser:SendPM(tbot,"Waiting for "..curUser2.sName.." to start.")
			else
				curUser:SendPM(tbot,"Other player went offline.")
			end
			tInvite[string.lower(curUser.sName)] = nil
		end
	end,
	["deny"] = function(curUser,sdata)
		if tInvite[string.lower(curUser.sName)] then
			curUser:SendPM(tbot,"Invitation was denied.")
			tInvite[string.lower(curUser.sName)][2]:SendPM(tbot,"You invitation was denied.")
			tInvite[string.lower(curUser.sName)] = nil
		end
	end,
}

Ignorance is Bliss.

Dessamator

#1
part 1:
--Lua 5 By Dessamator
-- By Chilla
-- Connect 4 

bot = "Connect4"; 
RegC4Bot = 1

VGScoresFile = "VGScores.txt" --The Scores File 
VGFolder = "Games" --The Games Folder 
Max1 = 3 -- How many topscorers are shown 

-- ************* MAIN SCRIPT ************* 

VGPlayers = {} 
curGames = {} 
tInvite = {} 
gameTrigs = {} 
VGChat = {} 
Matrix = { 
TL = { 
[1] = 6,[2] = 6,[3] = 5,[4] = 4,[5] = 3,[6] = 2,[7] = 1, 
[8] = 5,[15] = 4,[22] = 3,[29] = 2,[36] = 1, 
}, 
DL = { 
[1] = 1,[8] = 2,[15] = 3,[22] = 4,[29] = 5, 
[36] = 6,[37] = 6,[38] = 5,[39] = 4,[40] = 3,[41] = 2,[42] = 1, 
}, 
} 
timersets = { 0,0,0 } 

VGScores = {} 
--dofile(VGFolder.."/"..VGScoresFile) 

playchar1 = "X" 
playchar2 = "O" 

VGHelp = "--- Connect 4-Help ---\r\n\r\n".. 
"\t Main Chat\r\n".. 
"\t-----------------------------------\r\n".. 
"\tinvite  "..bot.." - Challenge Users\r\n".. 
"\ttopscore "..bot.." - TOP-Scorer\r\n".. 
"\tmyscore "..bot.." - Your Score\r\n".. 
"\thelp "..bot.." - This Help\r\n\r\n".. 
"\t PM to "..bot.."\r\n".. 
"\t-----------------------------------\r\n".. 
"\tinvite  - Challenge User\r\n".. 
"\tquit - Quit\r\n".. 
"\ttopscore - TOP-Scorer\r\n".. 
"\tmyscore - Your Score\r\n".. 
"\thelp - This Help\r\n" 

function Main() 
local file = io.open(VGFolder.."/"..VGScoresFile)
	if file then
		dofile(VGFolder.."/"..VGScoresFile) 
	else
		os.execute("mkdir Games")
		io.output(VGFolder.."/"..VGScoresFile)
		io.output()
	end
	for _ = 1,7 do 
		table.insert(gameTrigs,1) 
	end 
	if RegC4Bot == 1 then 
		frmHub:RegBot(bot) 
	end 
		SetTimer(10*1000) 
	StartTimer() 
end 

function OnTimer() 
	table.foreachi(timersets,function(i,_) timersets[i] = timersets[i] + 1 end) 
	table.foreach(tInvite, function(i,_) 
	tInvite[i][1] = tInvite[i][1] + 1 
	if tInvite[i][1] >= 6 then 
		tInvite[i] = nil 
	end 
	end) 
	if timersets[1] == 30 then 
		timersets[1] = 0 
		WriteTable(VGFolder.."/"..VGScoresFile,VGScores,"VGScores") 
	end 
		if timersets[2] == 60 then 
			timersets[2] = 0 
			table.foreach(curGames, function(i,_) 
			curGames[i].timeout = curGames[i].timeout + 1 
			if curGames[i].timeout == 6 then 
				VGPlayers[curGames[i].players[1]] = nil 
				VGPlayers[curGames[i].players[2]] = nil 
				curGames[i] = nil 
			end 
	end) 
end 
	if timersets[3] == 6 then 
		timersets[3] = 0 
		table.foreach(VGChat, function(i,_) 
		if not VGPlayers[i] then 
			VGChat[i][2] = VGChat[i][2] + 1 
			if VGChat[i][2] == 5 then 
				DelChat(i) 
			end 
		end 
	end) 
end 
end 

function UserDisconnected(curUser) 
	if VGPlayers[string.lower(curUser.sName)] then 
		local curUser1 = GetItemByName(VGPlayers[string.lower(curUser.sName)].PlaysWith) 
		if curUser1 then 
			curUser1:SendPM(bot,"Other Player went offline.")
		end 
			DelGame(curUser) 
			DelChat(string.lower(curUser.sName)) 
	end 
end 
OpDisconnected = UserDisconnected 

function ChatArrival(curUser,data) 
	if string.sub(data,string.len(data)-string.len(bot),string.len(data)-1) == bot then 
		local _,_,word1 = string.find(data,"^%b<>%s+(%S+)") 
		if word1 and VGFUNCS[string.lower(word1)] then 
			VGFUNCS[string.lower(word1)](curUser,string.sub(data,4+string.len(curUser.sName),string.len(data)-1),1) 
	return 1 
		end 
	end
end
function ToArrival(curUser,data)
	if string.sub(data,6,5+(string.len(bot))) == bot then 
		pmmsg = string.sub(data,(18+string.len(bot)+2*string.len(curUser.sName)),(string.len(data)-1)) 
		local _,_,word1 = string.find(pmmsg,"^(%S+)") 
		if word1 and VGFUNCS[string.lower(word1)] then 
			VGFUNCS[string.lower(word1)](curUser,pmmsg) 
		elseif (VGPlayers[string.lower(curUser.sName)]) and tonumber(word1) and gameTrigs[tonumber(word1)] then 
			Play4G(curUser,tonumber(word1)) 
		elseif word1 and VGChat[string.lower(curUser.sName)] and VGFUNCS[string.lower(word1)] then 
			VGFUNCS[string.lower(word1)](curUser) 
		elseif VGChat[string.lower(curUser.sName)] then 
			local curUser1 = GetItemByName(VGChat[string.lower(curUser.sName)][1]) 
			if curUser1 then 
				curUser1:SendData("$To: "..curUser1.sName.." von: "..bot.." $<"..curUser.sName.."> "..pmmsg) 
				ResetChat(string.lower(curUser.sName)) 
			else 
				curUser1:SendPM(bot,"Other Player went offline.")
				DelChat(string.lower(curUser.sName)) 
				 
			end 
		end 
	end 
end 

function OnExit() 
WriteTable(VGFolder.."/"..VGScoresFile,VGScores,"VGScores") 
end 

-- ************* GAME FUNCTIONS ************* 

-- RESET A CHAT SESSION 

function ResetChat(curNick1) 
VGChat[VGChat[curNick1][1]][2] = 0 
VGChat[curNick1][2] = 0 
end 

-- DELETE A CHAT SESSION 

function DelChat(curNick1) 
VGChat[VGChat[curNick1][1]] = nil 
VGChat[curNick1] = nil 
end 

-- SHOW CURRENT GAME 

function GetCurGame(table) 
local VierGewinntFeld = "\r\n\r\n".. "\t\t 1 2 3 4 5 6 7\r\n\r\n" 
local count = 0 
	for i = 1,6 do 
		count = count + 1 
		VierGewinntFeld = VierGewinntFeld.."\t\t "..table[count][1] 
		for i2 = 1,7 do 
			if i2 == 7 then 
			VierGewinntFeld = VierGewinntFeld.."\r\n\t\t______________________________________________________\r\n\r\n " 
		else 
			count = count + 1 
			VierGewinntFeld = VierGewinntFeld.." l "..table[count][1] 
			end 
		end 
	end 
return(VierGewinntFeld) 
end 

-- CREATE A GAME 

function CreateGame(curNick1,curNick2) 
curGames[curNick1.."$"..curNick2] = { 
players = { curNick1,curNick2 }, 
toPlay = { curNick2,playchar1 }, 
game = {}, 
plays = 0, 
timeout = 0, 
} 
VGPlayers[curNick1] = { 
PlaysWith = curNick2, 
curGame = curNick1.."$"..curNick2, 
} 
VGPlayers[curNick2] = { 
PlaysWith = curNick1, 
curGame = curNick1.."$"..curNick2, 
} 
VGChat[curNick1] = { curNick2,0 } 
VGChat[curNick2] = { curNick1,0 } 
	for _ = 1,42 do 
		table.insert(curGames[curNick1.."$"..curNick2].game,{ " ",0 }) 
	end 
end
Ignorance is Bliss.

Dessamator

#2
part 2:
-- DELETE A GAME 

function DelGame(curUser) 
local nick2 = VGPlayers[string.lower(curUser.sName)].PlaysWith 
local game = VGPlayers[string.lower(curUser.sName)].curGame 
curGames[game] = nil 
VGPlayers[string.lower(curUser.sName)] = nil 
VGPlayers[nick2] = nil 
end 

-- CHECK IF SOMEONE HAS WON 

function doCheckForWin(curGame,char,index,line,chink) 

--Up --> Down 
local count = 0 
	for i = 0,5 do 
		if curGame[(chink+7*i)][1] == char then 
			count = count + 1 
			if count == 4 then 
				return("WON") 
			end 
		else 
	count = 0 
	end 
end 

--Left --> Right 
local count = 0 
local begin = 7*line 
	for i = 1,7 do 
		if curGame[(begin+i)][1] == char then 
		count = count + 1 
			if count == 4 then 
				return("WON") 
			end 
		else 
	count = 0 
	end 
end 

--UpLeft --> DownRight 
local diffline = line 
local diffchink = chink - 1 
local mult = 0 
	if diffchink <= diffline then 
		mult = diffchink 
	else 
		mult = diffline 
	end 
		local sindex = index - mult*8 
		local count = 0 
	for _ = 1,Matrix.TL[sindex] do 
		if (curGame[sindex][1] == char) then 
			count = count + 1 
		if count == 4 then 
			return("WON") 
		end 
		else 
			count = 0 
	end 
		sindex = sindex + 8 
end 

--DownLeft --> UpRight 
local diffline = 5 - line 
local diffchink = chink - 1 
local mult = 0 
	if diffchink <= diffline then 	
		mult = diffchink 
	else 
		mult = diffline 
	end 
		local sindex = index + mult*6 
		local count = 0 
		for _ = 1,Matrix.DL[sindex] do 
			if (curGame[sindex][1] == char) then 
				count = count + 1 
				if count == 4 then 
					return("WON") 
				end 
				else 
					count = 0 
				end 
		sindex = sindex - 6 
	end 
end 

-- INSERT X 

function doInsertX(game,chink,char) 
local mult = 5 
	for _ = 0,5 do 
		if game[(chink+7*mult)][2] == 0 then 
			game[(chink+7*mult)] = { char,1 } 
			if doCheckForWin(game,char,(chink+7*mult),mult,chink) == "WON" then 
				return game,"WON" 
			else 
				return game,"PLAY" 
			end 
		end 
				mult = mult - 1 
	end 
return("FAILED") 
end 

-- PLAY ONE ROUND 

function Play4G(curUser,num1) 

local sGame = curGames[VGPlayers[string.lower(curUser.sName)].curGame].game 
	if (string.lower(curUser.sName) == curGames[VGPlayers[string.lower(curUser.sName)].curGame].toPlay[1]) then 
		if GetItemByName(VGPlayers[string.lower(curUser.sName)].PlaysWith) then 
			ResetChat(string.lower(curUser.sName)) 
			local curUser1 = GetItemByName(VGPlayers[string.lower(curUser.sName)].PlaysWith) 
			local char = curGames[VGPlayers[string.lower(curUser.sName)].curGame].toPlay[2] 
			local sGame,wp = doInsertX(sGame,num1,char) 
			if (sGame ~= "FAILED") then 
				curGames[VGPlayers[string.lower(curUser.sName)].curGame].game = sGame 
				curGames[VGPlayers[string.lower(curUser.sName)].curGame].timeout = 0 
				if char == playchar1 then 
					curGames[VGPlayers[string.lower(curUser.sName)].curGame].toPlay = { string.lower(curUser1.sName),playchar2 } 
				else 
					curGames[VGPlayers[string.lower(curUser.sName)].curGame].toPlay = { string.lower(curUser1.sName),playchar1 } 
				end 
					curUser:SendPM(bot,GetCurGame(sGame)) 
					curUser1:SendPM(bot,curUser.sName.." Fertig... "..num1..", DU bist d?ran!"..GetCurGame(sGame)) 
				if wp == "WON" then 
					curUser:SendPM(bot,"****** Victory! ********") 
					VGScores[curUser.sName] = VGScores[curUser.sName] or { wins = 0, losses = 0, lstreak = 0, cstreak = 0, } 
					VGScores[curUser.sName].wins = VGScores[curUser.sName].wins + 1 
					VGScores[curUser.sName].cstreak = VGScores[curUser.sName].cstreak + 1 
					if VGScores[curUser.sName].cstreak > VGScores[curUser.sName].lstreak then 
						VGScores[curUser.sName].lstreak = VGScores[curUser.sName].cstreak 
					end 
						curUser:SendPM(bot,"Your current status: Victories = "..VGScores[curUser.sName].wins..", Defeats = "..VGScores[curUser.sName].losses..", Winning Streak: "..VGScores[curUser.sName].lstreak) 
						curUser:SendPM(bot,"Do you want to play again? Type: \"newgame\"") 

						curUser1:SendPM(bot,"****** Defeat! ********") 
						VGScores[curUser1.sName] = VGScores[curUser1.sName] or { wins = 0, losses = 0, lstreak = 0, cstreak = 0, } 
						VGScores[curUser1.sName].losses = VGScores[curUser1.sName].losses + 1 
						VGScores[curUser1.sName].cstreak = 0 
						curUser1:SendPM(bot,"Your current status: Victories = "..VGScores[curUser1.sName].wins..", Defeats = "..VGScores[curUser1.sName].losses..", Winning Streak: "..VGScores[curUser1.sName].lstreak) 
						curUser1:SendPM(bot,"You want to begin a new game?  Write : \"newgame\"") 

						DelGame(curUser) 
				return 
				elseif wp == "PLAY" then 
					curGames[VGPlayers[string.lower(curUser.sName)].curGame].plays = curGames[VGPlayers[string.lower(curUser.sName)].curGame].plays + 1 
					if curGames[VGPlayers[string.lower(curUser.sName)].curGame].plays == 42 then 
	
						curUser:SendPM(bot,"****** Undecided ********") 
						curUser:SendPM(bot,"Your current status: Victories = "..VGScores[curUser.sName].wins..", Defeats = "..VGScores[curUser.sName].losses..", Winning Streak: "..VGScores[curUser.sName].lstreak)  
						curUser1:SendPM(bot,"You want to begin a new game?  Write : \"newgame\"") 
	
						curUser1:SendPM(bot,"****** GAME ENDED EVEN ********") 
						curUser:SendPM(bot,"Your current status: Victories = "..VGScores[curUser.sName].wins..", Defeats = "..VGScores[curUser.sName].losses..", Winning Streak: "..VGScores[curUser.sName].lstreak)  
						curUser1:SendPM(bot,"You want to begin a new game?  Write : \"newgame\"") 

					DelGame(curUser) 
					return 
					end 
				end 
			end 
	else 
		curUser1:SendPM(bot,"Other Player went offline.") 
		DelGame(curUser,curUser1) 
		DelChat(string.lower(curUser.sName)) 
		end 
	end 
end 

-- Write Tables 


function WriteTable(file , table , tablename)
	local handle = io.open(file,"w+")
        handle:write(Serialize(table, tablename))
	handle:flush()
        handle:close()
end 


function Serialize(tTable, sTableName, sTab)
        assert(tTable, "tTable equals nil");
        assert(sTableName, "sTableName equals nil");

        assert(type(tTable) == "table", "tTable must be a table!");
        assert(type(sTableName) == "string", "sTableName must be a string!");

        sTab = sTab or "";
        sTmp = ""

        sTmp = sTmp..sTab..sTableName.." = {\n"

        for key, value in tTable do
                local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);

                if(type(value) == "table") then
                        sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
                else
                        local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
                        sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
                end

                sTmp = sTmp..",\n"
        end

        sTmp = sTmp..sTab.."}"
        return sTmp
end

function doInvite(curUser,invited,ret) 
	if invited and (not VGPlayers[string.lower(curUser.sName)]) and GetItemByName(invited) and (not VGPlayers[string.lower(invited)]) then 
		tInvite[string.lower(invited)] = { 0,string.lower(curUser.sName) } 
		curUser:SendPM(bot,"Sending invitation to "..invited.."!") 
	GetItemByName(invited):SendPM(bot,curUser.sName.." Has invited you to play ! accept or deny?...") 
	else 
		if ret then 
			curUser:SendData(tbot,"Either you already playing or your Partner is OFF!") 
		else 
			curUser:SendPM(tbot,"Either you already playing or your Partner is OFF!") 
		end 
	end 
end 

-- VG TABLE FUNCS 

VGFUNCS = { 
["invite"] = function(curUser,sdata,ret) 
local _,_,invited = string.find(sdata,"^%S+%s+(%S+)") 
local invited = invited or "$" 
doInvite(curUser,invited,ret) 

end, 
["quit"] = function(curUser) 
	if VGPlayers[string.lower(curUser.sName)] then 
		curUser:SendPM(bot,"! Game Over !") 
		local curUser2 = GetItemByName(VGPlayers[string.lower(curUser.sName)].PlaysWith) 
		curUser2:SendPM(bot,curUser.sName.."The Game is Over...") 
		DelGame(curUser) 
	end 
end, 
["accept"] = function(curUser) 
	if tInvite[string.lower(curUser.sName)] then 
		if GetItemByName(tInvite[string.lower(curUser.sName)][2]) and (not VGPlayers[tInvite[string.lower(curUser.sName)][2]]) then 
			local curUser2 = GetItemByName(tInvite[string.lower(curUser.sName)][2]) 
			CreateGame(string.lower(curUser.sName),string.lower(curUser2.sName)) 
			curUser2:SendPM(bot,curUser.sName.." nimmt an...") 
			curUser2:SendPM(bot,GetCurGame(curGames[VGPlayers[string.lower(curUser2.sName)].curGame].game)) 
			curUser:SendPM(bot,"Waiting for "..curUser2.sName.." to start...") 
		else 
			curUser:SendPM(bot,"Either the other player is OFF or your already playing!") 
		end 
			tInvite[string.lower(curUser.sName)] = nil 
	end 
end, 
["deny"] = function(curUser) 
	if tInvite[string.lower(curUser.sName)] then 
		curUser:SendPM(bot,"Challenge Rejected!") 
		GetItemByName(tInvite[string.lower(curUser.sName)][2]):SendPM(bot,"Challenge Rejected! ^^") 
		tInvite[string.lower(curUser.sName)] = nil 
	end 
end, 
["topscore"] = function(curUser,_,ret) 
local ATable = {} 
table.foreach(VGScores, function(i,v) table.insert(ATable, { i,v }) end) 
local msg = "--- TOP "..Max1.." Connect 4 Status ---\r\n" 

table.sort(ATable, function(a,b) return(a[2].wins > b[2].wins) end) 
local msg = msg.."\r\n\t--- TOP-Winner ---\r\n\r\n" 
	for i = 1,Max1 do 
		if ATable[i] then 
			msg = msg.."\t# "..i.." - "..ATable[i][1].." With: "..ATable[i][2].wins.." Victories, "..ATable[i][2].losses.." defeats, "..ATable[i][2].lstreak.." Streak\r\n" 
		end 
	end 

table.sort(ATable, function(a,b) return(a[2].lstreak > b[2].lstreak) end) 
local msg = msg.."\r\n\t--- TOP-Streak ---\r\n\r\n" 
	for i = 1,Max1 do 
		if ATable[i] then 
		msg = msg.."\t# "..i.." - "..ATable[i][1].." With: "..ATable[i][2].lstreak.." Streak, "..ATable[i][2].wins.." Victories, "..ATable[i][2].losses.." Defeats\r\n" 
	end 
end 

table.sort(ATable, function(a,b) return(a[2].losses > b[2].losses) end) 
local msg = msg.."\r\n\t--- TOP-Loser ---\r\n\r\n" 
	for i = 1,Max1 do 
		if ATable[i] then 
			msg = msg.."\t# "..i.." - "..ATable[i][1].." With: "..ATable[i][2].losses.." Losses, "..ATable[i][2].wins.." Victories, "..ATable[i][2].lstreak.." Streak\r\n" 
		end 
	end 
	if ret then 
		curUser:SendData(bot,msg) 
	else 
		curUser:SendPM(bot,msg) 
	end 
end, 
["myscore"] = function(curUser,_,ret) 
VGScores[curUser.sName] = VGScores[curUser.sName] or { wins = 0, losses = 0, lstreak = 0, cstreak = 0, } 
	if ret then 
		curUser:SendData(bot,"Your Status: ".. VGScores[curUser.sName].wins.." Victories, ".. VGScores[curUser.sName].losses.." losses, ".. VGScores[curUser.sName].lstreak.." Streak") 
	else 
		curUser:SendPM(bot,"Your Status: ".. VGScores[curUser.sName].wins.." Victories, ".. VGScores[curUser.sName].losses.." losses, ".. VGScores[curUser.sName].lstreak.." Streak") 
	end 
end, 
["newgame"] = function(curUser) 
doInvite(curUser,VGChat[string.lower(curUser.sName)][1]) 
end, 
["help"] = function(curUser,_,ret) 
	if ret then 
		curUser:SendData(bot,VGHelp) 
	else 
		curUser:SendPM(bot,VGHelp) 
	end 
end, 
}
Ignorance is Bliss.

B@B?

#3
G??????nial!

That was, what i?d looked 4... THX!!!  :P
THE DAY AFTER...  

...is >>>>>>>> NOW!




Btw:
Plz excuse my english...
It?s not the best, i?m sure...but it?s funny...isn?t it?

Dessamator

QuoteOriginally posted by B@B€
G??????nial!

That was, what i?d looked 4... THX!!!  :P
ur welcome , i still have to add 1 more of his games, later on, if somebody doesnt do it first !
Ignorance is Bliss.

B@B?

YeZzzzz please!  :D

More?n more...

I love games like this.  ;)
THE DAY AFTER...  

...is >>>>>>>> NOW!




Btw:
Plz excuse my english...
It?s not the best, i?m sure...but it?s funny...isn?t it?

Dessamator

QuoteOriginally posted by B@B€
YeZzzzz please!  :D

More?n more...

I love games like this.  ;)

lol, ok, but the last one he made was a quite different, it was a chess script, dunno if ull like it, :)
Ignorance is Bliss.

-=NYC=-Hemarr

Do i use both this scripts independently or should i join them
Thanks

(-=TrIp-iN-SuN=-)

it's type me
Syntax [string "--Lua 5 By Dessamator
..."]:175: unexpected symbol near `&'

Dessamator

QuoteOriginally posted by -=NYC=-Hemarr
Do i use both this scripts independently or should i join them
Thanks
well for the second script, which has part 1 and 2, u join them, the first one u must use independently !
Ignorance is Bliss.

-=NYC=-Hemarr

I get the same thing

Syntax [string "--Lua 5 By Dessamator
..."]:175: unexpected symbol near `&'


also does it create the folder named

VGScoresFile = "VGScores.txt" --The Scores File
VGFolder = "Games" --The Games Folder

Dessamator

QuoteOriginally posted by -=NYC=-Hemarr
I get the same thing

Syntax [string "--Lua 5 By Dessamator
..."]:175: unexpected symbol near `&'


also does it create the folder named

VGScoresFile = "VGScores.txt" --The Scores File
VGFolder = "Games" --The Games Folder

DONE, error corrected, should work now, hopefully, :)
Ignorance is Bliss.

-=NYC=-Hemarr

DONE, error corrected, should work now, hopefully,



where is it

Dessamator

QuoteOriginally posted by -=NYC=-Hemarr
DONE, error corrected, should work now, hopefully,



where is it
lol,sorry forgot to say, post edited above, just copy it again(the entire script part1 and part 2), it should work now :D
Ignorance is Bliss.

-=NYC=-Hemarr

Ok got the script working but cant find commands

any ideas where to look for them

B@B?

#15
Hiho Hemarr! :)

Send the "help"-command as PM 2 the game-bot- here PM 2 >>> "connect4"...

Hope the followin helps?:

help
--- Connect 4-Help ---

    Main Chat
   -----------------------------------
   invite ?Connect4 - Challenge Users
   topscore ?Connect4 - TOP-Scorer
   myscore ?Connect4 - Your Score
   help ?Connect4 - This Help

    PM to ?Connect4
   -----------------------------------
   invite - Challenge User
   quit - Quit
   topscore - TOP-Scorer
   myscore - Your Score
   help - This Help

<[D@]B@B??> invite [D@]B@B??
Sending invitation to [D@]B@B??!
[D@]B@B?? Has invited you to play ! accept or deny?...
<[D@]B@B??> accept
[D@]B@B?? nimmt an...


       1 2 3 4 5 6 7 etc. (cutted)
 
Waiting for [D@]B@B?? to start...
<[D@]B@B??> quit
! Game Over !
[D@]B@B??The Game is Over...

btw: for TTT you need the same commands but theres no "help" string...
PM 2 da bot (here TicTacToe) and INVITE  someone, same as every...

MfG  :D
THE DAY AFTER...  

...is >>>>>>>> NOW!




Btw:
Plz excuse my english...
It?s not the best, i?m sure...but it?s funny...isn?t it?

B@B?

#16
@ Dessamator:

[/QUOTE]

lol, ok, but the last one he made was a quite different, it was a chess script, dunno if ull like it, :)
[/QUOTE]

I do so...  :P
THE DAY AFTER...  

...is >>>>>>>> NOW!




Btw:
Plz excuse my english...
It?s not the best, i?m sure...but it?s funny...isn?t it?

Dessamator

#17
nice one B@B€, i guess i should add help for both of them !,its basically the same.

first send a private msg to the bot, connect4, or tictactoe, and invite the user to play then

playing  connect4: just choose the write the number of where u  want to begin ex: 1,and wait for ur opponent to play

playing tictactoe: just choose where u want to begin write it ex.: A1,and wait for ur opponent to play
other commands are quit, deny, help, topscore

ps.: no "!" is required just type the word

ill add right clicks ASAP(less than a week),:)
Have Fun !
Ignorance is Bliss.

B@B?

...and SO:

YOU HAVE FUN!!!  :D

*****************************************

@ Dessamator:

[/QUOTE]

lol, ok, but the last one he made was a quite different, it was a chess script, dunno if ull like it,  
[/QUOTE]

I do so..
THE DAY AFTER...  

...is >>>>>>>> NOW!




Btw:
Plz excuse my english...
It?s not the best, i?m sure...but it?s funny...isn?t it?

Dessamator

#19
ok babe here it is :

Chess v011

the commands are in the right click, and so is the help, have fun, :)
Ignorance is Bliss.

B@B?

G R E A T!

...and works fine.

Thx a lot of!  ;)
THE DAY AFTER...  

...is >>>>>>>> NOW!




Btw:
Plz excuse my english...
It?s not the best, i?m sure...but it?s funny...isn?t it?

Dessamator

QuoteOriginally posted by B@B€
G R E A T!

...and works fine.

Thx a lot of!  ;)
ur welcome :)
Ignorance is Bliss.

Bobby1999

[20:35] Syntax cannot read Games/VGScores.txt: No such file or directory



Got chess working ok +TTT

Created folder games/text VGScores.txt:


Still get the same error
Running ptokax 17.08
Robo 10.01e

Dessamator

Done !

script edited, copy it again  !
Ignorance is Bliss.

kEwL

the chess script doesnt work for me

SMF spam blocked by CleanTalk