• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

MoveEvent Three Rounds Tic-Tac-Toc System(Fixed Version + more features)

Doggynub

LUA / C++
Joined
Sep 28, 2008
Messages
2,541
Reaction score
186
* System info :
NOTE : Fixed Version (updated in 21/4/2011)

Mod file , easy install.It is the famous "X" & "O" system containing 3 rounds , the third round is the final one if both scored 1 round , other than that the one who win 2 rounds wins the game and recive his reward.



Features :
1- Talking refree
2- Dead end = rematch round
3- Items is returned to play if it is dropped on play zone including container items
4- Now you can't drop two tokens on each other
5- Winner gets a reward on teleport out game zone , unless he dont have cap or space for it.



* Instruction Photo:



Uploaded with ImageShack.us









* Installing :

Go to your mod file paste this, and check config in it,please install the new map too.
XML:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Tic tac toc" version="1.0" author="Doggynub" contact="[email protected]" enabled="yes">

<config name="Tic_config"><![CDATA[	
--[[
    ##*#*#*#*#*#*#*	••••	VVVVVVVVV	••••  #%#%#%#%#%#%#%
	#%#%#%#%#%#%#%* ••••	VVVVVVVVV	••••  #%#%#%#%#%#%#%	
  #$#%#%#%#%#%#%#%#	 <<		Tic-Tac-Tuc System 	>>  #$#$#$#$#$#$#$#$#
					 <<		By : Doggynub		>>
	#%#%#%#%#%#%#%	••••	^^^^^^^^^	••••  #%#%#%#%#%#%%#
	#%#%#%#%#%#%##% ••••	^^^^^^^^^   ••••  ##*#*#*#*#*#*#
 
	]]--
 
 
 
 
--// Editable \\--  
 
turn_id_tocken = 555541 -- empty storage
 
turn_tocken = 555542 -- empty storage
 
canMove_token = 555543 -- empty storage
 
round_token = 555544 -- empty storage
 
winner_token = 555545 -- empty storage
 
running_token = 555546 -- empty storage
 
won_token = 555547 -- empty storage
 
ITem_WinnEr  = { {2160,2} , {2446,1} } -- {item,count} make sure non-stackable items would be with count 1 only
 
tic_pos = { -- game area, the little white area you place tokens at
				
				frompos = { x= 976, y = 1016, z = 7 }, 	-- start position of playing field
				
				topos = { x= 978, y = 1018, z = 7 } -- end position of playing field
			}
 
config_tic = {  -- in game config 
     
					{ --[[The player playing with "Cross" tokens config ]]--
					
						pos_start = { x= 978, y = 1012, z = 7 }, 		-- Lever place : the place he would be standing when the lever ispushed 
						
						pos_game = { x= 980, y = 1017, z = 7 },   		--Game place : the place where he stands in game
						
						storage = 553466, 				 				-- Empty storage : needed for wins
						
						token_pos = { x= 980, y = 1016, z = 7 }		--Token pos : the pos where the "Cross" tokens will be in
						
					},
 
					 	
					{ --[[The player playing with "Circle" tokens config ]]--
						
						pos_start = { x= 976, y = 1012, z = 7 }, 		-- Lever place : the place he would be standing when the lever ispushed 
						
						pos_game = { x= 974, y = 1017, z = 7 },  		--Game place : the place where he stands in game
						
						storage = 553469, 								-- Empty storage : needed for wins
						
						token_pos = { x= 974, y = 1018, z = 7 } 		--Token pos : the pos where the circle tokens will be in
					
					}
 
				}

]]></config>

