Gpwjhlkdcf 21 #1 Posted September 8, 2009 (edited) Tópico do POG POG = Programação Orientada a Gambiarras (Clique aqui e saiba mais!) Postem aqui seus POGs e comentem sobre o POG dos outros, e tentem não floodar. Exceto o Flatronez. 90% deste tópico será de posts dele. Vou começar com um POG que eu acabei de fazer: function onCastSpell(cid, var) for i, v in pairs(var) do if type(v) == "table" then for x, y in pairs(v) do if type(y) == "table" then doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Multiple tables!") else doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, i.." | y: "..x..", "..y) end end else doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "v: "..i..", "..v) end end return doSendMagicEffect(var.pos, CONST_ME_POFF) end Motivo disto? Eu queria saber quais mistérios a variavel "var" guardava consigo, pois eu já estava ficando frustrado! O POG funcionou, veja só o resultado in-game: 16:57 pos | y: y, 13616:57 pos | y: x, 140 16:57 pos | y: stackpos, 0 16:57 pos | y: z, 7 16:57 v: type, 2 Postem os seus! Edited January 23, 2011 by Mickfern Share this post Link to post Share on other sites
Magus 2 #2 Posted September 11, 2009 (edited) function mapRoute(cid,f,t) local route,pos,inv = {f} if (f.x > t.x and f.y < t.y) then inv = true t.x,f.x,t.y,f.y = f.x,t.x,f.y,t.y end for x = f.x, t.x do for y = f.y, t.y do pos = {x=x,y=y,z=f.z} if (doTileQueryAdd(cid, pos) == 1) then table.insert(route, pos) end end end table.sort(route, function(a, local c = t.x + t.y return a.x + a.y - c < b.x + b.y - c end) local function posExists(pos) local comp = { __eq = function(v1,v2) return v1.x == v2.x and v1.y == v2.y and v1.z == v2.z end } setmetatable(pos, comp) for i, v in pairs(route) do setmetatable(v, comp) if (pos == v) then return i end end return end for i, v in pairs(route) do local ret = { a = { {x=v.x+1,y=v.y,z=v.z}, {x=v.x,y=v.y+1,z=v.z}, {x=v.x+1,y=v.y+1,z=v.z} }, b = { {x=v.x-1,y=v.y,z=v.z}, {x=v.x,y=v.y-1,z=v.z}, {x=v.x-1,y=v.y-1,z=v.z} } } local ret = inv and ret.b or ret.a for t = 1, #ret do cont = posExists(ret[t]) if cont then for i = i+1, cont-1 do route[i] = nil end break end end end return route end Não deu tão certo quanto eu esperava, haha. Faz tempo que tá parada aqui >_> Edited January 23, 2011 by Mickfern Share this post Link to post Share on other sites
Addicted 1 #3 Posted September 12, 2009 (edited) function mapRoute(cid,f,t) local route,pos,inv = {f} if (f.x > t.x and f.y < t.y) then inv = true t.x,f.x,t.y,f.y = f.x,t.x,f.y,t.y end for x = f.x, t.x do for y = f.y, t.y do pos = {x=x,y=y,z=f.z} if (doTileQueryAdd(cid, pos) == 1) then table.insert(route, pos) end end end table.sort(route, function(a, local c = t.x + t.y return a.x + a.y - c < b.x + b.y - c end) local function posExists(pos) local comp = { __eq = function(v1,v2) return v1.x == v2.x and v1.y == v2.y and v1.z == v2.z end } setmetatable(pos, comp) for i, v in pairs(route) do setmetatable(v, comp) if (pos == v) then return i end end return end for i, v in pairs(route) do local ret = { a = { {x=v.x+1,y=v.y,z=v.z}, {x=v.x,y=v.y+1,z=v.z}, {x=v.x+1,y=v.y+1,z=v.z} }, b = { {x=v.x-1,y=v.y,z=v.z}, {x=v.x,y=v.y-1,z=v.z}, {x=v.x-1,y=v.y-1,z=v.z} } } local ret = inv and ret.b or ret.a for t = 1, #ret do cont = posExists(ret[t]) if cont then for i = i+1, cont-1 do route[i] = nil end break end end end return route end Não deu tão certo quanto eu esperava, haha. Faz tempo que tá parada aqui >_> Eu achando que ia ficar anos lendo seus pogs. Só postou um né safado. Edited January 23, 2011 by Mickfern Share this post Link to post Share on other sites
Mock 32 #4 Posted September 13, 2009 (edited) Meu maior pog... O meu IRC bot eu tentei fazer ele verificar se o ot tava on porem nao consegi entao apelei pro pog. fui no apache abri ele criei uma pagina que veirfica ots e pronto oia o code ai: (SO FIZ PQ JA TAVA COM UM SOCKET E ABERTO E N SEI PQ QDO EU ABRIA OTRO O SERVER N RESPONDIA ._.') function onIRCRecieve(msg,sender,msg_total,param) if param == nil or string.len(param) <= 0 then botSendNotice(sender,"Mande o comando corretamente!") return FALSE end botSendNotice(sender,'21,155[12Verificando aguarde...5]') http = require("socket.http") b, c, h = http.request("http://localhost:7172/teste/index.php?subtopic="..param.."") if b == "offline" then botSendMsg("0,1415<1> Server 15%0,18"..param.."0:1371710,1415%0,512[4Offline12]0,140,1415<1>") return TRUE end botSendMsg("0,1415<1> Server 15%0,18"..param.."0:1371710,1415%0,312[9Online12]0,140,1415<1>") b = string.explode(b,'€') print(b[1],b[2]) for i=1,7 do b[i] = b[i] or "Information falied" string.gsub(b[i],"\n","") string.gsub(b[i],"/n","") end botSendMsg(b[1]..", "..b[2]..", "..b[3]..", "..b[4]..", "..b[5]..", "..b[6]..".") botSendMsg(b[7]) return TRUE end Edited January 23, 2011 by Mickfern Share this post Link to post Share on other sites
Gpwjhlkdcf 21 #5 Posted September 13, 2009 (edited) Meu maior pog...O meu IRC bot eu tentei fazer ele verificar se o ot tava on porem nao consegi entao apelei pro pog. fui no apache abri ele criei uma pagina que veirfica ots e pronto oia o code ai: function onIRCRecieve(msg,sender,msg_total,param) if param == nil or string.len(param) <= 0 then botSendNotice(sender,"Mande o comando corretamente!") return FALSE end botSendNotice(sender,'21,155[12Verificando aguarde...5]') http = require("socket.http") b, c, h = http.request("http://localhost:7172/teste/index.php?subtopic="..param.."") if b == "offline" then botSendMsg("0,1415<1> Server 15%0,18"..param.."0:1371710,1415%0,512[4Offline12]0,140,1415<1>") return TRUE end botSendMsg("0,1415<1> Server 15%0,18"..param.."0:1371710,1415%0,312[9Online12]0,140,1415<1>") b = string.explode(b,'€') print(b[1],b[2]) for i=1,7 do b[i] = b[i] or "Information falied" string.gsub(b[i],"\n","") string.gsub(b[i],"/n","") end botSendMsg(b[1]..", "..b[2]..", "..b[3]..", "..b[4]..", "..b[5]..", "..b[6]..".") botSendMsg(b[7]) return TRUE end EPIC POG! Esse merece: Puts, esse humilhou o meu e o do Magus juntos... '-' Edited January 23, 2011 by Mickfern Share this post Link to post Share on other sites
Blackout 0 #6 Posted September 17, 2009 Participem: http://forums.otserv.com.br/group.php?groupid=310 ... Se eu for postar pog meu aqui nem vai dar... Tudo que eu faço é na base da gambiarra. Share this post Link to post Share on other sites
Gpwjhlkdcf 21 #7 Posted September 17, 2009 (edited) Participem: http://forums.otserv.com.br/group.php?groupid=310 ... Se eu for postar pog meu aqui nem vai dar... Tudo que eu faço é na base da gambiarra. Não tem problema, o Flatronez também. Pode postar, o tópico tá aqui pra isso. Aproveitando a oportunidade deste comentário, la vai mais um POG meu. Dessa vez é um POG pra ver se um POG funciona: function isFunctional(func, ...) status, error = pcall(func, ...) if error then return false end return true end Edited January 23, 2011 by Mickfern Share this post Link to post Share on other sites
Gpwjhlkdcf 21 #8 Posted September 28, 2009 (edited) Mais um POG fresquinho pra vocês: A função getItemWeaponType não funciona com Bows, CrossBows, etc... Então, apelemos para o POG: function isRanged(item) if item.itemid > 0 and getItemShootRange(item.uid) > 0 then return true end return false end getItemWeaponType_ = getItemWeaponType function getItemWeaponType(item) if isRanged(item) then return 5 end return getItemWeaponType_(item) end Apreciem com moderação... Edited January 23, 2011 by Mickfern Share this post Link to post Share on other sites
Fadi 0 #9 Posted October 1, 2009 (edited) Wow, "POG" é boa xD local fluidContainers = {2005,2006,2007,2008,2009,2011,2012,2013,2014,2015,2023,1775,2031,2032,2033,2034,2574,2575,2576,2577} function doPotion(cid, item, item2,frompos, base,ingredients, types, actionids, effect, finisheffect) local potid = 2562 local failtype = 15 local faileffect = 2 for x = 0, table.maxn(fluidContainers) do if item2.itemid == fluidContainers[x] then if item2.type == 0 then if item.type ~= 0 then doChangeTypeItem(item2.uid,item.type) doChangeTypeItem(item.uid,0) check = 1 end else doPlayerPopupFYI(cid,"There is already something in this fluid container") end end end if item.itemid == potid then if item.type == base then if types.first ~= 0 then doSetItemActionId(item.uid,actionids.first) if item2.itemid == ingredients.first then doRemoveItem(item2.uid,1) doSendMagicEffect(frompos,effect) doChangeTypeItem(item.uid,types.first) if types.second ~= 0 then doSetItemActionId(item.uid,actionids.first) else doSetItemActionId(item.uid,actionids.final) end else if check ~= 1 then doPlayerPopupFYI(cid,"This is not the right ingredient") doSendMagicEffect(frompos,faileffect) end end elseif types.first == 0 and types.second ~= 0 then if item2.itemid == ingredients.second then doRemoveItem(item2.uid,1) doSendMagicEffect(frompos,effect) doChangeTypeItem(item.uid,types.second) doSetItemActionId(item.uid,actionids.final) else if check ~= 1 then doPlayerPopupFYI(cid,"This is not the right ingredient") doSendMagicEffect(frompos,faileffect) end end elseif types.first == 0 and types.second == 0 then if item2.itemid == ingredients.final then doRemoveItem(item2.uid,1) doSendMagicEffect(frompos,finisheffect) doChangeTypeItem(item.uid,types.final) doPlayerSendTextMessage(cid,22, "You have finished the potion!" ) else if check ~= 1 then doPlayerPopupFYI(cid,"This is not the right ingredient") doSendMagicEffect(frompos,faileffect) end end end elseif item.type ~= types.base and item.actionid == actionids.first then if item2.itemid == ingredients.second then doRemoveItem(item2.uid,1) doSendMagicEffect(frompos,effect) doChangeTypeItem(item.uid,types.second) doSetItemActionId(item.uid,actionids.final) else if check ~= 1 then doPlayerPopupFYI(cid,"This is not the right ingredient") doSendMagicEffect(frompos,faileffect) end end elseif item.type ~= types.base and item.actionid == actionids.final then if item2.itemid == ingredients.final then doRemoveItem(item2.uid,1) doSendMagicEffect(frompos,finisheffect) doChangeTypeItem(item.uid,types.final) doPlayerSendTextMessage(cid, 22, "You have finished the potion!" ) else if check ~= 1 then doPlayerPopupFYI(cid,"This is not the right ingredient") doSendMagicEffect(frompos,faileffect) end end end else print('Action object is not valid to this function') end end function onUse(cid, item, frompos, item2, topos) ingredients = {first = 5879, second = 5881, final = 5883} types = {first = 3, second = 4, final = 5} actionids = {first = 60758, final = 60759} base = 2 effect = 12 finaleffect = 21 doPotion(cid, item, item2, frompos, base, ingredients, types, actionids, effect, finaleffect) end Essa droga nunca funcionou direito u.u Edited January 23, 2011 by Mickfern Share this post Link to post Share on other sites
Eventide 7 #10 Posted October 1, 2009 table.maxn foi abolida =( Share this post Link to post Share on other sites
Nord 2 #11 Posted October 13, 2009 (edited) Fadi, sua doPotion nunca funcionou, eu fiz uma pra vc e nunca usa Quanto eu não conhecia a função queryTileAddThing eu decidi fazer uma função pra ver se tal posição dava pra andar ou não e acabou saindo a isWalkable, eu demorei +- 1 semana pra fazer a primeira versão, essa é a versão atual dela: function isWalkable(pos, creature, proj, pz) pos.stackpos = 0 if getTileThingByPos(pos).uid == 0 then return FALSE end if getTopCreature(pos).uid > 0 and creature == TRUE then return FALSE end if getTileInfo(pos).protection == TRUE and (pz == 1 or pz == nil) then return FALSE end local n = (proj == nil or proj == 0) and 3 or 2 for i = 0, 50 do pos.stackpos = i local tile = getTileThingByPos(pos) if tile.itemid ~= 0 and isCreature(tile.uid) == FALSE then if (hasProperty(tile.uid, n) == TRUE or hasProperty(tile.uid, 7) == TRUE) then return FALSE end end end return TRUE end Até hoje acredito que fiz essa função por estar realmente no aperto, na época eu precisei dela pra uma spell que empurrava players. Edited January 23, 2011 by Mickfern Share this post Link to post Share on other sites
Mock 32 #12 Posted October 13, 2009 (edited) Nord... Vc merece Pog powered! meu utimo pog: http://www.lua.pastey.net/130403-5b9x Edited December 19, 2009 by Mock Share this post Link to post Share on other sites
Gpwjhlkdcf 21 #13 Posted January 21, 2010 (edited) OBS: O script NÃO é meu '-' Observem que ele inocentemente cria seu próprio sistema de linhas, já que a droga do bloco de notas não possui um contador. Que droga em bloco de notas! [...]--[[4]] coisaid = 2556 --[[5]] coisapos = {x=xxx, y=yyy, z=z, stackpos=2} --[[6]] coisa = getThingFromPos(coisapos) --[[7]] storage = 1518 --[[8]] --[[9]] if (item.itemid == 1945) then --[[10]] if (getPlayerStorageValue(cid,storage) == -1) then --[[11]] if (coisa.itemid == coisaid) then --[[12]] doSendMagicEffect(coisa,1) --[[13]] doTeleportThing(cid,npos) [...] Juro que chorei por 10 minutos a fio de tanto rir. Edited January 23, 2011 by Mickfern Share this post Link to post Share on other sites
Eventide 7 #14 Posted January 21, 2010 ri litros desses 2 ultimos POGs, o do Mock é ainda mais cabuloso...(e desnecessário) Share this post Link to post Share on other sites
Ramza 11 #15 Posted July 8, 2010 (edited) OBS: O script NÃO é meu '-' Observem que ele inocentemente cria seu próprio sistema de linhas, já que a droga do bloco de notas não possui um contador. Que droga em bloco de notas! [...] --[[4]] coisaid = 2556 --[[5]] coisapos = {x=xxx, y=yyy, z=z, stackpos=2} --[[6]] coisa = getThingFromPos(coisapos) --[[7]] storage = 1518 --[[8]] --[[9]] if (item.itemid == 1945) then --[[10]] if (getPlayerStorageValue(cid,storage) == -1) then --[[11]] if (coisa.itemid == coisaid) then --[[12]] doSendMagicEffect(coisa,1) --[[13]] doTeleportThing(cid,npos) [...] Juro que chorei por 10 minutos a fio de tanto rir. Putz, esse merece ser revivido! Ri por meia hora também disso, OMG! Epic Gambiarra! DHUSADHUHDSAAHUDHUSAAHUDAHUDHASUDSAHDUSHDUD Merece um beijo do notorious HDUSAHDUHAUSDSADASHDUSADHA Edited January 23, 2011 by Mickfern Share this post Link to post Share on other sites
Notorious 1 #16 Posted July 8, 2010 (edited) Merece um beijo do notorious HDUSAHDUHAUSDSADASHDUSADHA :viado: Edited July 8, 2010 by Notorious Share this post Link to post Share on other sites