Guest User

Untitled

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