Ir para conteúdo

Tic Tac Toe


Posts Recomendados

  • Nome: TIC TAC TOE GAME
  • Autor: sailorv5
  • Servidor Testado: Original Tibia 9.80 - Cliente 9.80
  • Descrição e/ou Informações Adicionais: é um NPC inteligente capaz de jogar o jogo da velha (3 niveis, fácil, médio e pro)
  • Scripts e Como Instalar: ver abaixo

Como Instalar -

Vá em data/npc, crie um arquivo .xml com o nome de GM tic tac e adicione isso -

<?xml version="1.0"?>
<npc name="Master of tic tac toe" script="data/npc/scripts/games/tictactoe.lua" access="9" lookdir="3">
<health now="1000000" max="1000000"/>
<look type="266" head="0" body="0" legs="0" feet="0"/>
</npc>

 

Depois, ainda na pasta npc, vá na pasta scripts. Crie uma pasta chamada games. Dentro dela, crie um arquivo .lua com o nome

de tictactoe e adicione isto -

 

dofile(getDataDir() .. "npc/scripts/games/tictactoeVAR.lua")
dofile(getDataDir() .. "npc/scripts/games/tictactoeFUNC.lua")

local focus = 0
local talk_start = 0
local target = 0
local following = false
local attacking = false



function onThingMove(creature, thing, oldpos, oldstackpos)

end


function onCreatureAppear(creature)

end


function onCreatureDisappear(cid, pos)
  if focus == cid then
	  selfSay('Good bye then.')
	  focus = 0
	  talk_start = 0
  end
end


function onCreatureTurn(creature)

end


function msgcontains(txt, str)
  return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))
end


function creatureGetName	(cid)
	return getCreatureName(cid)
end


function onCreatureSay(cid, type, msg)
  msg = string.lower(msg)


  if (msgcontains(msg, 'hi') and (focus == 0)) and getDistanceToCreature(cid) < 4 then

		selfSay( getCreatureName(cid) ..' Isnt a good day today to play ?')
		doPlayerSendTextMessage(cid,18,"voce pode somente responder (yes,rules,bye)")
		focus = cid
		talk_start = os.clock()
  elseif msgcontains(msg, 'hi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then

	  selfSay('Sorry, ' .. creatureGetName(cid) .. '! I talk to you in a minute.')
	doPlayerSendTextMessage(cid,18,"lamento mais tera que esperar!")

  elseif focus == cid then
	talk_start = os.clock()

	if msgcontains(msg, 'yes') then

		selfSay( creatureGetName(cid) ..' SO get ready the game start now.  ')
		doPlayerSendTextMessage(cid,18,"Playing")


	tokenPiecePlayer = doCreateItemEx(playerToken, 5)
	--	doItemSetAttribute(tokenPiecePlayer, "description", "GM VS " .. getCreatureName(cid) .. ".")
	doPlayerAddItemEx(cid, tokenPiecePlayer, 5, true)


tttturncount = 1
clearField( pos, field  )

		setPlayerStorageValue(cid, tttconfig.storage, tttconfig.storageData)
		selfSay('  Lets see who go First...'  )


	elseif msgcontains(msg, 'rules') and getDistanceToCreature(cid) < 4 then
		doPlayerSendTextMessage(cid,18,"BYE")
		selfSay('PLS Visit http://en.wikipedia.org/wiki/Tic-tac-toe')
		focus = 0
		talk_start = 0
		tttturncount = 0
	elseif msgcontains(msg, 'bye') and getDistanceToCreature(cid) < 4 then
		doPlayerSendTextMessage(cid,18,"BYE")
		selfSay('Good bye, ' .. creatureGetName(cid) .. '!')
		focus = 0
		talk_start = 0
		tttturncount = 0
	end

end
end


function onCreatureChangeOutfit(creature)

end


function onThink()
cid = focus

	if (os.clock() - talk_start) > 5
	and (tttturncount>0)  then

ttPlayerMovesFt = tttPlayerMoves( pos, field , playerToken, true )
ttNpcMoves = tttPlayerMoves( pos, field , npcToken, true )	--tttnpcMove
tttlistofdanger= table.counter(goingtoWinPos, ttPlayerMovesFt)
tttlistdotowin= table.counter(goingtoWinPos, ttNpcMoves)
checkforcheater( pos, field, token)


		if tokenCount( pos, field , token ) > tttturncount  then
			selfSay('  I dont Play With Cheater like You' .. ' come back if u want to play for FUN. CHEATER...'  )
			focus = 0
			tttturncount = 0
		end
		if tttgamewinner(winnerPos, ttPlayerMovesFt) ~= false or tttgamewinner(winnerPos, ttNpcMoves) ~=false		 then
			selfSay(' Game Over Guess who won?  that was a nice game,  BUT a LOST one... bye '  )
			focus = 0
			tttturncount = 0
		else
			if playerTurn == 2  then
				if tokenCount( pos, field , token  ) == tttturncount  then
					selfSay('so easy  ' .. whoPlay[playerTurn] .. ' .'  )
						playerTurn = 1
						tttturncount = tttturncount +1
						talk_start = os.clock()
				else
--						print (tokenCount( pos, field , token ))
					selfSay(' Waitting...  Fast pls -.- ' ..tttturncount  )
				end

			else
				selfSay('what u think?  ' .. whoPlay[playerTurn] .. ' .'.. creatureGetName(cid)  )
				dofile(getDataDir() .. "npc/scripts/games/tictactoeLVhard.lua")

--					checkfield( cid,tttconfig, pos, field , playerToken , tttPlayerMoves( pos, field, playerToken ) )

				playerTurn = 2
				tttturncount = tttturncount +1
				talk_start = os.clock()
--					print ("can u do better")
			end
		  end
	  if tttturncount > 9   then
			selfSay(' Game Over and NO Winner, u not that all BAD... bye '  )
			focus = 0
			tttturncount = 0
	  end
--				print (tttturncount)
	end

  if (os.clock() - talk_start) > 40 then
	  if focus > 0 then
		  selfSay(' You make me sleep, BYE... ')
	  end
		  focus = 0
		tttturncount = 0
  end
if focus ~= 0 then
	 if getDistanceToCreature(focus) > 5 then
		 selfSay('Good bye then.')
		 focus = 0
		tttturncount = 0
	 end
 end
end

 

 

Agora na mesma pasta, crie um arquivo .lua com o nome de tictactoeVAR e adicione isto -

 

pos = {x = 994, y = 1512, z = 8}
field = {	
	{
	 {position ={x = pos.x+0, y = pos.y, z=pos.z,stackpos=1}},	-- field[1][1]	1st square
	 {position ={x = pos.x+1, y = pos.y, z=pos.z,stackpos=1}},
	 {position ={x = pos.x+2, y = pos.y, z=pos.z,stackpos=1}}	-- field[1][3]	last square of 1st line
	},
	{
	 {position ={x = pos.x+0, y = pos.y+1, z=pos.z,stackpos=1}},
	 {position ={x = pos.x+1, y = pos.y+1, z=pos.z,stackpos=1}},	-- field[2][2]  middle position
	 {position ={x = pos.x+2, y = pos.y+1, z=pos.z,stackpos=1}}
	},
	{
	 {position ={x = pos.x+0, y = pos.y+2, z=pos.z,stackpos=1}},	-- field[3][1]	1st square of last line
	 {position ={x = pos.x+1, y = pos.y+2, z=pos.z,stackpos=1}},
	 {position ={x = pos.x+2, y = pos.y+2, z=pos.z,stackpos=1}}
	}	--	field[3][3], last square
}




conner = {
		field[1][1],
		field[1][3],
		field[3][1],
		field[3][3]
}

goingtoWinPos = {

		{ field[1][1], field[1][2] },		-- 1	
		{ field[2][1], field[2][2] },
		{ field[3][1], field[3][2] },

		{ field[1][3], field[1][2] },
		{ field[2][3], field[2][2] },
		{ field[3][3], field[3][2] },

		{ field[1][1], field[2][1] },		--	7
		{ field[1][2], field[2][2] },		--	8
		{ field[1][3], field[2][3] },

		{ field[3][1], field[2][1] },
		{ field[3][2], field[2][2] },
		{ field[3][3], field[2][3] },

		{ field[1][1], field[2][2] },		--	13
		{ field[3][3], field[2][2] },

		{ field[1][3], field[2][2] },		--	15
		{ field[3][1], field[2][2] },

		{ field[1][1], field[3][3] },		--	17
		{ field[1][3], field[3][1] },

		{ field[1][1], field[1][3] },
		{ field[2][1], field[2][3] },
		{ field[3][1], field[3][3] },

		{ field[1][1], field[3][1] },
		{ field[1][2], field[3][2] },
		{ field[1][3], field[3][3] }

}


counterWinPos = {

		field[1][3],
		field[2][3],
		field[3][3],

		field[1][1],
		field[2][1],
		field[3][1],

		field[3][1],
		field[3][2],
		field[3][3],

		field[1][1],
		field[1][2],
		field[1][3],

		field[3][3],
		field[1][1],

		field[3][1],
		field[1][3],

		field[2][2],
		field[2][2],

		field[1][2],
		field[2][2],
		field[3][2],

		field[2][1],
		field[2][2],
		field[2][3]


}

npclv = {
		{
			{ field[1][1], field[3][3], field[2][2], field[3][1] },
			{ field[3][3], field[3][1], field[3][2], field[1][3] },
			{ field[1][3], field[3][3], field[2][3], field[2][1] },		--3 1

			{ field[1][1], field[3][3], field[1][3], field[2][3] },
			{ field[1][2], field[1][3], field[3][1], field[3][2] },		--5 1
			{ field[2][2], field[1][3], field[3][1], field[2][1] },		--6 1

			{ field[2][1], field[3][1], field[3][3], field[2][1] },
			{ field[3][2], field[2][3], field[3][3], field[3][2] },
			{ field[2][1], field[3][1], field[3][3], field[2][1] }
		},
		{
			{ field[3][1], field[1][3], field[1][1], field[2][1] },
			{ field[3][1], field[1][3], field[1][1], field[1][2] },
			{ field[3][1], field[1][3], field[3][3], field[2][3] },

			{ field[3][1], field[1][3], field[3][3], field[3][2] },
			{ field[3][1], field[1][1], field[3][3], field[2][3] },
			{ field[3][1], field[1][1], field[3][3], field[3][2] },

			{ field[3][1], field[3][3], field[1][3], field[3][2] },
			{ field[3][1], field[3][3], field[1][3], field[2][3] },
			{ field[3][1], field[3][3], field[1][3], field[2][3] }
		},
		{
			{ field[3][3], field[1][1], field[3][1], field[2][1] },
			{ field[3][3], field[1][1], field[3][1], field[3][2] },
			{ field[3][3], field[1][1], field[1][3], field[1][2] },

			{ field[3][3], field[1][1], field[1][3], field[2][3] },
			{ field[3][3], field[1][3], field[3][1], field[3][2] },
			{ field[3][3], field[1][3], field[3][1], field[2][3] },

			{ field[3][3], field[3][1], field[1][1], field[2][1] },
			{ field[3][3], field[3][1], field[1][1], field[3][2] },
			{ field[3][3], field[3][1], field[1][1], field[3][2] }
		}


}

winnerPos = {
		field[1],
		field[2],
		field[3],

		{ field[1][1], field[2][1], field[3][1] },
		{ field[1][2], field[2][2], field[3][2] },
		{ field[1][3], field[2][3], field[3][3] },

		{ field[1][1], field[2][2], field[3][3] },
		{ field[1][3], field[2][2], field[3][1] }
}




tttconfig = {
	storage = 931699  , -- change to your own storage value 
	storageData= "ttt , " ..1 .. " , " .. 1
--		storageData= "ttt , " ..math.random(1,3) .. " , " .. 1			-- math.random(1,3) for random npc level 1 most hard 3 noob moves.

}




npcMove = {}
tttnpcMove = {}
ttPlayerMovesFt = {}
ttNpcMoves = {}

tttturncount = 0


token = { 2638, 2639 }	-- X  or O
playerToken =	token[2]
npcToken = token[1]

local notworkingdontknowhyif = [[
token = { 2638, 2639 }	-- X  or O
playerToken = token[math.random(1,2)]
playerToken == 1 then
npcToken = token[2]
else
npcToken = token[1]
end
]]






playerTurn = math.random(1,2)
if playerTurn == 2  then
whoPlay = { 'Your turn', 'My turn' }
else
whoPlay = { 'My turn', 'Your turn' }
end

 

 

Agora crie um arquivo .lua com nome de tictactoeFUNC e adicione isto -

 

function getArrayStorageValue( cid, key )
objProp = {}
getArrayfromKey = getPlayerStorageValue(cid, key)
index = 1
for value in string.gmatch(getArrayfromKey,"%w+") do
	objProp [index] = value
	index = index + 1
end
return objProp
end


function clearField( pos, field  )
local i = true
while i do
	i = false
	for _, col in ipairs(field) do
		for _, square in ipairs(col) do
			local item = getThingfromPos(square.position)
			if item.itemid ~= 0 then doRemoveItem(item.uid, 1) i = true	end
		end
	end
end
return true
end

function checkforcheater( pos, field, token)
local i = true
while i do
	i = false
	for _, col in ipairs(field) do
		for _, square in ipairs(col) do
			local item1 = getTileItemById(square.position, token[1])

			local item2 = getTileItemById(square.position, token[2])

			local item3 = getThingfromPos( square.position )

			if item1.itemid == token[1] and item2.itemid == token[2] then
					if item3.itemid ~= 0 then doRemoveItem(item3.uid, 1)	end
					i = true
			end
			if item3.itemid ~= 0 and not(item3.itemid == token[1] or item3.itemid == token[2])  then
					doRemoveItem(item3.uid, 1)
					i = true
			end
		end
	end
end
	return i
end




function tokenCount(  pos, field , token   )
tcount = 0
for _, col in ipairs(field) do
	for _, square in ipairs(col) do
			local item = getThingfromPos(square.position)
			if item.itemid == token[1]  or item.itemid == token[2] then
				tcount= tcount +1
			end
	end
end
return tcount
end




function table.contains(table, element)
 for _, value in pairs(table) do
if value == element then
  return true
end
 end
 return false
end



function table.counter(tctable, element)
tttiii = {}
for k1, v1 in pairs( element ) do
	for k2, v2 in pairs( tctable ) do
		if ( v2[1].position.x == v1.position.x ) and ( v2[1].position.y == v1.position.y ) then
		  for _, v3 in pairs(element) do
			if v3.position.x == v2[2].position.x and ( v2[2].position.y == v3.position.y ) then
				table.insert(tttiii,k2)
			end
		  end
		end
	end
end
if next(tttiii) == nil then return false else return tttiii  end
end


function tttgamewinner(tctable, element)
tttiii = {}
for k1, v1 in pairs( element ) do
	for k2, v2 in pairs( tctable ) do
		if ( v2[1].position.x == v1.position.x ) and ( v2[1].position.y == v1.position.y ) then
--				print "v2"
		  for _, v3 in pairs(element) do
			if v3.position.x == v2[2].position.x and ( v2[2].position.y == v3.position.y ) then
--					print "v3"
				for _, v4 in pairs(element) do
--						print "looking for v4"
					if v4.position.x == v2[3].position.x and ( v2[3].position.y == v4.position.y ) then
--							print "v4"
						table.insert(tttiii,k2)
					end
				end
			end
		  end
		end
	end
end
if next(tttiii) == nil then return false else return tttiii  end
end


function	tttPlayerMoves( pos, field , playerToken, FET )	--	FET = [defalt = return empt table ]	[false = return false]
playerMove = {}
for _, col in ipairs(field) do
	for _, square in ipairs(col) do
		local item = getThingfromPos(square.position)
		if item.itemid == playerToken   and   table.contains(playerMove, square)  ~= true then
			table.insert(playerMove,square)
		end
	end
end
if next(playerMove) == nil then if FET==false then return false else return {} end else return playerMove  end	
end



function tttnpcnextmove( cid, tttconfig, npclv, playerMove, npcMove )
tictacpara = getArrayStorageValue( cid, tttconfig.storage )
tictaclv = tonumber(tictacpara[2])
tictacstra = tonumber(tictacpara[3])

--		print (tictaclv .." " .. tictacstra )
--		print "_____"
tttjjj = {}
for i=1, 9 do

  for j=1,4 do
	if  i ==  tictacstra  then
--			print ( i .." j " ..j )
		if table.contains(playerMove, npclv[tictaclv][i][j]) ~= true and table.contains(npcMove, npclv[tictaclv][i][j]) ~= true	 then
--				print "pt1"
--				print ("x " ..npclv[tictaclv][i][j].position.x .."y"..npclv[tictaclv][i][j].position.y .."z"..npclv[tictaclv][i][j].position.z	)
--				print "_____"
			return npclv[tictaclv][i][j]
		elseif table.contains(playerMove, npclv[tictaclv][i][j]) == true then
--				print "pt2"
--				print "_____"
			tictacstra = tictacstra +1
			storageData= "ttt , " ..tictaclv .. " , " .. tictacstra
			setPlayerStorageValue(cid, tttconfig.storage, storageData)
		else
--				print "pt3"
			i=i
		end
	end
  end
end
--
return {}	--	false
end

 

 

Agora crie outro arquivo .lua com o nome de tictactoeLVhard e adicione isto -

 

if tttlistdotowin ~= false then
			for i,line in ipairs(tttlistdotowin) do
				gettoken = getThingfromPos( counterWinPos[line].position )
				if  gettoken.itemid ~= npcToken then		--		i == #tttlistdotowin and
					tttplayheretowin = line
				end
			end
		end







--	function checkfield( cid,tttconfig , pos, field , playerToken, playerMove )

-- print (tttnpcChose[1].position.x,tttnpcChose[1].position.y,tttnpcChose[1].position.z)
--		tttnpcMove	 ttNpcMoves

tttnpcmaxtoken = 1


if	tttturncount == 2 and  table.contains(ttPlayerMovesFt, field[2][2])  ~= true	  then
	if tttnpcmaxtoken > 0 then
		tttnpcmaxtoken = tttnpcmaxtoken -1
		tttnpcChose = field[2][2]
		table.insert(tttnpcMove,tttnpcChose)
		tokenPieceNpc = doCreateItemEx(npcToken, 1)
		doTileAddItemEx( tttnpcChose.position, tokenPieceNpc)
	end
else
	if tttturncount == 4  and table.contains(ttPlayerMovesFt, field[3][2])  ~= true and  table.contains(tttnpcMove, field[2][2])  == true and  table.contains(ttPlayerMovesFt, field[1][2])  ~= true	then
			if tttlistofdanger ~= false		 then
				for i,line in ipairs(tttlistofdanger) do
				  gettoken = getThingfromPos( counterWinPos[line].position )
				  if i == #tttlistofdanger and  gettoken.itemid == npcToken then
--							print "turn 4 pt1"
						if tttnpcmaxtoken > 0 then
							tttnpcmaxtoken = tttnpcmaxtoken -1
							tttnpcChose = field[3][2]
							table.insert(tttnpcMove,tttnpcChose)
							tokenPieceNpc = doCreateItemEx(npcToken, 1)
							doTileAddItemEx( tttnpcChose.position, tokenPieceNpc)
						end
				  else
--						print "turn 4 pt2"
					  if  gettoken.itemid ~= npcToken or gettoken.itemid ~= playerToken		then
						if tttnpcmaxtoken > 0 then
							tttnpcmaxtoken = tttnpcmaxtoken -1
							if gettoken.itemid ~= 0 then doRemoveItem(gettoken.uid, 1)	end
							table.insert(tttnpcMove,counterWinPos[line])
							tokenPieceNpc = doCreateItemEx(npcToken, 1)
							doTileAddItemEx( counterWinPos[line].position, tokenPieceNpc)
						end
					  end
				  end
				end
			else
--					print "turn 4 pt3"
				if tttnpcmaxtoken > 0 then
					tttnpcmaxtoken = tttnpcmaxtoken -1
					tttnpcChose = field[3][2]
					table.insert(tttnpcMove,tttnpcChose)
					tokenPieceNpc = doCreateItemEx(npcToken, 1)
					doTileAddItemEx( tttnpcChose.position, tokenPieceNpc)
				end
			end
	else
-------

------------------		and (getThingfromPos( counterWinPos[tttplayheretowin].position ).itemid == npcToken)
		if tttlistdotowin ~= false and (getThingfromPos( counterWinPos[tttplayheretowin].position ).itemid ~= playerToken)		  then
			--	print ("winning  ! " ..tttnpcmaxtoken)

--						print (getThingfromPos( counterWinPos[tttplayheretowin].position ).itemid)

				gettoken = getThingfromPos( counterWinPos[tttplayheretowin].position )
				if  gettoken.itemid ~= npcToken or gettoken.itemid ~= playerToken then
					if tttnpcmaxtoken > 0 then
						tttnpcmaxtoken = tttnpcmaxtoken -1

						if gettoken.itemid ~= 0 then doRemoveItem(gettoken.uid, 1)	end
						table.insert(tttnpcMove,counterWinPos[tttplayheretowin])
						tokenPieceNpc = doCreateItemEx(npcToken, 1)
						doTileAddItemEx( counterWinPos[tttplayheretowin].position, tokenPieceNpc)
						--	print ("danger pt 2 we did " ..tttnpcmaxtoken)
					end
				end
					--	print " possibility of win "

------------------

		else
			if tttlistofdanger ~= false		 then
				--	print ("danger  ! " ..tttnpcmaxtoken)

				for i,line in ipairs(tttlistofdanger) do
					gettoken = getThingfromPos( counterWinPos[line].position )

					if   gettoken.itemid ~= npcToken then		--	i == #tttlistofdanger and
						tttplayhere = line
					end
				end
--						print (getThingfromPos( counterWinPos[tttplayhere].position ).itemid)

					if (getThingfromPos( counterWinPos[tttplayhere].position ).itemid == npcToken)		 then
						tttnpcChose = tttnpcnextmove( cid, tttconfig , npclv, ttPlayerMovesFt, ttNpcMoves )
						if tttnpcChose ~= nil then
							--	print ("danger pt 1 " ..tttnpcmaxtoken)
							gettoken = getThingfromPos( tttnpcChose.position )
							if  gettoken.itemid ~= npcToken or gettoken.itemid ~= playerToken		then
								if tttnpcmaxtoken > 0 then
									tttnpcmaxtoken = tttnpcmaxtoken -1
									if gettoken.itemid ~= 0 then doRemoveItem(gettoken.uid, 1)	end
									table.insert(tttnpcMove, tttnpcChose )
									tokenPieceNpc = doCreateItemEx(npcToken, 1)
									doTileAddItemEx( tttnpcChose.position, tokenPieceNpc)
--										print ("danger pt 1 we did " ..tttnpcmaxtoken)
								end
							end
						end
				--		print "danger contree"
					else
						gettoken = getThingfromPos( counterWinPos[tttplayhere].position )
						if  gettoken.itemid ~= npcToken or gettoken.itemid ~= playerToken		then
--							print ("danger pt 2 " ..tttnpcmaxtoken)
							if tttnpcmaxtoken > 0 then
								tttnpcmaxtoken = tttnpcmaxtoken -1
								if gettoken.itemid ~= 0 then doRemoveItem(gettoken.uid, 1)	end
								table.insert(tttnpcMove,counterWinPos[tttplayhere])
								tokenPieceNpc = doCreateItemEx(npcToken, 1)
								doTileAddItemEx( counterWinPos[tttplayhere].position, tokenPieceNpc)
--									print ("danger pt 2 we did " ..tttnpcmaxtoken)
							end
						end
					--	print "pas danger"
					end
--					end

			elseif table.counter(goingtoWinPos, ttPlayerMovesFt) ~= true	 then
				--	print ("atk pt 1 " ..tttnpcmaxtoken)
				tttnpcChose = tttnpcnextmove( cid, tttconfig , npclv, ttPlayerMovesFt, ttNpcMoves )
			  if tttnpcChose ~= nil then
				gettoken = getThingfromPos( tttnpcChose.position )
				if  gettoken.itemid ~= npcToken or gettoken.itemid ~= playerToken		then
					if tttnpcmaxtoken > 0 then
						tttnpcmaxtoken = tttnpcmaxtoken -1
						if gettoken.itemid ~= 0 then doRemoveItem(gettoken.uid, 1)	end
						table.insert(tttnpcMove, tttnpcChose )
						tokenPieceNpc = doCreateItemEx(npcToken, 1)
						doTileAddItemEx( tttnpcChose.position, tokenPieceNpc)
					end
				end
			  end
			end
		end

	end
end



--	return error("invalid data from npc.")
--end

 

 

Vídeo -

 

Antes de dizerem "CADE OS CRÉDITOS?!", leiam o tópico.

Link para o comentário
Compartilhar em outros sites

nossa que script macarronico

 

local notworkingdontknowhyif = [[
token = { 2638, 2639 }  -- X  or O
playerToken = token[math.random(1,2)]
playerToken == 1 then
       npcToken = token[2]
else
       npcToken = token[1]
end
]]

uhahsuausahhsau,esse tem que se matar

coloca no lugar isso

playerToken == 2638 then
       npcToken = token[2]
else
       npcToken = token[1]
end

Editado por lordbug99
Link para o comentário
Compartilhar em outros sites

nossa que script macarronico

 

local notworkingdontknowhyif = [[
token = { 2638, 2639 }  -- X  or O
playerToken = token[math.random(1,2)]
playerToken == 1 then
	npcToken = token[2]
else
	npcToken = token[1]
end
]]

uhahsuausahhsau,esse tem que se matar

coloca no lugar isso

playerToken == 2638 then
	npcToken = token[2]
else
	npcToken = token[1]
end

 

Foi eu que fiz worriedsmiley.gif o importante e que funcione nao e ?

 

LuckinhaSan obrigado por trazer aqui :]

 

