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

setCreatureMaxMana on Voc ID?

Nevalopo

Demigod
Joined
Jul 21, 2008
Messages
5,165
Reaction score
68
Location
Sweden, Landskrona
Hi! Im really bad at lua can someone explain to me why this doesn't work? I want to set 0 mana to everyone with vocation id 9 when they login. If possible with a storage id so it doesnt get spammed every time. Here is what i got (tfs 0.4)

Code:
function onLogin(cid)

        if getPlayerVocation(cid) == 9 then
            setCreatureMaxMana(cid, 0)
            end
end
 
Code:
local voc = {
    id = 9, -- change this to the id
    storage = 1000 -- change this to whatever storage you want to use
}
function onLogin(cid)
    if getPlayerStorageValue(cid, voc.storage) ~= 1 and getPlayerVocation(cid) == voc.id then
        setPlayerStorageValue(voc.storage, 1)
        setPlayerMaxMana(cid, getPlayerMaxMana(cid) - getPlayerMaxMana(cid))
        return true
    end
end
 
Code:
local voc = {
    id = 9, -- change this to the id
    storage = 1000 -- change this to whatever storage you want to use
}
function onLogin(cid)
    if getPlayerStorageValue(cid, voc.storage) ~= 1 and getPlayerVocation(cid) == voc.id then
        setPlayerStorageValue(voc.storage, 1)
        setPlayerMaxMana(cid, getPlayerMaxMana(cid) - getPlayerMaxMana(cid))
        return true
    end
end

Can't login after running this script, No errors just logs me in/out then stucks me in Connecting to game world..
 
post your login file,
just put return true that end

Code:
local voc = {
    id = 9,
    storage = 1000 -- change this to whatever storage you want to use
}
function onLogin(cid)
    if getPlayerStorageValue(cid, voc.storage) ~= 1 and getPlayerVocation(cid) == voc.id then
        setPlayerStorageValue(voc.storage, 1)
        setPlayerMaxMana(cid, getPlayerMaxMana(cid) - getPlayerMaxMana(cid))
        return true
    end
    return true
end
 
post your login file

Code:
local config = {
    loginMessage = getConfigValue('loginMessage'),
    useFragHandler = getBooleanFromString(getConfigValue('useFragHandler'))
}

function onLogin(cid)
    local loss = getConfigValue('deathLostPercent')
    if(loss ~= nil) then
        doPlayerSetLossPercent(cid, PLAYERLOSS_EXPERIENCE, loss * 10)
    end

    local accountManager = getPlayerAccountManager(cid)
    if(accountManager == MANAGER_NONE) then
        local lastLogin, str = getPlayerLastLoginSaved(cid), config.loginMessage
        if(lastLogin > 0) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, str)
            str = "Your last visit was on " .. os.date("%a %b %d %X %Y", lastLogin) .. "."
        else
            str = str .. " Please choose your outfit."
            doPlayerSendOutfitWindow(cid)
        end

        doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, str)
    elseif(accountManager == MANAGER_NAMELOCK) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Hello, it appears that your character has been namelocked, what would you like as your new name?")
    elseif(accountManager == MANAGER_ACCOUNT) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Hello, type 'account' to manage your account and if you want to start over then type 'cancel'.")
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Hello, type 'account' to create an account or type 'recover' to recover an account.")
    end

    if(not isPlayerGhost(cid)) then
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
    end

    registerCreatureEvent(cid, "logintext")
    registerCreatureEvent(cid, "Mail")
    registerCreatureEvent(cid, "GuildMotd")
    registerCreatureEvent(cid, "firstItems")
    registerCreatureEvent(cid, "manalogin")

    registerCreatureEvent(cid, "Idle")
    if(config.useFragHandler) then
        registerCreatureEvent(cid, "SkullCheck")
    end

    registerCreatureEvent(cid, "ReportBug")
    registerCreatureEvent(cid, "testportals")
    registerCreatureEvent(cid, "AdvanceSave")
    return true
end

and in creatureevent.xml

Code:
<event type="login" name="manalogin" event="script" value="manalogin.lua"/>
 
post your login file,
just put return true that end

Code:
local voc = {
    id = 9,
    storage = 1000 -- change this to whatever storage you want to use
}
function onLogin(cid)
    if getPlayerStorageValue(cid, voc.storage) ~= 1 and getPlayerVocation(cid) == voc.id then
        setPlayerStorageValue(voc.storage, 1)
        setPlayerMaxMana(cid, getPlayerMaxMana(cid) - getPlayerMaxMana(cid))
        return true
    end
    return true
end

Ok atleast there is an error now:

qYsucUw.png
 
try this
Code:
local voc = {
    id = 9,
    storage = 1000 -- change this to whatever storage you want to use
}

local config = {
    loginMessage = getConfigValue('loginMessage'),
    useFragHandler = getBooleanFromString(getConfigValue('useFragHandler'))
}

