Farathor 22 Postado Maio 24, 2015 Share Postado Maio 24, 2015 (editado) Pessoal, gostaria de saber, se nesse script, os prêmios, estão com uma certa chance de vir. local query = db.query or db.executeQuery local premios = {{2390, 1, 200}, {2469, 1, 200}, {2646, 1, 200}, {8306, 1, 200}, {2408, 1, 200}, {10020, 1, 1}, {5804, 1, 1}, {5809, 1, 1}, {5937, 1, 1}} local function getGuildNameById(id) local name = "" local query = db.getResult('SELECT `name` FROM `guilds` WHERE `id` = "'.. id ..'"') if query:getID() == -1 then return true end name = query:getDataString("name") query:free() return name end function pointNumber(number) if not tonumber(number) then return false end local str = "" number = tostring(number):reverse() local count = 0 for i = 1, number:len() do count = count + 1 if count <= 3 then if str == "" then str = number:sub(i, i) else str = str..number:sub(i, i) end else count = 1 str = str.."."..number:sub(i, i) end end return str:reverse() end function onStatsChange(cid, attacker, type, combat, value) if isMonster(cid) and isPlayer(attacker) and type == STATSCHANGE_HEALTHLOSS then if isInArray({"Castle Guardian I", "Castle Guardian II", "Castle Guardian III", "Castle Guardian IV", "Castle Generator", "Ice Crystal"}, getCreatureName(cid)) then doPlayerSetStorageValue(attacker, 1827311, getPlayerStorageValue(attacker, 1827311) + value) local quant = guild_hit_count[getPlayerGuildId(attacker)] and guild_hit_count[getPlayerGuildId(attacker)] or 0 guild_hit_count[getPlayerGuildId(attacker)] = quant + value end end return true end function onDeath(cid, corpse, deathList) local gid = 0 local winner = 0 if isMonster(cid) and getCreatureName(cid) == "Ice Crystal" then if not getPlayingGuilds() then return true end local guilds = getPlayingGuilds() local max = 0 for index, var in pairs(guild_hit_count) do if var > max then max = var gid = index end end setGlobalStorageValue(1823999, gid) query("UPDATE `castle_dono` SET `guild_id` = '"..gid.."' WHERE `guild_id` > 0") doBroadcastMessage("{Castle War} O evento acabou, a guild com maior desempenho foi "..getGuildNameById(gid)..", com "..pointNumber(max).." pontos sobre o castelo.") updateCastleData() setGlobalStorageValue(18219113, -1) if gid > 0 then local mx = 0 for _, pid in pairs(getPlayersOnline()) do if getPlayerGuildId(pid) == gid then local st = getPlayerStorageValue(pid, 1827311) if st > mx then mx = st winner = pid end end end if isPlayer(winner) then local rand = math.random(1, #premios) local itemr,amountr = premios[rand][1], premios[rand][2] local recompensa = doPlayerAddItem(winner, itemr, amountr) doBroadcastMessage("{Castle War} O jogador com maior desempenho foi "..getCreatureName(winner)..", com "..pointNumber(mx).." pontos sobre o castelo. Ele recebeu "..pointNumber(amountr).."x "..getItemNameById(itemr).." como premio.") doItemSetAttribute(recompensa, 'description', "Premio do jogador "..getCreatureName(winner).." ganho no evento castle war do dia "..os.date("%d/%m/%y")..".") local medal = doPlayerAddItem(winner, 10127, 1) doItemSetAttribute(medal, 'description', "Trofeu ganho pelo jogador "..getCreatureName(winner).." no evento castle war do dia "..os.date("%d/%m/%y")..".") end end for _, pid in pairs(getPlayersOnline()) do if isInArea(getThingPos(pid), {x = 500, y = 574, z = 6}, {x = 575, y = 620, z = 6}) or isInArea(getThingPos(pid), {x = 511, y = 588, z = 5}, {x = 556, y = 607, z = 5}) or isInArea(getThingPos(pid), {x = 511, y = 588, z = 4}, {x = 556, y = 607, z = 4}) or isInArea(getThingPos(pid), {x = 511, y = 588, z = 3}, {x = 556, y = 607, z = 3}) or isInArea(getThingPos(pid), {x = 481, y = 580, z = 7}, {x = 683, y = 798, z = 7}) then doTeleportThing(pid, getTownTemplePosition(getPlayerTown(pid))) end end guild_hit_count = {} end return true end local premios = {{2390, 1, 200}} Aqui Seria assim. ID,Quantidade,Chance. gostaria de saber se isso está acontecendo realmente. Editado Maio 24, 2015 por Farathor Link para o comentário https://xtibia.com/forum/topic/234080-d%C3%BAvida-premio-por-chance/ Compartilhar em outros sites More sharing options...
Furabio 258 Postado Maio 24, 2015 Share Postado Maio 24, 2015 (editado) Da forma que o script está ele apenas da o item aleatoriamente pro player. You see!~ Editado Maio 24, 2015 por ScreaM Link para o comentário https://xtibia.com/forum/topic/234080-d%C3%BAvida-premio-por-chance/#findComment-1652529 Compartilhar em outros sites More sharing options...
Farathor 22 Postado Maio 24, 2015 Autor Share Postado Maio 24, 2015 teria como colocar para ele dar o item aleatoriamente, mas por exemplo, com chance, um item seria mais dificil que o outro por exemplo Link para o comentário https://xtibia.com/forum/topic/234080-d%C3%BAvida-premio-por-chance/#findComment-1652532 Compartilhar em outros sites More sharing options...
Vodkart 1515 Postado Maio 24, 2015 Share Postado Maio 24, 2015 local query = db.query or db.executeQuery local premios = { -- [chance] -- itemid,amount [{1, 3}] = {2390, 1}, -- por exmeplo de 1 a 3 porcento de vim 1 item com id 2390 [{4, 15}] = {2469, 1}, [{16, 25}] = {2646, 1}, [{25, 40}] = {8306, 1}, [{41, 55}] = {2408, 1}, [{56, 65}] = {10020, 1}, [{66, 75}] = {5804, 1}, [{76, 86}] = {5809, 1}, [{86, 100}] = {5937, 1} } local function getGuildNameById(id) local name = "" local query = db.getResult('SELECT `name` FROM `guilds` WHERE `id` = "'.. id ..'"') if query:getID() == -1 then return true end name = query:getDataString("name") query:free() return name end function pointNumber(number) if not tonumber(number) then return false end local str = "" number = tostring(number):reverse() local count = 0 for i = 1, number:len() do count = count + 1 if count <= 3 then if str == "" then str = number:sub(i, i) else str = str..number:sub(i, i) end else count = 1 str = str.."."..number:sub(i, i) end end return str:reverse() end function onStatsChange(cid, attacker, type, combat, value) if isMonster(cid) and isPlayer(attacker) and type == STATSCHANGE_HEALTHLOSS then if isInArray({"Castle Guardian I", "Castle Guardian II", "Castle Guardian III", "Castle Guardian IV", "Castle Generator", "Ice Crystal"}, getCreatureName(cid)) then doPlayerSetStorageValue(attacker, 1827311, getPlayerStorageValue(attacker, 1827311) + value) local quant = guild_hit_count[getPlayerGuildId(attacker)] and guild_hit_count[getPlayerGuildId(attacker)] or 0 guild_hit_count[getPlayerGuildId(attacker)] = quant + value end end return true end function onDeath(cid, corpse, deathList) local gid = 0 local winner = 0 if isMonster(cid) and getCreatureName(cid) == "Ice Crystal" then if not getPlayingGuilds() then return true end local guilds = getPlayingGuilds() local max = 0 for index, var in pairs(guild_hit_count) do if var > max then max = var gid = index end end setGlobalStorageValue(1823999, gid) query("UPDATE `castle_dono` SET `guild_id` = '"..gid.."' WHERE `guild_id` > 0") doBroadcastMessage("{Castle War} O evento acabou, a guild com maior desempenho foi "..getGuildNameById(gid)..", com "..pointNumber(max).." pontos sobre o castelo.") updateCastleData() setGlobalStorageValue(18219113, -1) if gid > 0 then local mx = 0 for _, pid in pairs(getPlayersOnline()) do if getPlayerGuildId(pid) == gid then local st = getPlayerStorageValue(pid, 1827311) if st > mx then mx = st winner = pid end end end if isPlayer(winner) then local r = math.random(1,100) for v, k in pairs(premios) do if r >= v[1] and r <= v[2] then local itemr, amountr = k[1], k[2] local recompensa = doPlayerAddItem(winner, itemr, amountr) doBroadcastMessage("{Castle War} O jogador com maior desempenho foi "..getCreatureName(winner)..", com "..pointNumber(mx).." pontos sobre o castelo. Ele recebeu "..amountr.."x "..getItemNameById(itemr).." como premio.") doItemSetAttribute(recompensa, 'description', "Premio do jogador "..getCreatureName(winner).." ganho no evento castle war do dia "..os.date("%d/%m/%y")..".") end end local medal = doPlayerAddItem(winner, 10127, 1) doItemSetAttribute(medal, 'description', "Trofeu ganho pelo jogador "..getCreatureName(winner).." no evento castle war do dia "..os.date("%d/%m/%y")..".") end end for _, pid in pairs(getPlayersOnline()) do if isInArea(getThingPos(pid), {x = 500, y = 574, z = 6}, {x = 575, y = 620, z = 6}) or isInArea(getThingPos(pid), {x = 511, y = 588, z = 5}, {x = 556, y = 607, z = 5}) or isInArea(getThingPos(pid), {x = 511, y = 588, z = 4}, {x = 556, y = 607, z = 4}) or isInArea(getThingPos(pid), {x = 511, y = 588, z = 3}, {x = 556, y = 607, z = 3}) or isInArea(getThingPos(pid), {x = 481, y = 580, z = 7}, {x = 683, y = 798, z = 7}) then doTeleportThing(pid, getTownTemplePosition(getPlayerTown(pid))) end end guild_hit_count = {} end return true end Link para o comentário https://xtibia.com/forum/topic/234080-d%C3%BAvida-premio-por-chance/#findComment-1652533 Compartilhar em outros sites More sharing options...
Farathor 22 Postado Maio 24, 2015 Autor Share Postado Maio 24, 2015 (editado) Não sei porque, mas ta acontecendo isso 18:22 {Castle War} O evento acabou, a guild com maior desempenho foi Eduardo Rodrigues, com 2.810 pontos sobre o castelo. 18:22 {Castle War} O jogador com maior desempenho foi GOD Farathor, com 57.396.246 pontos sobre o castelo. Ele recebeu 1x golden boots como premio. 18:22 {Castle War} O jogador com maior desempenho foi GOD Farathor, com 57.396.246 pontos sobre o castelo. Ele recebeu 5x pure energy como premio. 18:22 {Castle War} O jogador com maior desempenho foi GOD Farathor, com 57.396.246 pontos sobre o castelo. Ele recebeu 1x warlord sword como premio. 18:22 {Castle War} O jogador com maior desempenho foi GOD Farathor, com 57.396.246 pontos sobre o castelo. Ele recebeu 1x magic longsword como premio. 18:22 {Castle War} O jogador com maior desempenho foi GOD Farathor, com 57.396.246 pontos sobre o castelo. Ele recebeu 1x dragon scale legs como premio. [{10, 30}] = {2390, 1}, -- por exmeplo de 1 a 3 porcento de vim 1 item com id 2390 [{10, 30}] = {2469, 1}, [{10, 30}] = {2646, 1}, [{20, 50}] = {8306, 5}, [{10, 30}] = {2408, 1}, [{1, 5}] = {10020, 1}, [{1, 5}] = {5804, 1}, [{1, 5}] = {5809, 1}, [{1, 5}] = {5937, 1} @edit, tem vezes que vai normal e tem vezes que só aparece e mensagem da guild. 18:30 {Castle War} O evento acabou, a guild com maior desempenho foi Eduardo Rodrigues, com 12.083 pontos sobre o castelo. 18:30 {Castle War} O jogador com maior desempenho foi GOD Farathor, com 57.424.065 pontos sobre o castelo. Ele recebeu 1x pure energy como premio. 18:31 A ice crystal loses 281 hitpoints due to your attack. 18:31 {Castle War} O evento acabou, a guild com maior desempenho foi Eduardo Rodrigues, com 281 pontos sobre o castelo. @Edit² Os pontos do jogador, estão acumulando, teria como corrigir isto também? @Edit³ Quando o jogador ganha mais de 1 item que não é acumulativo, só vem 1 item. Por exemplo: o Pure Energy não acumula, era pra vir 5 items, mas só veio 1 Editado Maio 24, 2015 por Farathor Link para o comentário https://xtibia.com/forum/topic/234080-d%C3%BAvida-premio-por-chance/#findComment-1652605 Compartilhar em outros sites More sharing options...
Vodkart 1515 Postado Maio 25, 2015 Share Postado Maio 25, 2015 (editado) claro vc duplico as chance de porcentagem... vc quer colocar mais de um item pra vir entre 10 e 30 porcento de chance é isso? vo fazer pra vc e dps vc edita, mas n pode duplicar as chances --------------------- local query = db.query or db.executeQuery local premios = { -- -- [chance] -- itemid,amount [{1, 5}] = {{2493}, {2494}}, -- por exmeplo de 1 a 3 porcento de vim 1 item com id 2390 ou 2494 [{6, 30}] = {{2646}, {2471}, {2466}, {2130}}, [{31, 50}] = {{2191}, {2201}}, [{51, 80}] = {{2339}, {2342}}, [{81, 100}] = {{6500,100}, {6500,50}} } local function getGuildNameById(id) local name = "" local query = db.getResult('SELECT `name` FROM `guilds` WHERE `id` = "'.. id ..'"') if query:getID() == -1 then return true end name = query:getDataString("name") query:free() return name end function pointNumber(number) if not tonumber(number) then return false end local str = "" number = tostring(number):reverse() local count = 0 for i = 1, number:len() do count = count + 1 if count <= 3 then if str == "" then str = number:sub(i, i) else str = str..number:sub(i, i) end else count = 1 str = str.."."..number:sub(i, i) end end return str:reverse() end function onStatsChange(cid, attacker, type, combat, value) if isMonster(cid) and isPlayer(attacker) and type == STATSCHANGE_HEALTHLOSS then if isInArray({"Castle Guardian I", "Castle Guardian II", "Castle Guardian III", "Castle Guardian IV", "Castle Generator", "Ice Crystal"}, getCreatureName(cid)) then doPlayerSetStorageValue(attacker, 1827311, getPlayerStorageValue(attacker, 1827311) + value) local quant = guild_hit_count[getPlayerGuildId(attacker)] and guild_hit_count[getPlayerGuildId(attacker)] or 0 guild_hit_count[getPlayerGuildId(attacker)] = quant + value end end return true end function onDeath(cid, corpse, deathList) local gid = 0 local winner = 0 if isMonster(cid) and getCreatureName(cid) == "Ice Crystal" then if not getPlayingGuilds() then return true end local guilds = getPlayingGuilds() local max = 0 for index, var in pairs(guild_hit_count) do if var > max then max = var gid = index end end setGlobalStorageValue(1823999, gid) query("UPDATE `castle_dono` SET `guild_id` = '"..gid.."' WHERE `guild_id` > 0") doBroadcastMessage("{Castle War} O evento acabou, a guild com maior desempenho foi "..getGuildNameById(gid)..", com "..pointNumber(max).." pontos sobre o castelo.") updateCastleData() setGlobalStorageValue(18219113, -1) if gid > 0 then local mx = 0 for _, pid in pairs(getPlayersOnline()) do if getPlayerGuildId(pid) == gid then local st = getPlayerStorageValue(pid, 1827311) if st > mx then mx = st winner = pid end end end if isPlayer(winner) then local r = math.random(1,100) for v, k in pairs(premios) do if r >= v[1] and r <= v[2] then local rand = k[math.random(#k)] itemr, amountr = rand[1], (not rand[2] and 1 or isItemStackable(rand[1]) and rand[2] or 1) end end local recompensa = doPlayerAddItem(winner, itemr, amountr) doBroadcastMessage("{Castle War} O jogador com maior desempenho foi "..getCreatureName(winner)..", com "..pointNumber(mx).." pontos sobre o castelo. Ele recebeu "..amountr.."x "..getItemNameById(itemr).." como premio.") doItemSetAttribute(recompensa, 'description', "Premio do jogador "..getCreatureName(winner).." ganho no evento castle war do dia "..os.date("%d/%m/%y")..".") local medal = doPlayerAddItem(winner, 10127, 1) doItemSetAttribute(medal, 'description', "Trofeu ganho pelo jogador "..getCreatureName(winner).." no evento castle war do dia "..os.date("%d/%m/%y")..".") end end for _, pid in pairs(getPlayersOnline()) do if isInArea(getThingPos(pid), {x = 500, y = 574, z = 6}, {x = 575, y = 620, z = 6}) or isInArea(getThingPos(pid), {x = 511, y = 588, z = 5}, {x = 556, y = 607, z = 5}) or isInArea(getThingPos(pid), {x = 511, y = 588, z = 4}, {x = 556, y = 607, z = 4}) or isInArea(getThingPos(pid), {x = 511, y = 588, z = 3}, {x = 556, y = 607, z = 3}) or isInArea(getThingPos(pid), {x = 481, y = 580, z = 7}, {x = 683, y = 798, z = 7}) then doTeleportThing(pid, getTownTemplePosition(getPlayerTown(pid))) end end guild_hit_count = {} end return true end ------------------------- explicação local premios = { -- -- [chance] -- itemid,amount [{1, 5}] = {{2493}, {2494}}, -- por exmeplo de 1 a 3 porcento de vim 1 item com id 2390 ou 2494 [{6, 30}] = {{2646}, {2471}, {2466}, {2130}}, [{31, 50}] = {{2191}, {2201}}, [{51, 80}] = {{2339}, {2342}}, [{81, vc pode editar na tabela por exmeplo na chance de 1 a 5 porcento: [{1, 5}] = {{2493}, {2494}}, poderá vir um 2493 ou um 2494... se vc quiser editar para colocar mais itens poderia ser assim: [{1, 5}] = {{2493}, {2494}, {2492}}, e se vc quiser colocar item empilhavem como crystal coin só colocar assim: [{1, 5}] = {{2493}, {2494}, {2160,100}}, se n entendeu me adc skype thiago.vodkart Editado Maio 25, 2015 por Vodkart Link para o comentário https://xtibia.com/forum/topic/234080-d%C3%BAvida-premio-por-chance/#findComment-1652624 Compartilhar em outros sites More sharing options...
Farathor 22 Postado Maio 28, 2015 Autor Share Postado Maio 28, 2015 (editado) Mais uma coisinha, teria como, invés dele enviar os items para o personagem, ele poderia enviar para o depot? GOD Farathor has logged in. > Broadcasted message: "{Castle War} O evento acabou, a guild com maior desempenho foi Eduardo Rodrigues, com 13 pontos sobre o castelo.". [Error - CreatureScript Interface] data/creaturescripts/scripts/CastleWar/CastleWar.lua:onDeath Description: (luaDoPlayerAddItem) Item not found [Error - CreatureScript Interface] data/creaturescripts/scripts/CastleWar/CastleWar.lua:onDeath Description: data/lib/100-shortcut.lua:260: attempt to index a boolean value stack traceback: data/lib/100-shortcut.lua:260: in function 'getItemNameById' data/creaturescripts/scripts/CastleWar/CastleWar.lua:92: in function <data/creaturescripts/scripts/CastleWar/CastleWar.lua:52> vod? up Editado Maio 26, 2015 por Farathor Link para o comentário https://xtibia.com/forum/topic/234080-d%C3%BAvida-premio-por-chance/#findComment-1652817 Compartilhar em outros sites More sharing options...
Farathor 22 Postado Maio 31, 2015 Autor Share Postado Maio 31, 2015 Vodkart? Link para o comentário https://xtibia.com/forum/topic/234080-d%C3%BAvida-premio-por-chance/#findComment-1653680 Compartilhar em outros sites More sharing options...
Bruno 536 Postado Julho 14, 2015 Share Postado Julho 14, 2015 O tópico foi fechado e movido para lixeira por estar inativo a mais de 10 dias. Caso seja preciso reabrir o mesmo, favor entrar em contato com a equipe. Link para o comentário https://xtibia.com/forum/topic/234080-d%C3%BAvida-premio-por-chance/#findComment-1660187 Compartilhar em outros sites More sharing options...
Posts Recomendados