Advertisement
Guest User

Untitled

a guest
Feb 24th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.75 KB | None | 0 0
  1. function onTime()              
  2. function isInWallArray(pos)
  3.     for k = 0, table.getn(SBW_WALLSID) do
  4.         if (getTileItemById(pos, SBW_WALLSID[k]).itemid == SBW_WALLSID[k]) then
  5.             return true    
  6.         end
  7.     end
  8.  return false
  9. end
  10. function isWalkable(pos, creature, proj, pz)-- by Nord
  11.     if getTileThingByPos({x = pos.x, y = pos.y, z = pos.z, stackpos = 0}).itemid == 0 then return false end
  12.     if getTopCreature(pos).uid > 0 and creature then return false end
  13.     if getTileInfo(pos).protection and pz then return false, true end
  14.     local n = not proj and 3 or 2
  15.     for i = 0, 255 do
  16.         pos.stackpos = i
  17.         local tile = getTileThingByPos(pos)
  18.         if tile.itemid ~= 0 and not isCreature(tile.uid) then
  19.             if hasProperty(tile.uid, n) or hasProperty(tile.uid, 7) then
  20.                 return false
  21.             end
  22.         end
  23.     end
  24.     return true
  25. end            
  26. function endsnowball()
  27.     local score = {}
  28.     if not SBW_USEWAIT then
  29.         doRemoveItem(getTileItemById(SBW_TP, 1387).uid)
  30.     end
  31.     for _, pid in ipairs(getPlayersOnline()) do
  32.         if getPlayerStorageValue(pid, SBW_INEVENT) > 0 then
  33.             table.insert(score, {getCreatureName(pid), getPlayerStorageValue(pid, SBW_SCORE)})
  34.             doPlayerSetStorageValue(pid, SBW_INEVENT, 0)
  35.             doPlayerSetStorageValue(pid, SBW_SCORE, 0)
  36.             doPlayerSetStorageValue(pid, SBW_AMMO, 0)
  37.             doTeleportThing(pid, SBW_TPEND)
  38.         end
  39.     end
  40.     table.sort(score, function(a, b) return a[2] > b[2] end)
  41.     local random_item = SBW_REWARDS[math.random(1, #SBW_REWARDS)]
  42.     local hora = os.date("%X")
  43.     local data = os.date("%x") 
  44.     if table.getn(score) > 0 then
  45.         if SBW_ADDREWARD then
  46.             for _, pid in ipairs(getPlayersOnline()) do
  47.                 if getCreatureName(pid) == score[1][1] then
  48.                     doPlayerAddItem(pid, random_item, 1)
  49.                     break
  50.                 end
  51.             end
  52.         end
  53.         db.query("INSERT INTO `snowballwar`  VALUES ('', ".. db.escapeString(score[1][1]) ..  ",".. score[1][2] ..", ".. db.escapeString(data) ..", ".. db.escapeString(hora) ..");")  
  54.         db.query("UPDATE `players` SET `sbw_points`=`sbw_points`+".. score[1][2] .." WHERE `name` = " .. db.escapeString(score[1][1]) .. ";")
  55.         doBroadcastMessage("[SNOWBALL WAR] Foi encerrado, parabens ao jogador "..score[1][1].." que venceu o SnowBall com "..score[1][2].." pontos.")
  56.     end
  57.     return true
  58. end
  59.  
  60. local t_l = SBW_AREA[1]
  61. local b_r = SBW_AREA[2]
  62. function randearMap(cid)
  63.     local pos = {x=math.random(SBW_WAITROOM[1].x, SBW_WAITROOM[2].x), y=math.random(SBW_WAITROOM[1].y,SBW_WAITROOM[2].y), z=SBW_WAITROOM[1].z}
  64.     if not isWalkable(pos, false, false, false) then
  65.         randearMap(cid)
  66.     else
  67.         doTeleportThing(cid, pos)
  68.         doPlayerSetStorageValue(cid, SBW_INEVENT, 1)
  69.         doPlayerSetStorageValue(cid, SBW_AMMO, SBW_MINAMMO)
  70.         doPlayerSetStorageValue(cid, SBW_SCORE, 0)
  71.         doPlayerSendTextMessage(cid, 27, "[SNOWBALL WAR] Seja bem vindo, aqui estao os comandos que voce vai usar durante o evento\n!snowball atirar --Atirar uma bola de neve.\n!snowball info --Isso mostra seus pontos de jogos e a quantia de bolas de neve que voce tem. Tambem mostra o ranking de pontos do evento.\n Recarregue suas bolas de neve clicando em frente ao gerador no centro do campo.\nAltamente recomendado adicionar estes comandos a sua hotkeys.")
  72.     end
  73. end
  74. function moveToEvent()
  75.     for _, pid in ipairs(getPlayersOnline()) do
  76.         if isInRange(getCreaturePosition(pid), SBW_WAITROOM[1], SBW_WAITROOM[2]) then
  77.             randearMap(pid)
  78.         end
  79.     end
  80.     doRemoveItem(getTileItemById(SBW_TP, 1387).uid)
  81.     addEvent(endsnowball, SBW_DURATION*1000*60)
  82.     doBroadcastMessage(SBW_MSGSTART)
  83. end
  84. local time = os.date("*t")
  85. local timeopen1 = math.ceil(SBW_TIMEWAIT / 4)
  86. local timeopen2 = math.ceil(SBW_TIMEWAIT / 2)
  87. if (SBW_STARTAUTO) and (isInArray(SBW_DAYS,time.wday)) then
  88.     doBroadcastMessage(SBW_MSGWARNING)
  89.     if SBW_USEWAIT then
  90.         addEvent(doBroadcastMessage, timeopen1*1000*60, "[SNOWBALL WAR] - Resta(m) ".. timeopen2 .." minuto(s) para iniciar o evento!")
  91.         if (timeopen2 ~= timeopen1) then
  92.             addEvent(doBroadcastMessage, timeopen2*1000*60, "[SNOWBALL WAR] - Resta(m) ".. timeopen1 .." minuto(s) para iniciar o evento!")
  93.         end
  94.         addEvent(moveToEvent, SBW_TIMEWAIT*1000*60)
  95.         doCreateTeleport(1387, SBW_TPGO, SBW_TP)
  96.     else
  97.         if SBW_TFS == "0.3" then
  98.             doItemSetAttribute(doCreateItem(1387, SBW_TP), "aid", 2880)
  99.         else
  100.             doSetItemActionId(doCreateItem(1387, SBW_TP), 2880)
  101.         end
  102.         if(SBW_DURATION > 0) then
  103.             addEvent(endsnowball, SBW_DURATION*1000*60)
  104.         end
  105.     end
  106. end
  107. return true
  108. end
  109.  
  110. function onThink(interval, lastExecution)
  111. local texts = {["GERADOR"] = {SBW_GERADOR, 55, TEXTCOLOR_ORANGE}}
  112.  
  113. for text, param in pairs(texts) do
  114.     doSendAnimatedText(param[1], text, param[3])
  115.     doSendMagicEffect(param[1], param[2])
  116. end
  117. return TRUE
  118. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement