FA
pedido

[Pedido] Modificação em Script de Prêmio

Por Farathor, 06 de fev. de 2016 em Scripts

59
5.7k
FarathorF
14 de fevereiro de 2016 às 19:48

 

local query = db.query or db.executeQuery
local premios = { --  -- [chance] -- itemid,amount
[{1, 5}] = {{12674}, {11754}},
[{10, 30}] = {{2390}, {2469}, {2646}, {8306,5}, {2408}},
[{80, 100}] = {{2160,1000}}
}
 
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
 
local vocation = {
    druid,
    sorcerer,
    paladin,
    knight
}
 
function onDeath(cid, corpse, deathList)
    local gid = 0
    local winner = {}
    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 = {}
           for _, pid in pairs(getPlayersOnline()) do
               if getPlayerGuildId(pid) == gid then
                   local st = getPlayerStorageValue(pid, 1827311)
                   local i = getPlayerVocation(pid)
                   if st > mx[i%4] then
                       mx[i%4] = st
                       winner[i%4] = pid
                   end
               end
           end
           for i = 0, #winner do
               if isPlayer(winner[i]) 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 rand[1] and rand[2] or 1)
                           end
                       end
                   local recompensa = doPlayerAddItem(winner[i], itemr, amountr)
                   doBroadcastMessage("{Castle War} O jogador com maior desempenho da vocação " ..vocation[i].." foi "..getCreatureName(winner[i])..", com "..pointNumber(mx).." pontos sobre o castelo. Ele recebeu "..pointNumber(amountr).."x "..getItemNameById(itemr).." como premio.")
                   doItemSetAttribute(recompensa, 'description', "Premio do jogador "..getCreatureName(winner[i]).." ganho no evento castle war do dia "..os.date("%d/%m/%y")..".")
                   local medal = doPlayerAddItem(winner[i], 10127, 1)
                   doItemSetAttribute(medal, 'description', "Trofeu ganho pelo jogador "..getCreatureName(winner[i]).." no evento castle war do dia "..os.date("%d/%m/%y")..".")
               end
           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
SkullsS
14 de fevereiro de 2016 às 19:52

troca local mx = {} por local mx = {0, 0, 0, 0, 0, 0, 0, 0}

FarathorF
14 de fevereiro de 2016 às 20:06

@


@EDIT com dois personagens deu isso

[14/2/2016 20:2:50] [Error - CreatureScript Interface]
[14/2/2016 20:2:50] data/creaturescripts/scripts/CastleWar/CastleWar.lua:onDeath
[14/2/2016 20:2:50] Description:
[14/2/2016 20:2:50] data/creaturescripts/scripts/CastleWar/CastleWar.lua:100: attempt to concatenate a boolean value
[14/2/2016 20:2:50] stack traceback:
[14/2/2016 20:2:50] data/creaturescripts/scripts/CastleWar/CastleWar.lua:100: in function <data/creaturescripts/scripts/CastleWar/CastleWar.lua:58>

com 4 jogadores um de cada vocação deu esse

 

[14/2/2016 20:5:42] [Error - CreatureScript Interface]
[14/2/2016 20:5:42] data/creaturescripts/scripts/CastleWar/CastleWar.lua:onDeath
[14/2/2016 20:5:42] Description:
[14/2/2016 20:5:42] data/creaturescripts/scripts/CastleWar/CastleWar.lua:84: attempt to compare nil with number
[14/2/2016 20:5:42] stack traceback:
[14/2/2016 20:5:42] data/creaturescripts/scripts/CastleWar/CastleWar.lua:84: in function <data/creaturescripts/scripts/CastleWar/CastleWar.lua:58>

Editado Fevereiro 14 por Farathor

SkullsS
14 de fevereiro de 2016 às 20:12

Troca o vocations por isso:

 

local vocation = {
"druid",
"sorcerer",
"paladin",
"knight"
}
e for i = 0, #winner do por for i = 1, #winner do
FarathorF
14 de fevereiro de 2016 às 20:15

a sequencia é

Sorcerer = 1

Druid = 2

Paladin = 3

Knight = 4

 

para eu corrigir, é só eu trocar o lugar do druid pelo sorcerer?

SkullsS
14 de fevereiro de 2016 às 20:20

Sim

 

local vocation = {
"sorcerer",
"druid",
"paladin",
"knight"
}
FarathorF
14 de fevereiro de 2016 às 20:24

@edit error ->

 

com 1 jogador só ->

