Tonks
Banned User
Hello folks,
I decided to release a nice game and a funny game..!
Enjoy the game & Comment.
Please if you liked tic-tac-toe game,
[REP Tonks]
I decided to release a nice game and a funny game..!
Tic-Tac-Toe
Create a new mod file, call it TTT.xml and paste this into it:
XML:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Tic tac toc" version="1.0" author="Doggynub&Tonks"
contact="~~~~~~~~~~" enabled="yes">
<config name="Tic_config"><![CDATA[
--// 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= 849, y =
1072, z = 7 }, -- start position of playing field
topos = { x= 851, y = 1074,
z = 7 } -- end position of playing field
}
config_tic = { -- in game config
{ --[[The player
playing with "Cross" tokens config ]]--
pos_start
= { x= 851, y = 1068, z = 7 }, -- Lever place :
the place he would be standing when the lever ispushed
pos_game
= { x= 853, y = 1073, z = 7 }, --Game place : the
place where he stands in game
storage =
553466,
-- Empty storage : needed for wins
token_pos
= { x= 853, y = 1072, z = 7 } --Token pos : the
pos where the "Cross" tokens will be in
},
{ --[[The player
playing with "Circle" tokens config ]]--
pos_start
= { x= 849, y = 1068, z = 7 }, -- Lever place :
the place he would be standing when the lever ispushed
pos_game
= { x= 847, y = 1073, z = 7 }, --Game place : the
place where he stands in game
storage =
553469,
-- Empty storage : needed for wins
token_pos
= { x= 847, y = 1074, 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
Tonks
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 TtTtTtonks!
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 tONKS
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 tONKS
return getPlayerStorageValue(cid,config_tic[2].storage)
== 1 and true or false
end
function isCross(cid)--By
return getPlayerStorageValue(cid,config_tic[1].storage)
== 1 and true or false
end
function gatherTokens(frompos,topos, crosspos , circlepos)--By
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
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
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
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
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>
Please if you liked tic-tac-toe game,
[REP Tonks]