• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Creaturescripts Help

creatserver

New Member
Joined
Feb 7, 2015
Messages
25
Reaction score
0
For when a guild kills the boss only wins the members who are online. Offline will not win.

Lua:
function onDeath(cid, corpse, lastHitKiller, mostDamageKiller)
    local killer = lastHitKiller[1]
    if isPlayer(killer) and (getCreatureName(cid) == "Gran Tower") then
        if (getGlobalStorageValue(GRANTOWER.FINALWINNER) ~= getCreatureName(killer)) then
            if getPlayerGuildId(killer) >= 1 then
                for index, creature in ipairs(getGranTowerPlayers()) do
                    if getPlayerGuildId(creature) ~= getPlayerGuildId(killer) then
                        doTeleportThing(creature, getTownTemplePosition(getPlayerTown(creature)), true)
                    end
                end
            else
                for index, creature in ipairs(getGranTowerPlayers()) do
                    if getPlayerStorageValue(creature, GRANTOWER.AURA) ~= -1 then
                        doTeleportThing(creature, getTownTemplePosition(getPlayerTown(creature)), true)
                    end            
                end
            end
           
            if (getPlayerGuildId(killer) >= 1) then
                setGlobalStorageValue(GRANTOWER.SAVEWINNERGUILDID, getPlayerGuildId(killer))
                for index, creature in ipairs(getGranTowerGuild(getPlayerGuildId(killer))) do
                    setPlayerStorageValue(creature, GRANTOWER.AURA, 1)
                end
            else
                setGlobalStorageValue(GRANTOWER.SAVEWINNERGUILDID, -1)
            end

                 setPlayerStorageValue(killer, GRANTOWER.AURA, 1)
                 addEvent(changeOutfit, 0, killer)
                 setGlobalStorageValue(GRANTOWER.SAVELASTWINNER, getCreatureName(killer))
                addEvent(doCreateMonster, 2 * 1000, "Gran Tower", GRANTOWER.TOWERPOSITION)
                 setGlobalStorageValue(GRANTOWER.FINALWINNER, getCreatureName(killer))
                 setGlobalStorageValue(GRANTOWER.DESTROYCOUNT, (getGlobalStorageValue(GRANTOWER.DESTROYCOUNT) + 1))

             if getPlayerGuildId(killer) >= 1 and getPlayerGuildName(killer) then
                doBroadcastMessage(""..getCreatureName(killer).." acaba de conquistar o Gran Castle em nome da guild ".. getPlayerGuildName(killer) ..". Todos membros da guild que estão online acabam de receber a Gran Aura!")
              else
                doBroadcastMessage(""..getCreatureName(killer).." acaba de conquistar o Gran Castle e absorver a Gran Aura!")
              end
    end
 end
 return true
end

function onTarget(cid, target)
 if isPlayer(cid) and isMonster(target) and (getCreatureName(target) == "Gran Tower") then
    if getGlobalStorageValue(GRANTOWER.FINALWINNER) == getCreatureName(cid) or getGlobalStorageValue(GRANTOWER.SAVEWINNERGUILDID) == getPlayerGuildId(cid) then
        doPlayerSendCancel(cid, "Você não pode atacar o Gran Tower, proteja ele!")
        return false
    end
 end
 return true
end

function onStatsChange(cid, attacker, type, combat, value)
 if (type == STATSCHANGE_HEALTHLOSS) and isMonster(cid) and isPlayer(attacker) and (getCreatureName(cid) == "Gran Tower") then
     if (getGlobalStorageValue(GRANTOWER.FINALWINNER) == getCreatureName(attacker)) then
      return false
     end
  end
 return true
end
 
Last edited by a moderator:
Solution
In addition to storing guild_id of winner as a global storage, you may want to loop through online list, check who is in the same guild ID and give them a player storage value.
Before looping through online list and adding player storage to those who are in the same guild, I would first run a query to delete all previously set player storages (For that particular key).

That way, you can see which guild killed the boss last by checking the global storage value, and you can which players were online at that time in that guild through their player storage value.
In addition to storing guild_id of winner as a global storage, you may want to loop through online list, check who is in the same guild ID and give them a player storage value.
Before looping through online list and adding player storage to those who are in the same guild, I would first run a query to delete all previously set player storages (For that particular key).

That way, you can see which guild killed the boss last by checking the global storage value, and you can which players were online at that time in that guild through their player storage value.
 
Solution
Back
Top