• 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 bless book

Lbtg

Intermediate OT User
Joined
Nov 22, 2008
Messages
2,312
Reaction score
134
Hello , can someone please help me fix this script it seems sometimes player might loss items/all exp like they didint had bless.

blessbook.lua
Code:
local cfg = {
   bless = { 1, 2, 3, 4, 5 }
}
function onUse(cid, item, fromPosition, itemEx, toPosition)

     for i = 1, table.maxn(cfg.bless) do
         if(getPlayerBlessing(cid, cfg.bless[i])) then
             doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
             doPlayerSendCancel(cid, "You have already recieved Blessings!")
             return true
         end
     end
     doPlayerAddBlessing(cid, cfg.bless[1])
     doPlayerAddBlessing(cid, cfg.bless[2])
     doPlayerAddBlessing(cid, cfg.bless[3])
     doPlayerAddBlessing(cid, cfg.bless[4])
     doPlayerAddBlessing(cid, cfg.bless[5])
     doSendMagicEffect(getCreaturePosition(cid), CONST_ME_HOLYAREA)
     doSendAnimatedText(getCreaturePosition(cid), "BLESSED!", TEXTCOLOR_RED)
     doPlayerSendTextMessage(cid, 21, "You have recieved blessings by Book Of Spirits!")
     doRemoveItem(item.uid, 1)
     return true
end

and if script is good maybe its this script

timebleee.lua
Code:
function onUse(cid)

    if getGlobalStorageValue(6005) < os.time() then
        setGlobalStorageValue(6005, os.time() + 1800)
        for i = 1,5 do
            doPlayerAddBlessing(cid, i)
        end
        doPlayerSendTextMessage(cid, 27, "You Have Been Blessed By Warfare City")
        doSendMagicEffect(getThingPos(cid), 12)
    else
        doPlayerSendCancel(cid, "It is Too Soon to click it.")
        doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
    end
    return true
end

if player clicks blessbook he gets bless and so , but if he clicks timebless he gets it to maybe its like 1x1 ad getting 0.. +-

Thanks in advance
 
100% guaranteed it's some shitty script you added for aol or something along those lines.
Something is running before your playerdeath.lua, which is forcing incorrect behaviour.

Go look through your creaturescripts, and find the issue.
 
1 death script
Code:
function onDeath(cid)

doSendMagicEffect(getPlayerPosition(cid), CONST_ME_YALAHARIGHOST)
return true
end

2 death script
Code:
local config = {
    affected = 1, -- how many players (deathAssits) from table deathList should this script be executed for?
 
    killStorageValue = 3943,
    deathStorageValue = 3944,
 
    -- commands for the texts (those inside of ||, example: |KILLS| to show skills): KILLS, KILLERNAME, TARGETNAME
    rewardItem = {
        use = true,
        itemid = 5943,
        minLevel = false, -- false if you don't want any level req
        minLevelDiff = false, -- false if you don't want any level diff req (negative numbers allowed).
        text = "This is a gift to |KILLERNAME| [|KILLERLEVEL|] for killing |TARGETNAME| [|TARGETLEVEL|]"
    },
 
    killMessage = {
        use = false,
        text = "You owned |TARGETNAME|! You have now |KILLERKILLS| kills!",
        messageClass = MESSAGE_STATUS_CONSOLE_BLUE
    },
 
    broadcastMessage = {
        use = true,
        minLevel = false, -- false if you don't want any level req
        minLevelDiff = false, -- false if you don't want any level diff req (negative numbers allowed).
        text = "|KILLERNAME| [|KILLERLEVEL|] just killed |TARGETNAME| [|TARGETLEVEL|]!",
        messageClass = MESSAGE_STATUS_WARNING
    },
 
    killerAnimation = {
        use = true,
        text = "Frag!", -- Only 9 letters! No "commands" here.
        color = 215
    },
 
    targetAnimation = {
        use = true,
        text = "Owned!", -- Only 9 letters! No "commands" here.
        color = 215
    }
}
 
