Advertisement
Guest User

Tic Tac Toe fix plz

a guest
Apr 10th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 16.30 KB | None | 0 0
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <mod name="Tic tac toc" version="1.0" author="Doggynub" contact="tarabishy_2020@hotmail.com" enabled="yes">
  3.  
  4. <config name="Tic_config"><![CDATA[
  5. --[[
  6. ##*#*#*#*#*#*#* •••• VVVVVVVVV •••• #%#%#%#%#%#%#%
  7. #%#%#%#%#%#%#%* •••• VVVVVVVVV •••• #%#%#%#%#%#%#%
  8. #$#%#%#%#%#%#%#%# << Tic-Tac-Tuc System >> #$#$#$#$#$#$#$#$#
  9. << By : Doggynub >>
  10. #%#%#%#%#%#%#% •••• ^^^^^^^^^ •••• #%#%#%#%#%#%%#
  11. #%#%#%#%#%#%##% •••• ^^^^^^^^^ •••• ##*#*#*#*#*#*#
  12.  
  13. ]]--
  14.  
  15.  
  16.  
  17.  
  18. --// Editable \\--
  19.  
  20. turn_id_tocken = 555541 -- empty storage
  21.  
  22. turn_tocken = 555542 -- empty storage
  23.  
  24. canMove_token = 555543 -- empty storage
  25.  
  26. round_token = 555544 -- empty storage
  27.  
  28. winner_token = 555545 -- empty storage
  29.  
  30. running_token = 555546 -- empty storage
  31.  
  32. won_token = 555547 -- empty storage
  33.  
  34. ITem_WinnEr = { {2160,2} , {2446,1} } -- {item,count} make sure non-stackable items would be with count 1 only
  35.  
  36. tic_pos = { -- game area, the little white area you place tokens at
  37.  
  38. frompos = { x= 370, y = 124, z = 14 }, -- start position of playing field
  39.  
  40. topos = { x= 372, y = 126, z = 14 } -- end position of playing field
  41. }
  42.  
  43. config_tic = { -- in game config
  44.  
  45. { --[[The player playing with "Cross" tokens config ]]--
  46.  
  47. pos_start = { x= 372, y = 120, z = 14 }, -- Lever place : the place he would be standing when the lever ispushed
  48.  
  49. pos_game = { x= 374, y = 125, z = 14 }, --Game place : the place where he stands in game
  50.  
  51. storage = 553466, -- Empty storage : needed for wins
  52.  
  53. token_pos = { x= 374, y = 124, z = 14 } --Token pos : the pos where the "Cross" tokens will be in
  54.  
  55. },
  56.  
  57.  
  58. { --[[The player playing with "Circle" tokens config ]]--
  59.  
  60. pos_start = { x= 370, y = 120, z = 14 }, -- Lever place : the place he would be standing when the lever ispushed
  61.  
  62. pos_game = { x= 368, y = 125, z = 14 }, --Game place : the place where he stands in game
  63.  
  64. storage = 553469, -- Empty storage : needed for wins
  65.  
  66. token_pos = { x= 368, y = 126, z = 14 } --Token pos : the pos where the circle tokens will be in
  67.  
  68. }
  69.  
  70. }
  71.  
  72. ]]></config>
  73.  
  74. <lib name="Tic_lib"><![CDATA[
  75. Phases_Tic_Tac = {
  76. -- // Horizontal raws \\--
  77. { {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 } },
  78.  
  79. { {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 } },
  80.  
  81. { {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 } },
  82.  
  83. -- // Vertical raws \\--
  84. { {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 } },
  85.  
  86. { {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 } },
  87.  
  88. { {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 } },
  89.  
  90.  
  91. --// Crosses raws \\--
  92. { {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 } },
  93.  
  94. { {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 } }
  95.  
  96.  
  97. }
  98.  
  99.  
  100. function markWinningRaw(item, pos1, pos2, pos3, timer)--By Doggynub
  101. doRemoveItem(getTileItemById(pos1,item).uid)
  102. doRemoveItem(getTileItemById(pos2,item).uid)
  103. doRemoveItem(getTileItemById(pos3,item).uid)
  104. addEvent(doCreateItem,timer,item,1,pos1)
  105. addEvent(doCreateItem,timer,item,1,pos2)
  106. addEvent(doCreateItem,timer,item,1,pos3)
  107. end
  108.  
  109. function turn()
  110. if getStorage(canMove_token) ~= 0 and getStorage(running_token) > 0 then
  111. doSendAnimatedText(config_tic[getStorage(turn_tocken)].token_pos,"Play",TEXTCOLOR_GREEN)
  112. addEvent(turn,1000)
  113. end
  114. end
  115. function checkCircle() --By Doggynub
  116. local raw = 0
  117. local check = false
  118. for i = 1,#Phases_Tic_Tac do
  119. local caller = Phases_Tic_Tac[i]
  120. local item = getTileItemById(caller[1],6557).uid
  121. local item1 = getTileItemById(caller[2],6557).uid
  122. local item2 = getTileItemById(caller[3],6557).uid
  123.  
  124. if ( item > 0 and item1 > 0 and item2 > 0 ) then
  125. check = true
  126. raw = i
  127. break
  128. end
  129. end
  130.  
  131. if check == true and raw > 0 then
  132. local call = Phases_Tic_Tac[raw]
  133. for i = 1,7 do
  134. addEvent(markWinningRaw, i *800, 6557,call[1] , call[2], call[3], 400)
  135. end
  136. end
  137.  
  138. return check
  139. end
  140.  
  141. function checkCross()--By Doggynub
  142. local raw = 0
  143. local check = false
  144. for i = 1,#Phases_Tic_Tac do
  145. local caller = Phases_Tic_Tac
  146. local item = getTileItemById(caller[1],6556).uid
  147. local item1 = getTileItemById(caller[2],6556).uid
  148. local item2 = getTileItemById(caller[3],6556).uid
  149.  
  150. if ( item > 0 and item1 > 0 and item2 > 0 ) then
  151. check = true
  152. raw = i
  153. break
  154. end
  155. end
  156.  
  157. if check == true and raw > 0 then
  158. local call = Phases_Tic_Tac[raw]
  159. for i = 1,7 do
  160. addEvent(markWinningRaw, i *800, 6556,call[1] , call[2], call[3], 400)
  161. end
  162. end
  163.  
  164. return check
  165. end
  166.  
  167.  
  168.  
  169.  
  170. function isCircle(cid)--By Doggynub
  171. return getPlayerStorageValue(cid,config_tic[2].storage) == 1 and true or false
  172. end
  173.  
  174. function isCross(cid)--By Doggynub
  175. return getPlayerStorageValue(cid,config_tic[1].storage) == 1 and true or false
  176. end
  177.  
  178. function gatherTokens(frompos,topos, crosspos , circlepos)--By Doggynub
  179. for i = frompos.x, topos.x do
  180. for j = frompos.y, topos.y do
  181. local pos = {x = i, y=j,z=frompos.z}
  182. local circle = getTileItemById(pos,6557).uid
  183. local cross = getTileItemById(pos,6556).uid
  184. if cross > 0 then
  185. doTeleportThing(cross,crosspos)
  186. elseif circle > 0 then
  187. doTeleportThing(circle,circlepos)
  188. end
  189. end
  190. end
  191. return true
  192. end
  193.  
  194. function endPoint(frompos,topos)--By Doggynub
  195. local check = true
  196. for i = frompos.x, topos.x do
  197. for j = frompos.y, topos.y do
  198. local pos = {x = i, y=j,z=frompos.z}
  199. local circle = getTileItemById(pos,6557).uid
  200. local cross = getTileItemById(pos,6556).uid
  201. if circle < 1 and cross < 1 then
  202. check = false
  203. break
  204. end
  205. end
  206. end
  207. return check
  208. end
  209.  
  210. function isWinner(cid)--By Doggynub
  211. if isCircle(cid) then
  212. if checkCircle() then
  213. return true
  214. end
  215. elseif isCross(cid) then
  216. if checkCross() then
  217. return true
  218. end
  219. end
  220. return false
  221. end
  222.  
  223.  
  224. function send(uid,cid,n,type)--By Doggynub
  225.  
  226. for i = 1, n do
  227. if type == nil then
  228. addEvent(doSendDistanceShoot,i*300,getThingPos(uid),getThingPos(cid),41)
  229. addEvent(doSendAnimatedText,i*300,getThingPos(cid),"Winner!",math.random(0,255))
  230. else
  231. addEvent(doSendDistanceShoot,i*300,getThingPos(uid),config_tic[1].pos_game,41)
  232. addEvent(doSendDistanceShoot,i*300,getThingPos(uid),config_tic[2].pos_game,41)
  233. addEvent(doSendAnimatedText,i*300,config_tic[1].pos_game,"Draw!",math.random(0,255))
  234. addEvent(doSendAnimatedText,i*300,config_tic[2].pos_game,"Draw!",math.random(0,255))
  235. end
  236. end
  237. return true
  238. end
  239. function endGame()--By Doggynub
  240. local array = {getTopCreature(config_tic[1].pos_game).uid, getTopCreature(config_tic[2].pos_game).uid}
  241.  
  242. for i = 1,2 do
  243. doTeleportThing(array[i],getTownTemplePosition(getPlayerTown(array[i])))
  244. doCreatureSetNoMove(array,0)
  245. doRemoveCondition(array,CONDITION_INFIGHT)
  246. doSendMagicEffect(getThingPos(array),10)
  247. end
  248. doSetStorage(winner_token,-1)
  249. doSetStorage(round_token,-1)
  250. doSetStorage(running_token,-1)
  251. doSetStorage(won_token,-1)
  252. return true
  253. end
  254.  
  255. function doAddCopiedContainer(it, new) --By Doggynub
  256.  
  257. local uid,its,news = it.uid, {},{}
  258. local size = getContainerSize(uid)
  259. local test = {}
  260. for i = 0, size-1 do
  261. local item = getContainerItem(uid,i)
  262. table.insert(test,{item, item.type})
  263. if isContainer(item.uid) then
  264. table.insert(its,item)
  265. end
  266. end
  267.  
  268. for i = #test,1,-1 do
  269. local call = test[i]
  270. local ufg = doAddContainerItem(new,call[1].itemid,(call[2] < 1 and 1 or call[2]) )
  271. if isContainer(ufg) then
  272. table.insert(news,ufg)
  273. end
  274. end
  275. for i = 1,#its do
  276. doAddCopiedContainer(its[i], news)
  277. end
  278. return true
  279. end
  280.  
  281. function getRefree(cid,type)--By Doggynub
  282. local str1 = ""
  283. local str2 = ""
  284. if type == nil then
  285. if getStorage(round_token) < 1 then
  286. str1 = getCreatureName(cid).." won Round <1> "
  287. str2 = "Round <2> : start"
  288. doSetStorage(round_token,2)
  289. doSetStorage(winner_token,cid)
  290. elseif getStorage(round_token) == 2 then
  291. if getStorage(winner_token) == cid then
  292. str1 = getCreatureName(cid).." won the game, and will recive his reward."
  293. doSetStorage(won_token,1)
  294. str2 = "You will be teleported out shortly."
  295. else
  296. str1 = getCreatureName(cid).." won Round <2>."
  297. str2 = "Final Round : start"
  298. doSetStorage(round_token,3)
  299. doSetStorage(winner_token,cid)
  300. end
  301. elseif getStorage(round_token) == 3 then
  302. str1 = getCreatureName(cid).." won the game, and will recive his reward."
  303.  
  304. local item = ITem_WinnEr[math.random(1,#ITem_WinnEr)]
  305. local bp = doCreateItemEx(cid, item[1],item[2] )
  306. if(doPlayerAddItemEx(cid, bp) ~= RETURNVALUE_NOERROR) then
  307. doPlayerSendTextMessage(cid,MESSAGE_EVENT_ORANGE,"You didn't recieve your reward as you don't have enough space or cap.")
  308. else
  309. doPlayerSendTextMessage(cid,MESSAGE_TYPES["blue"],"You won "..item[2] .."x ".. getItemNameById(item[1])..".")
  310. end
  311. doSetStorage(won_token,1)
  312. str2 = "You will be teleported out shortly."
  313. doSetStorage(winner_token,cid)
  314. end
  315. else
  316. str1 = "No one won. Round re-match. "
  317. str2 = "Round <".. ( getStorage(round_token) < 1 and "1" or getStorage(round_token) ) .."> : start"
  318. end
  319. local uid = doCreateMonster("chicken",{x = tic_pos.frompos.x+1, y = tic_pos.frompos.y+1, z = tic_pos.frompos.z,stackpos = 0 })
  320. doChangeSpeed(uid, - getCreatureSpeed(uid) )
  321. addEvent(doCreatureSay,100,uid,str1,19)
  322. addEvent(doCreatureSay,10*300+ 1000,uid,str2,19)
  323. addEvent(turn,10*300+ 3305)
  324. if type == nil then
  325. addEvent(doCreatureSetLookDirection,10*300+ 8,uid, 2)
  326. end
  327. addEvent(doRemoveCreature,10*300+ 3300,uid)
  328. doCreatureSetLookDirection(uid, getDirectionTo(getThingPos(uid), getThingPos(cid)))
  329. send(uid,cid,10,type)
  330. addEvent(doSetStorage,10*300+ 3300,canMove_token,1)
  331. if getStorage(won_token) > 0 then
  332. addEvent(endGame,10*300+ 3300)
  333. end
  334.  
  335. return true
  336. end
  337. function getCounOnTile(posi)
  338. local found = 0
  339. 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
  340. if f~= false then
  341. for i = 1,254 do
  342. pos = {x=posi.x , y= posi.y, z= posi.z, stackpos = i}
  343. if getThingFromPos({x=posi.x , y= posi.y, z= posi.z, stackpos = i}).uid > 0 then
  344. if getThingFromPos({x=posi.x , y= posi.y, z= posi.z, stackpos = 255}).itemid == f then
  345. found = found+1
  346. end
  347. end
  348. end
  349. end
  350. return f == false and 0 or found
  351. end
  352. ]]></lib>
  353.  
  354. <action actionid="1111" event="script"> <![CDATA[
  355. domodlib('Tic_config')
  356. domodlib('Tic_lib')
  357. local fight = createConditionObject(CONDITION_INFIGHT,-1)
  358. function onUse(cid, item, fromPosition, itemEx, toPosition)
  359. local pl1_game = getTopCreature(config_tic[1].pos_start).uid
  360. local pl2_game = getTopCreature(config_tic[2].pos_start).uid
  361. local players1_enter = getTopCreature(config_tic[1].pos_game).uid
  362. local players2_enter = getTopCreature(config_tic[2].pos_game).uid
  363. local players = {}
  364.  
  365. if players1_enter < 1 and players2_enter < 1 then
  366. if getStorage(running_token) > 0 then
  367. doSetStorage(winner_token,-1)
  368. doSetStorage(round_token,-1)
  369. doSetStorage(running_token,-1)
  370. doSetStorage(won_token,-1)
  371. end
  372. end
  373.  
  374. if getStorage(running_token) > 0 then
  375. return doPlayerSendCancel(cid,"The players inside didn't finish there game yet.")
  376. end
  377.  
  378. if pl1_game > 0 and pl2_game > 0 then
  379. table.insert(players, pl1_game)
  380. table.insert(players, pl2_game)
  381. else
  382. return doPlayerSendCancel(cid,"The game needs 2 players to start.")
  383. end
  384. gatherTokens(tic_pos.frompos,tic_pos.topos, config_tic[1].token_pos , config_tic[2].token_pos)
  385. for i = 1,#players do
  386. doTeleportThing(players[i],config_tic.pos_game,false)
  387. doSendMagicEffect(config_tic.pos_game,10)
  388. doCreatureSetNoMove(players[i],1)
  389. doAddCondition(players[i],fight)
  390. setPlayerStorageValue(players[i],config_tic.storage,1)
  391. setPlayerStorageValue(players[i],turn_id_tocken,i)
  392. end
  393. local uid = doCreateMonster("chicken",{x = tic_pos.frompos.x+1, y = tic_pos.frompos.y+1, z = tic_pos.frompos.z,stackpos = 0 })
  394.  
  395. doSetStorage(turn_tocken,math.random(1,2))
  396. doSetStorage(running_token,1)
  397. doChangeSpeed(uid, - getCreatureSpeed(uid) )
  398. doSetStorage(canMove_token,0)
  399. addEvent(doCreatureSay,100,uid,"Round <1> : start",19)
  400. addEvent(doRemoveCreature,2400,uid)
  401. addEvent(doSetStorage,2410,canMove_token,1)
  402. addEvent(turn,2411)
  403.  
  404.  
  405. return true
  406. end
  407.  
  408.  
  409. ]]></action>
  410.  
  411. <movevent type="RemoveItem" fromid="6556" toid="6557" event="script"><![CDATA[
  412. domodlib('Tic_config')
  413. domodlib('Tic_lib')
  414. function onRemoveItem(moveItem, tileItem, position, cid)
  415. local returnplace = ( moveItem.itemid == 6556 and config_tic[1].token_pos or config_tic[2].token_pos )
  416. if cid > 0 then
  417.  
  418. if getStorage(running_token) > 0 then
  419.  
  420.  
  421. if doComparePositions(position,config_tic[1].token_pos) or doComparePositions(position,config_tic[2].token_pos) then
  422.  
  423. if getStorage(canMove_token) == 0 then
  424. return doPlayerSendCancel(cid,"Sorry, you can't move your token now.") and doSendMagicEffect(returnplace,2) and doTeleportThing(moveItem.uid,returnplace)
  425. end
  426.  
  427. if getStorage(turn_tocken) ~= getPlayerStorageValue(cid,turn_id_tocken) then
  428. return doSendMagicEffect(returnplace,2) and doPlayerSendCancel(cid,"Sorry, this isn't your turn.") and doTeleportThing(moveItem.uid,returnplace)
  429. end
  430.  
  431. local p = getThingPosition(moveItem.uid)
  432. local f = moveItem.itemid
  433.  
  434. if not isInRange(p,tic_pos.frompos,tic_pos.topos) then
  435. return doSendMagicEffect(returnplace,2) and doTeleportThing(moveItem.uid,returnplace) and doPlayerSendCancel(cid,"You can't move the token outside play zone.")
  436. else
  437. if getCounOnTile(p) > 1 then
  438. return doSendMagicEffect(returnplace,2) and doTeleportThing(moveItem.uid,returnplace) and doPlayerSendCancel(cid,"You can't place another token here.")
  439. end
  440. end
  441.  
  442.  
  443.  
  444. if isWinner(cid) then
  445. doSetStorage(canMove_token,0)
  446. addEvent(gatherTokens,6700,tic_pos.frompos,tic_pos.topos, config_tic[1].token_pos , config_tic[2].token_pos)
  447. addEvent(getRefree,7000,cid)
  448. else
  449. if endPoint(tic_pos.frompos,tic_pos.topos) then
  450. doSetStorage(canMove_token,0)
  451. gatherTokens(tic_pos.frompos,tic_pos.topos, config_tic[1].token_pos , config_tic[2].token_pos)
  452. addEvent(getRefree,200,cid,1)
  453. doSetStorage(turn_tocken, math.random(1,2) )
  454. else
  455. doSetStorage(turn_tocken, ( getStorage(turn_tocken) == 1 and 2 or 1 ) )
  456. end
  457. end
  458. end
  459.  
  460. else
  461. return doSendMagicEffect(returnplace,2) and doTeleportThing(moveItem.uid,returnplace) and doPlayerSendCancel(cid,"Game not started.")
  462. end
  463.  
  464. end
  465.  
  466. return true
  467. end
  468.  
  469.  
  470. ]]></movevent>
  471.  
  472. <movevent type="AddItem" tileitem="1" uniqueid="6666" event="script"><![CDATA[
  473. domodlib('Tic_config')
  474. domodlib('Tic_lib')
  475. function onAddItem(moveItem, tileItem, position, cid)
  476.  
  477. if cid > 0 then
  478. local returnplace = ( moveItem.itemid == 6556 and config_tic[1].token_pos or config_tic[2].token_pos )
  479. local check = false
  480. for i = tic_pos.frompos.x, tic_pos.topos.x do
  481. for j = tic_pos.frompos.y, tic_pos.topos.y do
  482. local pos = {x = i, y=j,z=tic_pos.frompos.z}
  483. if doComparePositions(position,pos) then
  484. check = true
  485. break
  486. end
  487. end
  488. end
  489. if not isInArray({6556,6557},moveItem.itemid) then
  490. local count = moveItem.type
  491. if not isContainer(moveItem.uid) then
  492. doRemoveItem(moveItem.uid)
  493. doPlayerAddItem(cid,moveItem.itemid,count)
  494. doPlayerSendCancel(cid,"You can't drop your item here.")
  495. doSendMagicEffect(getThingPos(cid),2)
  496. else
  497. local uids = moveItem
  498. local bp = doPlayerAddItem(cid,uids.itemid,1)
  499. doAddCopiedContainer(uids, bp)
  500. return doRemoveItem(moveItem.uid) and doPlayerSendCancel(cid,"You can't drop your item here.") and doSendMagicEffect(getThingPos(cid),2)
  501. end
  502. else
  503. if check == false then
  504. doRemoveItem(moveItem.uid)
  505. end
  506. end
  507. end
  508. return true
  509. end
  510.  
  511.  
  512. ]]></movevent>
  513.  
  514. </mod>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement