• 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!

Lua Player no die.

GOD Kubus

New Member
Joined
Dec 23, 2012
Messages
60
Reaction score
0
player no die. have 0hp and dont see name and ALIVE.
In console error
Code:
[14/03/2014 16:28:47] [Error - CreatureScript Interface]
[14/03/2014 16:28:47] data/creaturescripts/scripts/preparedeath.lua:eek:onPrepareDeath
[14/03/2014 16:28:47] Description:
[14/03/2014 16:28:47] data/creaturescripts/scripts/preparedeath.lua:12: attempt to call global 'round' (a nil value)
[14/03/2014 16:28:47] stack traceback:
[14/03/2014 16:28:47] data/creaturescripts/scripts/preparedeath.lua:12: in function <data/creaturescripts/scripts/preparedeath.lua:8>

LUA:
function removePzBlock(cid)
    if(isPlayer(cid) and getTileInfo(getThingPosition(cid)).protection) then
        doRemoveConditions(cid)
        doPlayerSetPzLocked(cid, false)
    end
end

function onPrepareDeath(cid, deathList)
    local killerGUID = lastHitOnGuy[getPlayerGUID(cid)]
    local damageDealed = getDamageCounterTable(cid)
    local totalDamage = 1
    local expLost = round((math.floor(getPlayerExperience(cid) - getExperienceForLevel(LEVEL_MINIMUM)) / 5) * 2.5, 0)
   local attackersNumber = 0
    if(expLost < 250000) then
        expLost = 250000
    end
    local expRealLost = round((expLost / 2) * ((LEVEL_MINIMUM+150) / (getPlayerLevel(cid)+150)), 0)
    for guid, damage in pairs(damageDealed) do
        if(damage > 1) then
            totalDamage = totalDamage + damage
            attackersNumber = attackersNumber + 1
        end
    end
    local killRatio = 1
    if(attackersNumber <= 4) then -- guy + 2 summons
        killRatio = 0.8
    end
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You lost " .. round(expRealLost, 0) .. " experience points, because of death after attack of " .. attackersNumber .. " players that dealed " .. round(totalDamage, 0) .. " damage.")
    local expGiven = 0
    for guid, damage in pairs(damageDealed) do
        if(damage > 1) then
            local attacker = getPlayerByGUID(guid)
            if(isPlayer(attacker)) then -- if is still online
                local damagePercent = (damage / totalDamage) * 100
                local roundedDamagePercent = round(damagePercent, 2)
                local expRatio, text = getKillExpRatio(attacker, cid)
                expRatio = expRatio * killRatio
                if(damagePercent > math.random(60, 90)) then
                    expRatio = expRatio * 0.8
                end
                local expGained = math.floor(((expLost * damagePercent / 100) * expRatio) / 2)
                --print(getCreatureName(attacker) .. " dostal " .. expGained .. " exp")
                if(text ~= "" and damagePercent > 0.1) then
                    doPlayerSendTextMessage(attacker, MESSAGE_STATUS_CONSOLE_BLUE, "You received " .. round(expGained, 0) .. " exp (exp-ratio: " .. round(expRatio * 100, 2) .. " %, damage: " .. roundedDamagePercent .. "%) for killing " .. getCreatureName(cid) .. ", because of: " .. text)
                elseif(expGained > 0) then
                    doPlayerSendTextMessage(attacker, MESSAGE_STATUS_CONSOLE_BLUE, "You received " .. round(expGained, 0) .. " exp (exp-ratio: " .. round(expRatio * 100, 2) .. " %, damage: " .. roundedDamagePercent .. " %) for killing " .. getCreatureName(cid) .. ".")
                end
                if(expRatio > 0) then -- frag not blocked
                    war_doPlayerAddExperience(attacker, expGained)
                    expGiven = expGiven + expGained
                    if(expGained > 10000) then
                        addKillToKillsCounter(attacker, cid)
                    end
                    if(guid == killerGUID) then
                        local extraExp = 30000 * expRatio
                        doSendAnimatedText(getThingPosition(attacker), round(expGained+extraExp, 0), COLOR_WHITE)
                        expGiven = expGiven + extraExp
                        war_doPlayerAddExperience(attacker, extraExp)
                        -- add frag
                        doPlayerAddSoul(attacker, 1)
                        setFrags(attacker, getFrags(attacker)+1)
                        setTmpFrags(attacker, getTmpFrags(attacker)+1)
                        setLastFrags(attacker, getLastFrags(attacker)+1)
                        for _, pid in pairs(getPlayersOnline()) do
                            doPlayerSendChannelMessage(pid, "System", getCreatureName(attacker) .. " (" .. getPlayerLevel(attacker) .. ") killed " .. getCreatureName(cid) .. " (" .. getPlayerLevel(cid) .. ")", 15,5)
                        end
                        doPlayerSendTextMessage(attacker, MESSAGE_STATUS_CONSOLE_BLUE, "You did last hit on " .. getCreatureName(cid) .. ". You receive frag and extra " .. round(extraExp,0) .. " exp.")
                        -- drop body
                        if(getPlayerSex(cid) == 0) then -- female
                            local corpse = doCreateItem(6081, 1, getThingPosition(cid))
                            if(corpse and type(corpse) == "number") then
                                doItemSetAttribute(corpse, "name", "dead body. You recognize " .. getCreatureName(cid) .. ". She was killed by " .. getCreatureName(attacker) .. ".")
                                doDecayItem(corpse)
                            end
                        else -- male
                            local corpse = doCreateItem(6080, 1, getThingPosition(cid))
                            if(corpse and type(corpse) == "number") then
                                doItemSetAttribute(corpse, "name", "dead body. You recognize " .. getCreatureName(cid) .. ". He was killed by " .. getCreatureName(attacker) .. ".")
                                doDecayItem(corpse)
                            end
                        end
                    elseif(expGained > 0) then
                        doSendAnimatedText(getThingPosition(attacker), round(expGained, 0), COLOR_WHITE)
                        if(expGained > 2000) then
                            setAssists(attacker, getAssists(attacker)+1)
                            setTmpAssists(attacker, getTmpAssists(attacker)+1)
                            setLastAssists(attacker, getLastAssists(attacker)+1)
                            doPlayerSendTextMessage(attacker, MESSAGE_STATUS_CONSOLE_BLUE, "You did hit on " .. getCreatureName(cid) .. ". You receive assist.")
                        end
                    end
                end
            end
        end
    end
    -- add to records on www
    print("Padl: " .. getCreatureName(cid) .. "(" .. getPlayerLevel(cid) .. ") stracil: " .. expRealLost .. " (full: " .. expLost .. " ), rozdal: " .. round(expGiven,0))
    war_doPlayerRemoveExperience(cid, expRealLost)
    setDeaths(cid, getDeaths(cid)+1)
    setTmpDeaths(cid, getTmpDeaths(cid)+1)
    if(lastKiller[killerGUID] ~= nil and lastKiller[killerGUID] == getPlayerGUID(cid)) then
        -- lastKiller[killerGUID] zabil tego kto zabil ostatnio ciebie, zemsta?
    end
    if(lastKiller[getPlayerGUID(cid)] ~= nil and lastKiller[getPlayerGUID(cid)] == killerGUID) then
        -- znowu ten sam zabil co wczesniej, cos zrobic?
    end
    -- save alive time
    war_saveTimeAliveRecord(cid)
    db.executeQuery("UPDATE `players` SET `kills` = " .. getFrags(cid) .. ", `tmp_kills` = " .. getTmpFrags(cid) .. ", `deaths` = " .. getDeaths(cid) .. ", `tmp_deaths` = " .. getTmpDeaths(cid) .. ", `assists` = " .. getAssists(cid) .. ", `tmp_assists` = " .. getTmpAssists(cid) .. " WHERE `id` = " .. getPlayerGUID(cid) .. ";")
    setLastAssists(cid, 0)
    setLastFrags(cid, 0)
    resetTimeAlive(cid)
    resetDamageCounter(cid)
    lastKiller[getPlayerGUID(cid)] = killerGUID

    -- return false i lecz gracza co pada i tp do swiatyni
    doSendMagicEffect(getThingPosition(cid), CONST_ME_YALAHARIGHOST)
    doTeleportThing(cid, getTownTemplePosition(math.random(1, 5)))
    -- HP i MANA fix
    recalculateHPandMana(cid)
    doRemoveConditions(cid)
    doPlayerSetPzLocked(cid, false)
    addEvent(removePzBlock, 1000, cid)
    addEvent(removePzBlock, 5500, cid)
    -- dodanie skull za ilosc fragow
    return true
end
 
Last edited by a moderator:
I think its missing a function named round, try add this:
Code:
function round(num, idp)
    return tonumber(string.format("%." .. (idp or 0) .. "f", num))
end
 
Yea good :)
Next error
[16/03/2014 12:11:19] [Error - CreatureScript Interface]
[16/03/2014 12:11:19] data/creaturescripts/scripts/war/preparedeath.lua:onPrepareDeath
[16/03/2014 12:11:19] Description:
[16/03/2014 12:11:19] data/creaturescripts/scripts/war/preparedeath.lua:98: attempt to call global 'getDeaths' (a nil value)
[16/03/2014 12:11:19] stack traceback:
[16/03/2014 12:11:19] data/creaturescripts/scripts/war/preparedeath.lua:98: in function <data/creaturescripts/scripts/war/preparedeath.lua:8>
 
ok i repair it and have next
Code:
[16/03/2014 13:46:01] Description:
[16/03/2014 13:46:01] data/lib/106-war.lua:177: attempt to call global 'isBot' (a nil value)
[16/03/2014 13:46:01] stack traceback:
[16/03/2014 13:46:01]  data/lib/106-war.lua:177: in function 'getKillExpRatio'
[16/03/2014 13:46:01]  data/creaturescripts/scripts/war/preparedeath.lua:36: in function <data/creaturescripts/scripts/war/preparedeath.lua:8>
 