function onDeath(cid, corpse, deathList)
    for i = 1, math.min(config.affected, getConfigInfo('deathAssistCount')) do
        local killer = deathList[i]
        if(isPlayer(killer) == TRUE) then
            local targetKills = math.max(0, getPlayerStorageValue(cid, config.killStorageValue)) + 1
            local targetDeaths = math.max(0, getPlayerStorageValue(cid, config.deathStorageValue)) + 1
 
            local killerKills = math.max(0, getPlayerStorageValue(killer, config.killStorageValue)) + 1
            local killerDeaths = math.max(0, getPlayerStorageValue(killer, config.deathStorageValue)) + 1
 
            setPlayerStorageValue(killer, config.killStorageValue, targetKills)
            setPlayerStorageValue(cid, config.deathStorageValue, targetDeaths)
 
            local killerLevel = getPlayerLevel(killer)
            local targetLevel = getPlayerLevel(cid)
            local levelDiff = targetLevel - killerLevel
 
            local values = {
                ["KILLERKILLS"] = killerKills,
                ["KILLERDEATHS"] = killerDeaths,
                ["KILLERNAME"] = getCreatureName(killer),
                ["KILLERLEVEL"] = killerLevel,
 
                ["TARGETKILLS"] = targetKills,
                ["TARGETDEATHS"] = targetDeaths,
                ["TARGETNAME"] = getCreatureName(cid),
                ["TARGETLEVEL"] = targetLevel
            }
 
            function formateString(str)
                return(str:gsub("|([A-Z]+)|", (function(a) return values[a] end)))
            end
 
            if(config.rewardItem.use and (not config.rewardItem.minLevel or targetLevel >= config.rewardItem.minLevel) and (not config.rewardItem.minLevelDiff or levelDiff >= config.rewardItem.minLevelDiff)) then
                local uid = doPlayerAddItem(killer, config.rewardItem.itemid, 1)
             doItemSetAttribute(uid, "description", formateString(config.rewardItem.text))
            end
            if(config.killMessage.use) then
                doPlayerSendTextMessage(killer, config.killMessage.messageClass, formateString(config.killMessage.text))
            end
            if(config.broadcastMessage.use and (not config.broadcastMessage.minLevel or getPlayerLevel(cid) >= config.broadcastMessage.minLevel) and (not config.broadcastMessage.minLevelDiff or levelDiff >= config.broadcastMessage.minLevelDiff)) then
                broadcastMessage(formateString(config.broadcastMessage.text), config.broadcastMessage.messageClass)
            end
            if(config.killerAnimation.use) then
                doSendAnimatedText(getCreaturePosition(killer), config.killerAnimation.text, config.killerAnimation.color)
            end
            if(config.targetAnimation.use) then
                doSendAnimatedText(getCreaturePosition(cid), config.targetAnimation.text, config.targetAnimation.color)
            end
        end
    end
 
    return true
end

playerdeath.lua
Code:
local config = {
    deathListEnabled = getBooleanFromString(getConfigInfo('deathListEnabled')),
    sqlType = getConfigInfo('sqlType'),
    maxDeathRecords = getConfigInfo('maxDeathRecords')
}

config.sqlType = config.sqlType == "sqlite" and DATABASE_ENGINE_SQLITE or DATABASE_ENGINE_MYSQL