e pelo que eu to vendo xtibia e o unico forum de tibia que talvez ainda nao esta morto, ( prefiro receber critica do que nao receber nada )

 

ou por que minha ideia nao interessa ninguem :[

Link para o comentário
Compartilhar em outros sites

mais da pra melhora bastante,acho que ficaraia melhor se fosse por action, dai o npc so dava um item(que seria como serviria com caneta pra marca).

Link para o comentário
Compartilhar em outros sites

mais da pra melhora bastante,acho que ficaraia melhor se fosse por action, dai o npc so dava um item(que seria como serviria com caneta pra marca).

 

eu ate pensei em fazer assim mais o player ( nem uma criatura ) nao pode ter acesso ao terreno como vc viu o video,

1 evitar que o player mude os objetos de lugar

 

 

eu ja estou melhorando o codigo pra ficar mais simples (...)

obrigado pelo comentario

Link para o comentário
Compartilhar em outros sites

cara só por uma cerquinha pra n passar,e em vez de de checa os items la(pra ve se ganho) cria alguma variavel que mude quando joga tipo

cada tile com uma string

 

local center = { x = ??, y  = ??, z = ?? }
local s = {
[center.x - 1..","..center.y - 1] = "a",
[center.x ..","..center.y  - 1] = "b",
[center.x + 1..","..center.y - 1] = "c",
[center.x - 1..","..center.y] = "d",
[center.x..","..center.y] = "e",
[center.x + 1..","..center.y] = "f",
[center.x - 1..","..center.y + 1] = "g",
[center.x..","..center.y + 1] = "h",
[center.x + 1..","..center.y  +1] = "i"
}
local turn = 0
local marks = ""
local npcmarks = ""
local pmarks = "" --playermarks
function onUse(cid, item, fpos, itemex, topos)
 if turn = 1 then
 >>mensagen que n é fez dele<<
 end
 if getDistanceBetween(center, topos) <= 1 then
   if not marks:find(s[topos.x..","..tops.y]) then
  marks = marks..s[topos.x..","..tops.y]
  pmarks = pmarks..s[topos.x..","..tops.y]
   turn = 1 -- passa a ser turno
  if  ( #pmarks:gsub('[^abc]',"") = 3 or #pmarks:gsub('[^def]',"") = 3 or #pmarks:gsub('[^ghi]',"") = 3 or #pmarks:gsub('[^adg]',"") = 3 or #pmarks:gsub('[^beh]',"") =  3 or #pmarks:gsub('[^cfi]',"") = 3 or #pmarks:gsub('[^aei]',"") = 3 or #pmarks:gsub('[^ceg]',"") = 3 ) then --meio pog,mas deve funciona
	   >>playerwincode<<
   else
	   >>npcturncode<<
	   turn = 0 --voltar ser vez do jogador
   end
   else
   >>mensagen de tentativa de trapaça que o espaço ja foi marcado<<
   end
 else
  >> mesangem que o local n faz parte do campo<<
 end
end

isso é so um esbolço mal feito,que fiz rapidão aki, do que to falando

 

 

 

mas deve ter sido foda faze a Ai por npc joga bem

Link para o comentário
Compartilhar em outros sites

YUPY meu 1 Ponto de reputacao ;]

just fell in love !

@ lordbug99

eu estou trabalhando nisso ... -- Ja terminei essa parte de jogar com uma Wand ou rod fish rod XD

so que ta um pouco foda usar variaveis locais na fuction on use o npc nao tem acesso. -- resolvido com uma " global storage value "

e mesmo declarando global quando eu mudo sua valor continua a valor antiga ( como se dentro da function on use elas fossem somente fixa, a mesma de quando o serve abre )

 

e eu quero fazer tipo uma LIB ( para ser reusada em outros jogos )

 

 

 

 


function onUse(cid, item, fromPosition, itemEx, toPosition)
tpos = {}
tpos.position = toPosition
miniGamePara = getArrayStorageValue( cid, nmmGameState.config.storage )
miniGameName = miniGamePara[1]

 miniGame  =  MiniGameSetting.getAll (  miniGameName  )

if  miniGame.Player  == cid then
 print ( "cid = "  ..cid)
 doSendMagicEffect(toPosition, CONST_ME_LOSEENERGY)

else
 doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)  --  Player isnt playing Any Game
 return true