function onLogin(cid)
    local loss = getConfigValue('deathLostPercent')
    if(loss ~= nil) then
        doPlayerSetLossPercent(cid, PLAYERLOSS_EXPERIENCE, loss * 10)
    end
   
    if getPlayerStorageValue(cid, voc.storage) ~= 1 and getPlayerVocation(cid) == voc.id then
        setPlayerStorageValue(voc.storage, 1)
        setPlayerMaxMana(cid, getPlayerMaxMana(cid) - getPlayerMaxMana(cid))
    end

    local accountManager = getPlayerAccountManager(cid)
    if(accountManager == MANAGER_NONE) then
        local lastLogin, str = getPlayerLastLoginSaved(cid), config.loginMessage
        if(lastLogin > 0) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, str)
            str = "Your last visit was on " .. os.date("%a %b %d %X %Y", lastLogin) .. "."
        else
            str = str .. " Please choose your outfit."
            doPlayerSendOutfitWindow(cid)
        end

        doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, str)
    elseif(accountManager == MANAGER_NAMELOCK) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Hello, it appears that your character has been namelocked, what would you like as your new name?")
    elseif(accountManager == MANAGER_ACCOUNT) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Hello, type 'account' to manage your account and if you want to start over then type 'cancel'.")
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Hello, type 'account' to create an account or type 'recover' to recover an account.")
    end

    if(not isPlayerGhost(cid)) then
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
    end

    registerCreatureEvent(cid, "logintext")
    registerCreatureEvent(cid, "Mail")
    registerCreatureEvent(cid, "GuildMotd")
    registerCreatureEvent(cid, "firstItems")
    registerCreatureEvent(cid, "manalogin")

    registerCreatureEvent(cid, "Idle")
    if(config.useFragHandler) then
        registerCreatureEvent(cid, "SkullCheck")
    end

    registerCreatureEvent(cid, "ReportBug")
    registerCreatureEvent(cid, "testportals")
    registerCreatureEvent(cid, "AdvanceSave")
    return true
end
 
try this
Code:
local voc = {
    id = 9,
    storage = 1000 -- change this to whatever storage you want to use
}

local config = {
    loginMessage = getConfigValue('loginMessage'),
    useFragHandler = getBooleanFromString(getConfigValue('useFragHandler'))
}

function onLogin(cid)
    local loss = getConfigValue('deathLostPercent')
    if(loss ~= nil) then
        doPlayerSetLossPercent(cid, PLAYERLOSS_EXPERIENCE, loss * 10)
    end
 
    if getPlayerStorageValue(cid, voc.storage) ~= 1 and getPlayerVocation(cid) == voc.id then
        setPlayerStorageValue(voc.storage, 1)
        setPlayerMaxMana(cid, getPlayerMaxMana(cid) - getPlayerMaxMana(cid))
    end

    local accountManager = getPlayerAccountManager(cid)
    if(accountManager == MANAGER_NONE) then
        local lastLogin, str = getPlayerLastLoginSaved(cid), config.loginMessage
        if(lastLogin > 0) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, str)
            str = "Your last visit was on " .. os.date("%a %b %d %X %Y", lastLogin) .. "."
        else
            str = str .. " Please choose your outfit."
            doPlayerSendOutfitWindow(cid)
        end

        doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, str)
    elseif(accountManager == MANAGER_NAMELOCK) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Hello, it appears that your character has been namelocked, what would you like as your new name?")
    elseif(accountManager == MANAGER_ACCOUNT) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Hello, type 'account' to manage your account and if you want to start over then type 'cancel'.")
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Hello, type 'account' to create an account or type 'recover' to recover an account.")
    end

    if(not isPlayerGhost(cid)) then
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
    end

    registerCreatureEvent(cid, "logintext")
    registerCreatureEvent(cid, "Mail")
    registerCreatureEvent(cid, "GuildMotd")
    registerCreatureEvent(cid, "firstItems")
    registerCreatureEvent(cid, "manalogin")

    registerCreatureEvent(cid, "Idle")
    if(config.useFragHandler) then
        registerCreatureEvent(cid, "SkullCheck")
    end

    registerCreatureEvent(cid, "ReportBug")
    registerCreatureEvent(cid, "testportals")
    registerCreatureEvent(cid, "AdvanceSave")
    return true
end


Same error as i posted above:
cNQ1FJn.png
 
3rd time is a charm
Code:
local voc = {
    id = 9,
    storage = 1000 -- change this to whatever storage you want to use
}

local config = {
    loginMessage = getConfigValue('loginMessage'),
    useFragHandler = getBooleanFromString(getConfigValue('useFragHandler'))
}