function onDeath(cid, corpse, lastHitKiller, mostDamageKiller)
    if(config.deathListEnabled ~= TRUE) then
        return
    end

    local hitKillerName = "field item"
    local damageKillerName = ""
    if(lastHitKiller ~= FALSE) then
        if(isPlayer(lastHitKiller) == TRUE) then
            hitKillerName = getPlayerGUID(lastHitKiller)
        else
            hitKillerName = getCreatureName(lastHitKiller)
        end

        if(mostDamageKiller ~= FALSE and mostDamageKiller ~= lastHitKiller and getCreatureName(mostDamageKiller) ~= getCreatureName(lastHitKiller)) then
            if(isPlayer(mostDamageKiller) == TRUE) then
                damageKillerName = getPlayerGUID(mostDamageKiller)
            else
                damageKillerName = getCreatureName(mostDamageKiller)
            end
        end
    end

    db.executeQuery("INSERT INTO `player_deaths` (`player_id`, `time`, `level`, `killed_by`, `altkilled_by`) VALUES (" .. getPlayerGUID(cid) .. ", " .. os.time() .. ", " .. getPlayerLevel(cid) .. ", " .. db.escapeString(hitKillerName) .. ", " .. db.escapeString(damageKillerName) .. ");")
    local rows = db.getResult("SELECT `player_id` FROM `player_deaths` WHERE `player_id` = " .. getPlayerGUID(cid) .. ";")
    if(rows:getID() ~= -1) then
        local amount = rows:getRows(true) - config.maxDeathRecords
        if(amount > 0) then
            if(config.sqlType == DATABASE_ENGINE_SQLITE) then
                for i = 1, amount do
                    db.executeQuery("DELETE FROM `player_deaths` WHERE `rowid` = (SELECT `rowid` FROM `player_deaths` WHERE `player_id` = " .. getPlayerGUID(cid) .. " ORDER BY `time` LIMIT 1);")
                end
            else
                db.executeQuery("DELETE FROM `player_deaths` WHERE `player_id` = " .. getPlayerGUID(cid) .. " ORDER BY `time` LIMIT " .. amount .. ";")
            end
        end
    end
end
local config = {
    deathListEnabled = getBooleanFromString(getConfigInfo('deathListEnabled')),
    sqlType = getConfigInfo('sqlType'),
    maxDeathRecords = getConfigInfo('maxDeathRecords')
}
 
config.sqlType = config.sqlType == "sqlite" and DATABASE_ENGINE_SQLITE or DATABASE_ENGINE_MYSQL
 
function onDeath(cid, corpse, lastHitKiller, mostDamageKiller)
    if(config.deathListEnabled ~= TRUE) then
        return
    end
 
    local hitKillerName = "field item"
    local damageKillerName = ""
    if(lastHitKiller ~= FALSE) then
        if(isPlayer(lastHitKiller) == TRUE) then
            hitKillerName = getPlayerGUID(lastHitKiller)
        else
            hitKillerName = getCreatureName(lastHitKiller)
        end
 
        if(mostDamageKiller ~= FALSE and mostDamageKiller ~= lastHitKiller and getCreatureName(mostDamageKiller) ~= getCreatureName(lastHitKiller)) then
            if(isPlayer(mostDamageKiller) == TRUE) then
                damageKillerName = getPlayerGUID(mostDamageKiller)
            else
                damageKillerName = getCreatureName(mostDamageKiller)
            end
        end
    end
 
    db.query("INSERT INTO `player_deaths` (`player_id`, `time`, `level`, `killed_by`, `altkilled_by`) VALUES (" .. getPlayerGUID(cid) .. ", " .. os.time() .. ", " .. getPlayerLevel(cid) .. ", " .. db.escapeString(hitKillerName) .. ", " .. db.escapeString(damageKillerName) .. ");")
    local rows = db.getResult("SELECT `player_id` FROM `player_deaths` WHERE `player_id` = " .. getPlayerGUID(cid) .. ";")
    if(rows:getID() ~= -1) then
        local amount = rows:getRows(true) - config.maxDeathRecords
        if(amount > 0) then
            if(config.sqlType == DATABASE_ENGINE_SQLITE) then
                for i = 1, amount do
                    db.executeQuery("DELETE FROM `player_deaths` WHERE `rowid` = (SELECT `rowid` FROM `player_deaths` WHERE `player_id` = " .. getPlayerGUID(cid) .. " ORDER BY `time` LIMIT 1);")
                end
            else
                db.executeQuery("DELETE FROM `player_deaths` WHERE `player_id` = " .. getPlayerGUID(cid) .. " ORDER BY `time` LIMIT " .. amount .. ";")
            end
        end
    end