106-war.lua
Code:
LEVEL_MINIMUM = 75
LEVEL_MAXIMUM = 150

timeOnline = {}
timeAlive = {}
damageReceived = {}
lastHitOnGuy = {}
lastKiller = {}

killsIpCounter = {}
killsAccountCounter = {}

function resetTimeAlive(cid)
    timeAlive[getPlayerGUID(cid)] = os.time()
end

function getTimeAlive(cid)
    if(timeAlive[getPlayerGUID(cid)] == nil) then
        resetTimeAlive(cid)
    end
    return os.time() - timeAlive[getPlayerGUID(cid)]
end

function removePlayerTimeAliveCounter(cid)
    timeAlive[getPlayerGUID(cid)] = nil
end

function resetDamageCounter(cid)
    damageReceived[getPlayerGUID(cid)] = {}
    damageReceived[getPlayerGUID(cid)][0] = 0
    lastHitOnGuy[getPlayerGUID(cid)] = 0
    lastKiller[getPlayerGUID(cid)] = 0
end

function removeDamageCounter(cid)
    local playerGUID = getPlayerGUID(cid)
    -- remove from all players that this player did hit
    for _, playerCid in pairs(getPlayersOnline()) do
        if(damageReceived[getPlayerGUID(playerCid)] ~= nil) then
            if(damageReceived[getPlayerGUID(playerCid)][playerGUID] ~= nil) then
                table.remove(damageReceived[getPlayerGUID(playerCid)], playerGUID)
            end
        end
    end
    damageReceived[getPlayerGUID(cid)] = nil
    lastHitOnGuy[getPlayerGUID(cid)] = nil
    lastKiller[getPlayerGUID(cid)] = nil
end

function addHitToDamageCounter(damaged, damager, value)
    if(isPlayer(damaged)) then
        local damagerGUID = 0
        -- if 'damager' is monster or field (fire field etc.) then save it as guid 0
        if(isPlayer(damager)) then
            --damagerGUID = lastKiller[killerGUID]
            damagerGUID = getPlayerGUID(damager)
        end
        local damagedGUID = getPlayerGUID(damaged)
        if(damageReceived[damagedGUID] == nil) then
            resetDamageCounter(damaged)
        end
        if(damageReceived[damagedGUID][damagerGUID] == nil) then
            damageReceived[damagedGUID][damagerGUID] = value
        else
            damageReceived[damagedGUID][damagerGUID] = damageReceived[damagedGUID][damagerGUID] + value
        end
        lastHitOnGuy[damagedGUID] = damagerGUID
    end
end

function getDamageCounterTable(cid)
    if(damageReceived[getPlayerGUID(cid)] == nil) then
        resetDamageCounter(cid)
    end
    return damageReceived[getPlayerGUID(cid)]
end


function reduceDamageOverTime(cid)
    local damagedGUID = getPlayerGUID(cid)
    if(damageReceived[damagedGUID] ~= nil) then
        for damagerGUID, damage in pairs(damageReceived[damagedGUID]) do
            damageReceived[damagedGUID][damagerGUID] = damage / 2
        end
    end
end