end
if isMiniGameField ( miniGame.Field , tpos) then
gettoken = getThingfromPos( toPosition )

if miniGame.CanDestroyToken > 0 then
 if gettoken.itemid == miniGame.NpcTokenId then doRemoveItem(gettoken.uid, 1)
  MiniGameSetting.set (  "nmm" , "CanDestroyToken"  ,  miniGame.CanDestroyToken -1   )
 end
 return true
end

if miniGame.PlayerTurn == 2 then

 if getItemAttribute(gettoken.uid, "aid") == miniGame.Player then
  doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)  --  there, already have a token in this position
  return true
 end

--  print ( " cred = "  ..miniGame.PlayerCredit  )
 if miniGame.PlayerCredit > 0 then
  MiniGameSetting.set (  "nmm" , "PlayerCredit"  ,  miniGame.PlayerCredit -1   )
  tokenPiecePlayer = doCreateItemEx( miniGame.PlayerTokenId, 1 )
  doItemSetAttribute(tokenPiecePlayer , "aid", miniGame.Player)
  doTileAddItemEx( toPosition, tokenPiecePlayer)
  MiniGameSetting.set (  "nmm" , "PlayerTurn"  ,  1   )
 end
end
else
doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)   --  isnt player turn or position isnt the game field
return true
end