end

another death script
Code:
local names = {'earth stone', 'icy stone', 'fire stone', 'wind stone'}
local rewards = {{2157, 3}, {2141, 1}, {6512, 1}, {2829, 1}, {12602, 3}}


function onDeath(cid, corpse, deathList)
    if (isInArray(names, getCreatureName(cid):lower())) then
        --local mostdmg = deathList[2] ~= nil and deathList[2] or deathList[1]
        local mostdmg = isPlayer(deathList[1]) and deathList[1] or (deathList[2] ~= nil and deathList[2])
        if isPlayer(mostdmg) then
            local rand = math.random(1, #rewards)
        
            doPlayerAddItem(mostdmg, rewards[rand][1], rewards[rand][2])
            doPlayerSendTextMessage(mostdmg, 22, "You have killed " .. getCreatureName(cid) .. ". You won " .. rewards[rand][2] .. " " .. getItemNameById(rewards[rand][1]) .. ".")
            db.executeQuery("INSERT INTO metin_wins (name, reward, reward_id, stone, date) VALUES ('" .. getCreatureName(mostdmg) .. "', '" .. getItemNameById(rewards[rand][1]) .. "', '" .. rewards[rand][1] .. "', '" .. getCreatureName(cid) .. "', " .. os.time() .. ")")
        
        else
            doBroadcastMessage("No one has destroyed the stone")
        end
    end
    return TRUE
end

i got like 15 scripts exact same , just ofc no same location or mob or line in xml
Code:
function onDeath(cid, corpse, deathList)
    if getCreatureName(cid):lower() == "morkarian" then
        for i = 1, #deathList do
            if isPlayer(deathList[i]) then
                doCreatureSay(deathList[i], "Morkarian dead you been teleported to reward room GRATZZZ!", 22, nil, nil, {x=1291, y=1241, z=11})
                doSendMagicEffect(getCreaturePosition(deathList[i]), CONST_ME_TELEPORT)
                for _, pid in pairs(deathList) do
                    doTeleportThing(pid, {x=1291, y=1241, z=11}, false)
                end
                doSendMagicEffect({x=1291, y=1241, z=11}, CONST_ME_TELEPORT)
                break
            end
        end
    end
    return true
end

i have no idea why its happening like that , can't understand :(

thanks in advance :)
 
try not copy/pasting everything and learn
brother im heading and trying for it .i can promise , but please understand not everyone same , prograaming goes very hard for me as PC. i dont like pc, i rather run to nature. but the thing i waste my time/money / health on this is to make a great coomunity with nice people and great servers. what i still do and have on my servers is feathers what i planning if evrything goes good, i learn programing, study. but as i mention programing goes hard for me...+ i have memory problems i forget quit fast, but its not for long anymore as i fixing my health :)

Honest reply as always...
 
and i ditnt not just copy paste , i tryed checking them reading but my eyes cant see what yours sees etc.
 
Unfortunately it comes down to trial and error at this point.
Until you can narrow down the cause of the issue, we are just blindly guessing.

By the way.. does last two scripts even work?
I thought monsters didn't activate "onDeath" scripts?
-shrugs- must've changed in 1.x+ servers.

edit -

If they do work.. you should add a check to ensure cid is a monster and not a player.. or your players might find that most excellent cheese you have scripted there.
 
Unfortunately it comes down to trial and error at this point.
Until you can narrow down the cause of the issue, we are just blindly guessing.


If they do work.. you should add a check to ensure cid is a monster and not a player.. or your players might find that most excellent cheese you have scripted there.
can you please more explain please i use translater alot times xd :)
 
Back
Top