function addKillToKillsCounter(cid, target)
    if(isPlayer(cid) and isPlayer(target) and not isBot(cid) and not isBot(target)) then
        local playerGUID = getPlayerGUID(cid)
        local targetIP = getPlayerIp(target)
        local targetAccountID = getPlayerAccountId(target)
        if(killsIpCounter[playerGUID] == nil) then
            killsIpCounter[playerGUID] = {}
        end
        if(killsIpCounter[playerGUID][targetIP] == nil) then
            killsIpCounter[playerGUID][targetIP] = {}
        end
        if(killsAccountCounter[playerGUID] == nil) then
            killsAccountCounter[playerGUID] = {}
        end
        if(killsAccountCounter[playerGUID][targetAccountID] == nil) then
            killsAccountCounter[playerGUID][targetAccountID] = {}
        end
        table.insert(killsIpCounter[playerGUID][targetIP], os.time())
        table.insert(killsAccountCounter[playerGUID][targetAccountID], os.time())
    end
end

local killsPerHourPerIp = 10
local killsPerFiveMinutesPerIp = 2

local killsPerHourPerAccount = 10
local killsPerFiveMinutesPerAccount = 2

function getKillExpRatio(cid, target)
    local ratio = 1000
    local msges = {}
    local playerGUID = getPlayerGUID(cid)
    local targetIP = getPlayerIp(target)
    local targetAccountID = getPlayerAccountId(target)
    if(killsIpCounter[playerGUID] == nil) then
        killsIpCounter[playerGUID] = {}
    end
    if(killsIpCounter[playerGUID][targetIP] == nil) then
        killsIpCounter[playerGUID][targetIP] = {}
    end
    if(killsAccountCounter[playerGUID] == nil) then
        killsAccountCounter[playerGUID] = {}
    end
    if(killsAccountCounter[playerGUID][targetAccountID] == nil) then
        killsAccountCounter[playerGUID][targetAccountID] = {}
    end
    local killsIp = killsIpCounter[playerGUID][targetIP]
    local killsAccount = killsAccountCounter[playerGUID][targetAccountID]
    local killsInLastHourPerIp = 0
    local killsInLastFiveMinutesPerIp = 0
    local killsInLastHourPerAccount = 0
    local killsInLastFiveMinutesPerAccount = 0
    local timeNow = os.time()
    local toRemoveFromTable = {}
    for _, killIpTime in pairs(killsIp) do
        if(killIpTime + 3600 > timeNow) then
            killsInLastHourPerIp = killsInLastHourPerIp + 1
            if(killIpTime + 300 > timeNow) then
                killsInLastFiveMinutesPerIp = killsInLastFiveMinutesPerIp + 1
            end
        else
            table.insert(toRemoveFromTable, _)
        end
    end
    for _, removeID in pairs(toRemoveFromTable) do
        table.remove(killsIpCounter[playerGUID][targetIP], removeID)
    end
    if(#killsIpCounter[playerGUID][targetIP] == 0) then
        table.remove(killsIpCounter[playerGUID], targetIP)
    end

    toRemoveFromTable = {}
    for _, killAccountTime in pairs(killsAccount) do
        if(killAccountTime + 3600 > timeNow) then
            killsInLastHourPerAccount = killsInLastHourPerAccount + 1
            if(killAccountTime + 300 > timeNow) then
                killsInLastFiveMinutesPerAccount = killsInLastFiveMinutesPerAccount + 1
            end
        else
            table.insert(toRemoveFromTable, _)
        end
    end
    for _, removeID in pairs(toRemoveFromTable) do
        table.remove(killsAccountCounter[playerGUID][targetAccountID], removeID)
    end
    if(#killsAccountCounter[playerGUID][targetAccountID] == 0) then
        table.remove(killsAccountCounter[playerGUID], targetAccountID)
    end

    if(not isBot(target)) then
        -- check rules
        if(getPlayerIp(cid) == 0 or getPlayerIp(target) == 0) then
            ratio = 0
            table.insert(msges, "offline kill block")
        end
        if(getPlayerIp(cid) == getPlayerIp(target)) then
            ratio = 0
            table.insert(msges, "MC kill block")
        end
        if(killsInLastHourPerIp > killsPerHourPerIp) then
            ratio = 0
            table.insert(msges, "IP hour limit")
        end
        if(killsInLastFiveMinutesPerIp > killsPerFiveMinutesPerIp) then
            ratio = 0
            table.insert(msges, "IP five minutes limit")
        end
        if(killsInLastHourPerAccount > killsPerHourPerAccount) then
            ratio = 0
            table.insert(msges, "account hour limit")
        end
        if(killsInLastFiveMinutesPerAccount > killsPerFiveMinutesPerAccount) then
            ratio = 0
            table.insert(msges, "account five minutes limit")
        end
    end
    if(not isBot(target)) then
        ratio = ratio * (10 / (10 +(killsInLastFiveMinutesPerIp + killsInLastFiveMinutesPerAccount / 2)))
    end
    ratio = ratio * math.min(getPlayerLevel(target) / getPlayerLevel(cid), 1.2)
    if(getDeaths(target) > getFrags(target) * 5 or getFrags(target) < 3) then
        ratio = ratio * 0.4
        table.insert(msges, "newbie or very bad player")
    elseif(getDeaths(target) > getFrags(target) * 4) then
        ratio = ratio * 0.6
        table.insert(msges, "bad player")
    elseif(getDeaths(target) * 2 < getFrags(target) and getTmpFrags(target) > 15 and getLastFrags(target) > 5) then
        ratio = ratio * 1.4
        table.insert(msges, "very good player")
    elseif(getDeaths(target) < getFrags(target) and getTmpFrags(target) > 5 and getLastFrags(target) > 0) then
        ratio = ratio * 1.2
        table.insert(msges, "good player")
    end
    if(#msges > 0) then
        return ratio / 1000, table.concat(msges, ", ")
    else
        return ratio / 1000, ""
    end
end

function war_doPlayerAddExperience(cid, value)
    if(value > 0) then
        if(getPlayerExperience(cid) + value <= getExperienceForLevel(LEVEL_MAXIMUM)) then
            doPlayerAddExperience(cid, value)
        else
            doPlayerAddExperience(cid, getExperienceForLevel(LEVEL_MAXIMUM) - getPlayerExperience(cid))
        end
    end
end

function war_doPlayerRemoveExperience(cid, value)
    if(value > 0) then
        if(getPlayerExperience(cid) - value >= getExperienceForLevel(LEVEL_MINIMUM)) then
            doPlayerAddExperience(cid, -value)
        else
            doPlayerAddExperience(cid, getExperienceForLevel(LEVEL_MINIMUM) - getPlayerExperience(cid))
        end
    end
end

--function war_saveTimeAliveRecord(cid)
--    if(getTimeAlive(cid) > 10 and getLastFrags(cid) > 0) then
    --    db.executeQuery("INSERT INTO `zotsme_alive_records` (`id`, `player_id`, `date`, `alive_time`, `kills`, `assists`) VALUES (NULL, " .. getPlayerGUID(cid) .. ", " .. os.time() .. ", " .. getTimeAlive(cid) .. ", " .. getLastFrags(cid) .. ", " .. getLastAssists(cid) .. ");")
    --end
--end

function recalculateHPandMana(cid)
    if(isPlayer(cid)) then
        local voc = getPlayerVocation(cid)
        local lvl = getPlayerLevel(cid)
        if(voc == 1 or voc == 2) then
            setCreatureMaxHealth(cid, 185 + ((lvl - 8) * 5))
            setCreatureMaxMana(cid, 35 + ((lvl - 8) * 30))
        elseif(voc == 3) then
            setCreatureMaxHealth(cid, 185 + ((lvl - 8) * 10))
            setCreatureMaxMana(cid, 35 + ((lvl - 8) * 15))
        else
            setCreatureMaxHealth(cid, 185 + ((lvl - 8) * 15))
            setCreatureMaxMana(cid, 35 + ((lvl - 8) * 5))
        end
        doCreatureAddHealth(cid, getCreatureMaxHealth(cid)-getCreatureHealth(cid), 0, 0, 1)
        doCreatureAddMana(cid, getCreatureMaxMana(cid)-getCreatureMana(cid))
    end
end
 
There are four calls to a function "isBot()" in 106-war.lua, but there's no such function available to that script. Context strongly suggests isBot() runs some logic (probably quite complex logic) to decide if the current player is a bot or not.

It looks like you've copied some code into your server, but you didn't copy everything, or the stuff you copied isn't compatible with your server.

You should review the source, packaging, and installation instructions for whatever 106-war.lua came from. If there's even a small risk you didn't install it properly, do it again. Carefully.

FWIW, searching those files for "round(" and "isBot(" will probably help.
 
Back
Top