end

Editado por hellFriend
Link para o comentário
Compartilhar em outros sites

Bom trabalho

muito obrigado :] logo vou tentar fazer o de xadrez ( mais a dama ta foda )

 

function MiniGameStates.placedToken(  field , TokenIds ) -- update of tttPlayerMoves one scan save all the field
local placedTokens = matrix.new ( #TokenIds+1 , 0 )  -- creat a new array with nbr of line eq nbr of token +1 ( unplaced )
local indexOfTokenIds = matrix.invert(TokenIds)
for _, col in ipairs(field) do
 for _, square in ipairs(col) do
  local item = getThingfromPos(square.position)
  if isInArray( TokenIds, item.itemid )	 and   table_contains(placedTokens, square)  ~= true then
   table.insert( placedTokens [indexOfTokenIds[item.itemid]] ,square)
  else
   table.insert( placedTokens [#TokenIds+1] ,square)
  end
 end
end
return placedTokens
end

--  how to use
 local placedTokens = MiniGameStates.placedToken(  field , {nmmPlayerToken, nmmNpcToken} )

 local placedPlayerTokens = placedTokens[1]
 local placedNpcTokens = placedTokens[2]
 local unPlacedTokens = placedTokens[#placedTokens]

Link para o comentário
Compartilhar em outros sites

×
×
  • Criar Novo...