function onLogin(cid)
    local loss = getConfigValue('deathLostPercent')
    if(loss ~= nil) then
        doPlayerSetLossPercent(cid, PLAYERLOSS_EXPERIENCE, loss * 10)
    end
   
    if getPlayerStorageValue(cid, voc.storage) ~= 1 and getPlayerVocation(cid) == voc.id then
        setPlayerStorageValue(cid, voc.storage, 1)
        setCreatureMaxMana(cid, getPlayerMaxMana(cid) - getPlayerMaxMana(cid))
    end

    local accountManager = getPlayerAccountManager(cid)
    if(accountManager == MANAGER_NONE) then
        local lastLogin, str = getPlayerLastLoginSaved(cid), config.loginMessage
        if(lastLogin > 0) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, str)
            str = "Your last visit was on " .. os.date("%a %b %d %X %Y", lastLogin) .. "."
        else
            str = str .. " Please choose your outfit."
            doPlayerSendOutfitWindow(cid)
        end

        doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, str)
    elseif(accountManager == MANAGER_NAMELOCK) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Hello, it appears that your character has been namelocked, what would you like as your new name?")
    elseif(accountManager == MANAGER_ACCOUNT) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Hello, type 'account' to manage your account and if you want to start over then type 'cancel'.")
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Hello, type 'account' to create an account or type 'recover' to recover an account.")
    end

    if(not isPlayerGhost(cid)) then
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
    end

    registerCreatureEvent(cid, "logintext")
    registerCreatureEvent(cid, "Mail")
    registerCreatureEvent(cid, "GuildMotd")
    registerCreatureEvent(cid, "firstItems")
    registerCreatureEvent(cid, "manalogin")

    registerCreatureEvent(cid, "Idle")
    if(config.useFragHandler) then
        registerCreatureEvent(cid, "SkullCheck")
    end

    registerCreatureEvent(cid, "ReportBug")
    registerCreatureEvent(cid, "testportals")
    registerCreatureEvent(cid, "AdvanceSave")
    return true
end
 
3rd time is a charm
Code:
local voc = {
    id = 9,
    storage = 1000 -- change this to whatever storage you want to use
}

local config = {
    loginMessage = getConfigValue('loginMessage'),
    useFragHandler = getBooleanFromString(getConfigValue('useFragHandler'))
}

function onLogin(cid)
    local loss = getConfigValue('deathLostPercent')
    if(loss ~= nil) then
        doPlayerSetLossPercent(cid, PLAYERLOSS_EXPERIENCE, loss * 10)
    end
  
    if getPlayerStorageValue(cid, voc.storage) ~= 1 and getPlayerVocation(cid) == voc.id then
        setPlayerStorageValue(cid, voc.storage, 1)
        setCreatureMaxMana(cid, getPlayerMaxMana(cid) - getPlayerMaxMana(cid))
    end

    local accountManager = getPlayerAccountManager(cid)
    if(accountManager == MANAGER_NONE) then
        local lastLogin, str = getPlayerLastLoginSaved(cid), config.loginMessage
        if(lastLogin > 0) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, str)
            str = "Your last visit was on " .. os.date("%a %b %d %X %Y", lastLogin) .. "."
        else
            str = str .. " Please choose your outfit."
            doPlayerSendOutfitWindow(cid)
        end

        doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, str)
    elseif(accountManager == MANAGER_NAMELOCK) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Hello, it appears that your character has been namelocked, what would you like as your new name?")
    elseif(accountManager == MANAGER_ACCOUNT) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Hello, type 'account' to manage your account and if you want to start over then type 'cancel'.")
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Hello, type 'account' to create an account or type 'recover' to recover an account.")
    end

    if(not isPlayerGhost(cid)) then
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
    end

    registerCreatureEvent(cid, "logintext")
    registerCreatureEvent(cid, "Mail")
    registerCreatureEvent(cid, "GuildMotd")
    registerCreatureEvent(cid, "firstItems")
    registerCreatureEvent(cid, "manalogin")

    registerCreatureEvent(cid, "Idle")
    if(config.useFragHandler) then
        registerCreatureEvent(cid, "SkullCheck")
    end

    registerCreatureEvent(cid, "ReportBug")
    registerCreatureEvent(cid, "testportals")
    registerCreatureEvent(cid, "AdvanceSave")
    return true
end

It works! Thank you sooo much for all your help! Not sure why it had to be posted in login.lua but it works! Thanks :D
 
It works! Thank you sooo much for all your help! Not sure why it had to be posted in login.lua but it works! Thanks :D
Because if you already have existing players that are of vocations 9 this will set their mana, but this also allows you to have more control over your vocation and not have to worry about editing the vocations file or editing the database.. its just an easier solution :)

But i would recomend you change your vocation 9 to have 0 zero mana gain if thats is what you want, because this will only work 1 time per character
 
Because if you already have existing players that are of vocations 9 this will set their mana, but this also allows you to have more control over your vocation and not have to worry about editing the vocations file or editing the database.. its just an easier solution :)

But i would recomend you change your vocation 9 to have 0 zero mana gain if thats is what you want, because this will only work 1 time per character

Yeah they already have 0 mana gain, I just wanted this to set it to start with 0 mana because znote acc has no specific vocation hp/mana start settings just overall settings.
 
Back
Top