• 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 creaturescript debug

CforMe

C how it works
Joined
Nov 26, 2015
Messages
16
Reaction score
1
I have made about 100 scripts like this and for some reason cannot figure out why this script is debugging my server. Here is the code can someone help me please?

Code:
local monster_name = "monstrosity"
local pos = {x = 2000, y = 2000, z = 7}

function onKill(cid, target)
if getCreatureName(target) == monster_name then
    doPlayerSetVocation(cid, 1)
    doTeleportThing(cid, pos)
    doPlayerSetTown(cid, 2)
    doRemoveCreature(cid, true)
    doPlayerSetLevel(cid, 1)
    doPlayerSetHealth(cid, 100)
    doPlayerSetHealthMax(cid, 100)
    doPlayerSetMana(cid, 30)
    doPlayerSetManaMax(cid, 30)
end
return true
end

function doPlayerSetLevel(cid, level)
local query = db.executeQuery("UPDATE `players` SET `level` = '"..level.."' WHERE `id` ='"..getPlayerAccountId(cid).."'")
return query
end

function doPlayerSetHealth(cid, health)
local query = db.executeQuery("UPDATE `players` SET `health` = '"..health.."' WHERE `id` ='"..getPlayerAccountId(cid).."'")
return query
end

function doPlayerSetHealthMax(cid, healthMax)
local query = db.executeQuery("UPDATE `players` SET `healthmax` = '"..healthMax.."' WHERE `id` ='"..getPlayerAccountId(cid).."'")
return query
end

function doPlayerSetMana(cid, mana)
local query = db.executeQuery("UPDATE `players` SET `mana` = '"..mana.."' WHERE `id` ='"..getPlayerAccountId(cid).."'")
return query
end

function doPlayerSetManaMax(cid, manaMax)
local query = db.executeQuery("UPDATE `players` SET `manamax` = '"..manaMax.."' WHERE `id` ='"..getPlayerAccountId(cid).."'")
return query
end
 
Simplified but not tested
Code:
    local monster_name = "monstrosity" -- this can be upper or lowercase, doesn't matter
    local pos = {x = 2000, y = 2000, z = 7}
    local playerId = 0

    -- you could do just 1 query for everything, but we will just use this for now
    function doUpdatePlayer(health, mana, level, playerId)
        db.executeQuery("UPDATE `players` SET `level` = "..level..", `health` = "..health..", `healthmax` = "..health..", `mana` = "..mana..", `manamax` = "..mana.." WHERE `id` ="..playerId..";")
    end

    function onKill(cid, target)
        -- just incase you change the creatures name it will compare them both as lowercase
        if getCreatureName(target):lower() == monster_name:lower() then
        
            doPlayerSetVocation(cid, 1)
            doPlayerSetTown(cid, 2)
            doTeleportThing(cid, pos)
            -- playerId should still exist even after the player logs out
            playerId = getPlayerAccountId(cid)
        
            doRemoveCreature(cid, true)
            -- now that the player is offline we can update the database,
            -- we need to call this after the player is offline
            -- otherwise it will save its old values of when it was online
            doUpdatePlayer(100, 30, 1, playerId)
        end
        return true
    end
 
Back
Top