<lib name="Tic_lib"><![CDATA[
Phases_Tic_Tac = { 
					-- // Horizontal raws \\--
					{ {x = tic_pos.frompos.x, y = tic_pos.frompos.y, z = tic_pos.frompos.z } , {x = tic_pos.frompos.x+1, y = tic_pos.frompos.y, z = tic_pos.frompos.z } , {x = tic_pos.frompos.x+2, y = tic_pos.frompos.y, z = tic_pos.frompos.z } }, 
 
					{ {x = tic_pos.frompos.x, y = tic_pos.frompos.y+1, z = tic_pos.frompos.z } , {x = tic_pos.frompos.x+1, y = tic_pos.frompos.y+1, z = tic_pos.frompos.z } , {x = tic_pos.frompos.x+2, y = tic_pos.frompos.y+1, z = tic_pos.frompos.z } },
 
					{ {x = tic_pos.frompos.x, y = tic_pos.frompos.y+2, z = tic_pos.frompos.z } , {x = tic_pos.frompos.x+1, y = tic_pos.frompos.y+2, z = tic_pos.frompos.z } , {x = tic_pos.frompos.x+2, y = tic_pos.frompos.y+2, z = tic_pos.frompos.z } },
 
					-- // Vertical raws \\--
					{ {x = tic_pos.frompos.x, y = tic_pos.frompos.y, z = tic_pos.frompos.z } , {x = tic_pos.frompos.x, y = tic_pos.frompos.y+1, z = tic_pos.frompos.z } , {x = tic_pos.frompos.x, y = tic_pos.frompos.y+2, z = tic_pos.frompos.z } },
 
					{ {x = tic_pos.frompos.x+1, y = tic_pos.frompos.y, z = tic_pos.frompos.z } , {x = tic_pos.frompos.x+1, y = tic_pos.frompos.y+1, z = tic_pos.frompos.z } , {x = tic_pos.frompos.x+1, y = tic_pos.frompos.y+2, z = tic_pos.frompos.z } },
 
					{ {x = tic_pos.frompos.x+2, y = tic_pos.frompos.y, z = tic_pos.frompos.z } , {x = tic_pos.frompos.x+2, y = tic_pos.frompos.y+1, z = tic_pos.frompos.z } , {x = tic_pos.frompos.x+2, y = tic_pos.frompos.y+2, z = tic_pos.frompos.z } },
 
 
					--// Crosses raws \\--
					{ {x = tic_pos.frompos.x, y = tic_pos.frompos.y, z = tic_pos.frompos.z } , {x = tic_pos.frompos.x+1, y = tic_pos.frompos.y+1, z = tic_pos.frompos.z } , {x = tic_pos.frompos.x+2, y = tic_pos.frompos.y+2, z = tic_pos.frompos.z } },
 
					{ {x = tic_pos.frompos.x, y = tic_pos.frompos.y+2, z = tic_pos.frompos.z } , {x = tic_pos.frompos.x+1, y = tic_pos.frompos.y+1, z = tic_pos.frompos.z } , {x = tic_pos.frompos.x+2, y = tic_pos.frompos.y, z = tic_pos.frompos.z } }
 
 
				}
 
 
function markWinningRaw(item, pos1, pos2, pos3, timer)--By Doggynub
	doRemoveItem(getTileItemById(pos1,item).uid)
	doRemoveItem(getTileItemById(pos2,item).uid)
	doRemoveItem(getTileItemById(pos3,item).uid)
	addEvent(doCreateItem,timer,item,1,pos1)
	addEvent(doCreateItem,timer,item,1,pos2)
	addEvent(doCreateItem,timer,item,1,pos3)
end
 
function turn()
	if getStorage(canMove_token) ~= 0 and getStorage(running_token) > 0 then
		doSendAnimatedText(config_tic[getStorage(turn_tocken)].token_pos,"Play",TEXTCOLOR_GREEN)
		addEvent(turn,1000)
	end
end
function checkCircle() --By Doggynub
	local raw = 0
	local check = false
	for i = 1,#Phases_Tic_Tac do 
		local caller = Phases_Tic_Tac[i]
		local item = getTileItemById(caller[1],6557).uid
		local item1 = getTileItemById(caller[2],6557).uid
		local item2 = getTileItemById(caller[3],6557).uid
 
		if ( item > 0 and item1 > 0 and item2 > 0 ) then
			check = true
			raw = i
			break
		end
	end
 
	if check == true and raw > 0 then
		local call = Phases_Tic_Tac[raw]
		for i = 1,7 do 
			addEvent(markWinningRaw, i *800, 6557,call[1] , call[2], call[3], 400)
		end
	end
 
	return check
end
 
function checkCross()--By Doggynub
	local raw = 0
	local check = false
	for i = 1,#Phases_Tic_Tac do 
		local caller = Phases_Tic_Tac[i]
		local item = getTileItemById(caller[1],6556).uid
		local item1 = getTileItemById(caller[2],6556).uid
		local item2 = getTileItemById(caller[3],6556).uid
 
		if ( item > 0 and item1 > 0 and item2 > 0 ) then
			check = true
			raw = i
			break
		end
	end
 
	if check == true and raw > 0 then
		local call = Phases_Tic_Tac[raw]
		for i = 1,7 do 
			addEvent(markWinningRaw, i *800, 6556,call[1] , call[2], call[3], 400)
		end
	end
 
	return check
end	
 
 
 
 
function isCircle(cid)--By Doggynub
	return getPlayerStorageValue(cid,config_tic[2].storage) == 1 and true or false
end
 
function isCross(cid)--By Doggynub
	return getPlayerStorageValue(cid,config_tic[1].storage) == 1 and true or false
end
 
function gatherTokens(frompos,topos, crosspos , circlepos)--By Doggynub
		for i = frompos.x, topos.x do 
			for j = frompos.y, topos.y do 
				local pos = {x = i, y=j,z=frompos.z}
				local circle = getTileItemById(pos,6557).uid
				local cross = getTileItemById(pos,6556).uid
				if cross > 0 then
					doTeleportThing(cross,crosspos)
				elseif circle > 0 then
					doTeleportThing(circle,circlepos)
				end
			end
		end
	return true
end
 
function endPoint(frompos,topos)--By Doggynub
		local check = true
		for i = frompos.x, topos.x do 
			for j = frompos.y, topos.y do 
				local pos = {x = i, y=j,z=frompos.z}
				local circle = getTileItemById(pos,6557).uid
				local cross = getTileItemById(pos,6556).uid
				if circle < 1 and cross < 1 then
					check = false
					break
				end
			end
		end
	return check
end
 
function isWinner(cid)--By Doggynub
	if isCircle(cid) then
		if checkCircle() then
			return true
		end
	elseif isCross(cid) then
		if checkCross() then
			return true
		end
	end
	return false
end
 
 
function send(uid,cid,n,type)--By Doggynub
 
		for i = 1, n do 
			if type == nil then
				addEvent(doSendDistanceShoot,i*300,getThingPos(uid),getThingPos(cid),41)
				addEvent(doSendAnimatedText,i*300,getThingPos(cid),"Winner!",math.random(0,255))
			else
				addEvent(doSendDistanceShoot,i*300,getThingPos(uid),config_tic[1].pos_game,41)
				addEvent(doSendDistanceShoot,i*300,getThingPos(uid),config_tic[2].pos_game,41)
				addEvent(doSendAnimatedText,i*300,config_tic[1].pos_game,"Draw!",math.random(0,255))
				addEvent(doSendAnimatedText,i*300,config_tic[2].pos_game,"Draw!",math.random(0,255))
			end
		end
	return true
end
function endGame()--By Doggynub
	local array = {getTopCreature(config_tic[1].pos_game).uid, getTopCreature(config_tic[2].pos_game).uid}

	for i = 1,2 do 
		doTeleportThing(array[i],getTownTemplePosition(getPlayerTown(array[i])))
		doCreatureSetNoMove(array[i],0)
		doRemoveCondition(array[i],CONDITION_INFIGHT)
		doSendMagicEffect(getThingPos(array[i]),10)
	end
	doSetStorage(winner_token,-1)
	doSetStorage(round_token,-1)
	doSetStorage(running_token,-1)
	doSetStorage(won_token,-1)
	return true
end
 
function doAddCopiedContainer(it, new) --By Doggynub
 
	local uid,its,news = it.uid, {},{}
	local size = getContainerSize(uid)
	local test = {}
	for i = 0, size-1 do 
		local item = getContainerItem(uid,i)
		table.insert(test,{item, item.type})
		if isContainer(item.uid) then
			table.insert(its,item)
		end
	end
 
	for i = #test,1,-1 do
		local call = test[i]
		local ufg = doAddContainerItem(new,call[1].itemid,(call[2] < 1 and 1 or call[2]) )
		if isContainer(ufg) then
			table.insert(news,ufg)
		end
	end
	for i = 1,#its do
		doAddCopiedContainer(its[i], news[i])
	end
	return true
end	
 
function getRefree(cid,type)--By Doggynub
	local str1 = ""
	local str2 = ""
	if type == nil then
		if getStorage(round_token) < 1 then
			str1 = getCreatureName(cid).." won Round <1> "
			str2 = "Round <2> : start"
			doSetStorage(round_token,2)
			doSetStorage(winner_token,cid)
		elseif getStorage(round_token) == 2 then
			if getStorage(winner_token) == cid then
				str1 = getCreatureName(cid).." won the game, and will recive his reward."
				doSetStorage(won_token,1)
				str2 = "You will be teleported out shortly."
			else
				str1 = getCreatureName(cid).." won Round <2>."
				str2 = "Final Round : start"
				doSetStorage(round_token,3)
				doSetStorage(winner_token,cid)
			end
		elseif getStorage(round_token) == 3 then
			str1 = getCreatureName(cid).." won the game, and will recive his reward."
			
			local item = ITem_WinnEr[math.random(1,#ITem_WinnEr)]
			local bp = doCreateItemEx(cid, item[1],item[2] )
			if(doPlayerAddItemEx(cid, bp) ~= RETURNVALUE_NOERROR) then
				doPlayerSendTextMessage(cid,MESSAGE_EVENT_ORANGE,"You didn't recieve your reward as you don't have enough space or cap.")
			else
				doPlayerSendTextMessage(cid,MESSAGE_TYPES["blue"],"You won "..item[2] .."x ".. getItemNameById(item[1])..".")
			end
			doSetStorage(won_token,1)
			str2 = "You will be teleported out shortly."
			doSetStorage(winner_token,cid)
		end
	else
		str1 = "No one won. Round re-match. "
		str2 = "Round <".. ( getStorage(round_token) < 1 and "1" or getStorage(round_token) ) .."> : start"
	end
	local uid = doCreateMonster("chicken",{x = tic_pos.frompos.x+1, y = tic_pos.frompos.y+1, z = tic_pos.frompos.z,stackpos = 0 })
	doChangeSpeed(uid, - getCreatureSpeed(uid) )
	addEvent(doCreatureSay,100,uid,str1,19)
	addEvent(doCreatureSay,10*300+ 1000,uid,str2,19)
	addEvent(turn,10*300+ 3305)
	if type == nil then
		addEvent(doCreatureSetLookDirection,10*300+ 8,uid, 2)
	end
	addEvent(doRemoveCreature,10*300+ 3300,uid)
	doCreatureSetLookDirection(uid, getDirectionTo(getThingPos(uid), getThingPos(cid)))
	send(uid,cid,10,type)
	addEvent(doSetStorage,10*300+ 3300,canMove_token,1)
		if getStorage(won_token) > 0 then
			addEvent(endGame,10*300+ 3300)
		end
 
	return true
end
function getCounOnTile(posi)
		local found = 0
			local f = getThingFromPos({x=posi.x , y= posi.y, z= posi.z, stackpos = 255}).uid > 0 and getThingFromPos({x=posi.x , y= posi.y, z= posi.z, stackpos = 255}).itemid or false
			if f~= false then
				for i = 1,254 do 	
					pos = {x=posi.x , y= posi.y, z= posi.z, stackpos = i}
					if getThingFromPos({x=posi.x , y= posi.y, z= posi.z, stackpos = i}).uid > 0 then
						if getThingFromPos({x=posi.x , y= posi.y, z= posi.z, stackpos = 255}).itemid == f then
							found = found+1
						end
					end
				end
			end
			return f == false and 0 or found
end
]]></lib>

<action actionid="1111" event="script"> <![CDATA[
domodlib('Tic_config')
domodlib('Tic_lib')
local fight = createConditionObject(CONDITION_INFIGHT,-1)
function onUse(cid, item, fromPosition, itemEx, toPosition)
	local pl1_game = getTopCreature(config_tic[1].pos_start).uid
	local pl2_game = getTopCreature(config_tic[2].pos_start).uid
	local players1_enter = getTopCreature(config_tic[1].pos_game).uid
	local players2_enter = getTopCreature(config_tic[2].pos_game).uid
	local players = {}
 
	if  players1_enter < 1 and players2_enter < 1 then
		if getStorage(running_token) > 0 then
			doSetStorage(winner_token,-1)
			doSetStorage(round_token,-1)
			doSetStorage(running_token,-1)
			doSetStorage(won_token,-1)
		end
	end
 
	if getStorage(running_token) > 0 then
		return  doPlayerSendCancel(cid,"The players inside didn't finish there game yet.")
	end
 
	if pl1_game > 0 and pl2_game > 0 then
		table.insert(players, pl1_game)
		table.insert(players, pl2_game)
	else
		return doPlayerSendCancel(cid,"The game needs 2 players to start.")
	end
	gatherTokens(tic_pos.frompos,tic_pos.topos, config_tic[1].token_pos , config_tic[2].token_pos)
	for i = 1,#players do 
		doTeleportThing(players[i],config_tic[i].pos_game,false)
		doSendMagicEffect(config_tic[i].pos_game,10)
		doCreatureSetNoMove(players[i],1)
		doAddCondition(players[i],fight)
		setPlayerStorageValue(players[i],config_tic[i].storage,1)
		setPlayerStorageValue(players[i],turn_id_tocken,i)
	end
	local uid = doCreateMonster("chicken",{x = tic_pos.frompos.x+1, y = tic_pos.frompos.y+1, z = tic_pos.frompos.z,stackpos = 0 })
 
	doSetStorage(turn_tocken,math.random(1,2))
	doSetStorage(running_token,1)
	doChangeSpeed(uid, - getCreatureSpeed(uid) )
	doSetStorage(canMove_token,0)
	addEvent(doCreatureSay,100,uid,"Round <1> : start",19)
	addEvent(doRemoveCreature,2400,uid)
	addEvent(doSetStorage,2410,canMove_token,1)
	addEvent(turn,2411)
 
 
	return true
end


]]></action>

<movevent type="RemoveItem"  fromid="6556" toid="6557" event="script"><![CDATA[
domodlib('Tic_config')
domodlib('Tic_lib')
function onRemoveItem(moveItem, tileItem, position, cid)
	local returnplace = ( moveItem.itemid == 6556 and config_tic[1].token_pos or config_tic[2].token_pos ) 
	if cid > 0 then
 
		if getStorage(running_token) > 0 then
 
 
			if doComparePositions(position,config_tic[1].token_pos) or doComparePositions(position,config_tic[2].token_pos) then
 
				if getStorage(canMove_token) == 0 then
					return doPlayerSendCancel(cid,"Sorry, you can't move your token now.") and doSendMagicEffect(returnplace,2) and doTeleportThing(moveItem.uid,returnplace)
				end
 
				if getStorage(turn_tocken) ~=  getPlayerStorageValue(cid,turn_id_tocken) then
					return doSendMagicEffect(returnplace,2) and doPlayerSendCancel(cid,"Sorry, this isn't your turn.") and doTeleportThing(moveItem.uid,returnplace)
				end
 
				local p = getThingPosition(moveItem.uid)
				local f = moveItem.itemid
 
				if not isInRange(p,tic_pos.frompos,tic_pos.topos) then 
					return doSendMagicEffect(returnplace,2) and doTeleportThing(moveItem.uid,returnplace) and doPlayerSendCancel(cid,"You can't move the token outside play zone.")
				else
					if getCounOnTile(p) > 1 then 
						return doSendMagicEffect(returnplace,2) and doTeleportThing(moveItem.uid,returnplace) and doPlayerSendCancel(cid,"You can't place another token here.")
					end
				end
 
 
 
				if isWinner(cid) then
					doSetStorage(canMove_token,0)
					addEvent(gatherTokens,6700,tic_pos.frompos,tic_pos.topos, config_tic[1].token_pos , config_tic[2].token_pos)
					addEvent(getRefree,7000,cid)
				else
					if endPoint(tic_pos.frompos,tic_pos.topos) then
						doSetStorage(canMove_token,0)
						gatherTokens(tic_pos.frompos,tic_pos.topos, config_tic[1].token_pos , config_tic[2].token_pos)
						addEvent(getRefree,200,cid,1)
						doSetStorage(turn_tocken, math.random(1,2) )
					else
						doSetStorage(turn_tocken, ( getStorage(turn_tocken) == 1 and 2 or 1 ) )
					end
				end
			end
 
		else
			return doSendMagicEffect(returnplace,2) and doTeleportThing(moveItem.uid,returnplace) and doPlayerSendCancel(cid,"Game not started.")
		end
 
	end
 
	return true
end


]]></movevent>

<movevent type="AddItem" tileitem="1" uniqueid="6666" event="script"><![CDATA[
domodlib('Tic_config')
domodlib('Tic_lib')
function onAddItem(moveItem, tileItem, position, cid)
 
	if cid > 0 then
	 local returnplace = ( moveItem.itemid == 6556 and config_tic[1].token_pos or config_tic[2].token_pos ) 
		local check = false
		for i = tic_pos.frompos.x, tic_pos.topos.x do 
			for j = tic_pos.frompos.y, tic_pos.topos.y do 
				local pos = {x = i, y=j,z=tic_pos.frompos.z}
				if doComparePositions(position,pos) then
					check = true
					break
				end
			end
		end
		if not isInArray({6556,6557},moveItem.itemid) then
			local count = moveItem.type
			if not isContainer(moveItem.uid) then
				doRemoveItem(moveItem.uid)
				doPlayerAddItem(cid,moveItem.itemid,count)
				doPlayerSendCancel(cid,"You can't drop your item here.")
				doSendMagicEffect(getThingPos(cid),2)
			else
				local uids = moveItem
				local bp = doPlayerAddItem(cid,uids.itemid,1)
				doAddCopiedContainer(uids, bp)
				return doRemoveItem(moveItem.uid) and doPlayerSendCancel(cid,"You can't drop your item here.") and doSendMagicEffect(getThingPos(cid),2)
			end
		else
			if check == false then
				doRemoveItem(moveItem.uid)
			end
		end
	end
	return true
end


]]></movevent>

</mod>







* Map (updated,more protection ):
MAp








Regards,
Doggynub
 
Last edited:
I am making more fixes , to make it better and when somone through somthing a bp or items it come to him again, so this will be done in 5 hours from now when i come back.
 
Last edited:
Ye i am , but i am suffering from loss of time , so as soon as i am free i will update. It is working well actually , but need little fix to perfect it. :p
 
Nice, I was doing this but with creaturescript, yours is much better of course.
Good job
 
i got this :/

Code:
[20/03/2011 20:06:33] [Error - Action Interface] 
[20/03/2011 20:06:33] data/actions/scripts/tic.lua:onUse
[20/03/2011 20:06:33] Description: 
[20/03/2011 20:06:33] data/actions/scripts/tic.lua:43: attempt to perform arithmetic on a boolean value
[20/03/2011 20:06:33] stack traceback:
[20/03/2011 20:06:33] 	data/actions/scripts/tic.lua:43: in function <data/actions/scripts/tic.lua:4>
 
i got this :/

Code:
[20/03/2011 20:06:33] [Error - Action Interface] 
[20/03/2011 20:06:33] data/actions/scripts/tic.lua:onUse
[20/03/2011 20:06:33] Description: 
[20/03/2011 20:06:33] data/actions/scripts/tic.lua:43: attempt to perform arithmetic on a boolean value
[20/03/2011 20:06:33] stack traceback:
[20/03/2011 20:06:33] 	data/actions/scripts/tic.lua:43: in function <data/actions/scripts/tic.lua:4>

you failed at pasting?
it works fine.
@ONTOPIC
OMG a talking chicken!!, I'll make it a panda :3
 
Problem. Anyone can move the tokens but both get deleted when touching the play field :s
 
I tried on TFS 0.3.6, Everything working but it never ends, they dont get tped out :S

Code:
[Error - Action Interface]
In a timer event called from:
data/actions/scripts/tic.lua:onUse
Description:
(luaDoRemoveCreature) Creature not found
 
Last edited:
Back
Top