[14/2/2016 20:20:46] [Error - CreatureScript Interface]
[14/2/2016 20:20:46] data/creaturescripts/scripts/CastleWar/CastleWar.lua:onDeath
[14/2/2016 20:20:46] Description:
[14/2/2016 20:20:46] data/creaturescripts/scripts/CastleWar/CastleWar.lua:100: attempt to concatenate a boolean value
[14/2/2016 20:20:46] stack traceback:
[14/2/2016 20:20:46] data/creaturescripts/scripts/CastleWar/CastleWar.lua:100: in function <data/creaturescripts/scripts/CastleWar/CastleWar.lua:58>
com 2 jogadores ->
[14/2/2016 20:21:57] [Error - CreatureScript Interface]
[14/2/2016 20:21:57] data/creaturescripts/scripts/CastleWar/CastleWar.lua:onDeath
[14/2/2016 20:21:57] Description:
[14/2/2016 20:21:57] data/creaturescripts/scripts/CastleWar/CastleWar.lua:100: attempt to concatenate a boolean value
[14/2/2016 20:21:57] stack traceback:
[14/2/2016 20:21:57] data/creaturescripts/scripts/CastleWar/CastleWar.lua:100: in function <data/creaturescripts/scripts/CastleWar/CastleWar.lua:58>
com 3 jogadores ->
[14/2/2016 20:22:50] [Error - CreatureScript Interface]
[14/2/2016 20:22:50] data/creaturescripts/scripts/CastleWar/CastleWar.lua:onDeath
[14/2/2016 20:22:50] Description:
[14/2/2016 20:22:50] data/creaturescripts/scripts/CastleWar/CastleWar.lua:84: attempt to compare nil with number
[14/2/2016 20:22:50] stack traceback:
[14/2/2016 20:22:50] data/creaturescripts/scripts/CastleWar/CastleWar.lua:84: in function <data/creaturescripts/scripts/CastleWar/CastleWar.lua:58>
com 4 jogadores ->
[14/2/2016 20:23:55] [Error - CreatureScript Interface]
[14/2/2016 20:23:55] data/creaturescripts/scripts/CastleWar/CastleWar.lua:onDeath
[14/2/2016 20:23:55] Description:
[14/2/2016 20:23:55] data/creaturescripts/scripts/CastleWar/CastleWar.lua:84: attempt to compare nil with number
[14/2/2016 20:23:55] stack traceback:
[14/2/2016 20:23:55] data/creaturescripts/scripts/CastleWar/CastleWar.lua:84: in function <data/creaturescripts/scripts/CastleWar/CastleWar.lua:58>

 

SkullsS
14 de fevereiro de 2016 às 20:32

troca de novo o mx pra mx = {}

 

e antes do if st>mx[i%4] coloca a linha if not mx[i%4] then mx[i%4] = 0 end

FarathorF
14 de fevereiro de 2016 às 20:41

assim?

 

if not mx[i%4] then mx[i%4] = 0 end
if st > mx[i%4] then

com 1 jogador ja deu erro

 

[14/2/2016 20:41:19] [Error - CreatureScript Interface]
[14/2/2016 20:41:19] data/creaturescripts/scripts/CastleWar/CastleWar.lua:onDeath
[14/2/2016 20:41:19] Description:
[14/2/2016 20:41:19] data/creaturescripts/scripts/CastleWar/CastleWar.lua:101: attempt to concatenate a boolean value
[14/2/2016 20:41:19] stack traceback:
[14/2/2016 20:41:19] data/creaturescripts/scripts/CastleWar/CastleWar.lua:101: in function <data/creaturescripts/scripts/CastleWar/CastleWar.lua:58>
SkullsS
14 de fevereiro de 2016 às 21:23

Troca pointNumber(mx) por pointNumber(mx)


E ae?

FarathorF
14 de fevereiro de 2016 às 23:00

cara, ta quase, funcionou, só tem um problema, druid, sorcerer e paladin receberam o premio, o knight nao

SkullsS
14 de fevereiro de 2016 às 23:03

Eu já sei o pq, vou editar aqui 2 segundos.

 

Troca:

 

local st = getPlayerStorageValue(pid, 1827311)
local i = getPlayerVocation(pid)
if st > mx[i%4] then...
por
local st = getPlayerStorageValue(pid, 1827311)
local i = getPlayerVocation(pid)
local index = i%4
if index == 0 then index = 4 end
if st > mx[index] then

Editado Fevereiro 14 por Skulls

FarathorF
14 de fevereiro de 2016 às 23:04

o evento, utiliza um script na LIB, vou postar aqui pra vc ver se tem algo haver

guild_hit_count = {}
 
function updateCastleData()
    local func = db.query or db.executeQuery
    local max = 0
    local gid = 0
    local max_sto = 0
    local winner = 0
    for index, g in pairs(guild_hit_count) do
        if g > max then
            max = g
            gid = index
        end
    end
    for _, pid in pairs(getPlayersOnline()) do
        if getPlayerGuildId(pid) == gid then
            local sto = getPlayerStorageValue(pid, 1827311)
            if sto > max_sto then
                max_sto = sto
                winner = pid
            end
        end
    end
    if isPlayer(winner) then
        func("INSERT INTO `castle_achievements` (`guild_id`, `date`, `damage`, `player_name`, `player_damage`) VALUES ('"..gid.."', '"..os.date('%d/%m/%y - %H:%M').."', '"..max.."', '"..getCreatureName(winner).."', '"..max_sto.."')")
    else
        func("INSERT INTO `castle_achievements` (`guild_id`, `date`, `damage`) VALUES ('"..gid.."', '"..os.date("%d/%m/%y - %H:%M").."', '"..max.."')")
    end
end          
 
function getPlayingGuilds()
    local ids = {}
    for index, g in pairs(guild_hit_count) do
        table.insert(ids, index)
    end
    if #ids <= 0 then
        return false
    end
    return ids
end
 
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 

Editado Fevereiro 14 por Farathor

SkullsS
14 de fevereiro de 2016 às 23:04

Troca:

local st = getPlayerStorageValue(pid, 1827311)
local i = getPlayerVocation(pid)
if st > mx[i%4] then...
por
local st = getPlayerStorageValue(pid, 1827311)
local i = getPlayerVocation(pid)
local index = i%4
if index == 0 then index = 4 end
if st > mx[index] then
FarathorF
14 de fevereiro de 2016 às 23:07

eu nao deixo o if not mx[i%4] then mx[i%4] = 0 end ?