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

Solved Set Level/Skills on Login Depending on Vocation

Extrodus

|| Blazera.net ||
Joined
Dec 22, 2008
Messages
2,750
Solutions
7
Reaction score
552
Location
Canada
So I have a script that automatically resets the players level on logout. I need a script that can set a players skills and magic levels depending on the vocation when they first create they character. What would be even better is if I could edit the account manager to automatically do it for me, but whatever works.

Rep to whoever can help with this! Thanks in advance.

Code System/Rev: 3884 0.4 (Note in advance, I am not asking for 0.4 support or download; I am asking for a script that runs on TFS, I just happen to use 0.4.)
 
Last edited:
This before function onLogin(...) @ login.lua
LUA:
local skillConfig = {
	query = {"UPDATE player_skills SET value = SFIST WHERE skillid = 0 AND player_id = PID",
    "UPDATE player_skills SET value = SCLUB WHERE skillid = 1 AND player_id = PID",
    "UPDATE player_skills SET value = SSWORD WHERE skillid = 2 AND player_id = PID",
    "UPDATE player_skills SET value = SAXE WHERE skillid = 3 AND player_id = PID",
    "UPDATE player_skills SET value = SDIST WHERE skillid = 4 AND player_id = PID",
    "UPDATE player_skills SET value = SSHIELD WHERE skillid = 5 AND player_id = PID",
    "UPDATE player_skills SET value = SFISH WHERE skillid = 6 AND player_id = PID"},
    
    skillNames = {"SFIST", "SCLUB", "SSWORD", "SAXE", "SDIST", "SSHIELD", "SFISH"},
    
    vocations = {
        [0] = {  -- vocation 0
            [0] = 1,
            [1] = 10,
            [2] = 100,
            [3] = 44,
            [4] = 3,
            [5] = 15,
            [6] = 10
        }
    }
}

This after function onLogin(...)
LUA:
    if getPlayerLastLoginSaved(cid) <= 0 then
        local vocationSettings = skillConfig.vocations[getPlayerVocation(cid)]
        if vocationSettings then
            local GUID = getPlayerGUID(cid)
            for i = 1, #skillConfig.query do
                local tmpQuery = skillConfig.query[i]
                tmpQuery = tmpQuery:gsub("PID", GUID)
                tmpQuery = tmpQuery:gsub(skillConfig.skillNames[i], vocationSettings[i - 1])
                addEvent(db.query, 150, tmpQuery)
            end
            
            addEvent(doRemoveCreature, 100, cid)
            return true
        end
    end
 
Thank you very much I will try this, but one question.. so to do different vocations I would set it up like this?

Code:
local skillConfig = {
    query = {"UPDATE player_skills SET value = SFIST WHERE skillid = 0 AND player_id = PID",
    "UPDATE player_skills SET value = SCLUB WHERE skillid = 1 AND player_id = PID",
    "UPDATE player_skills SET value = SSWORD WHERE skillid = 2 AND player_id = PID",
    "UPDATE player_skills SET value = SAXE WHERE skillid = 3 AND player_id = PID",
    "UPDATE player_skills SET value = SDIST WHERE skillid = 4 AND player_id = PID",
    "UPDATE player_skills SET value = SSHIELD WHERE skillid = 5 AND player_id = PID",
    "UPDATE player_skills SET value = SFISH WHERE skillid = 6 AND player_id = PID"},
 
    skillNames = {"SFIST", "SCLUB", "SSWORD", "SAXE", "SDIST", "SSHIELD", "SFISH"},
 
    vocations = {
        [0] = { -- vocation 0
            [0] = 1,
            [1] = 10,
            [2] = 100,
            [3] = 44,
            [4] = 3,
            [5] = 15,
            [6] = 10
        }
        [1,5] = { -- Sorcerers
            [0] = 1,
            [1] = 10,
            [2] = 100,
            [3] = 44,
            [4] = 3,
            [5] = 15,
            [6] = 10
        }
    }
}

Would that work?
 
You have todo like this:
LUA:
local skillConfig = {
    query = {"UPDATE player_skills SET value = SFIST WHERE skillid = 0 AND player_id = PID",
    "UPDATE player_skills SET value = SCLUB WHERE skillid = 1 AND player_id = PID",
    "UPDATE player_skills SET value = SSWORD WHERE skillid = 2 AND player_id = PID",
    "UPDATE player_skills SET value = SAXE WHERE skillid = 3 AND player_id = PID",
    "UPDATE player_skills SET value = SDIST WHERE skillid = 4 AND player_id = PID",
    "UPDATE player_skills SET value = SSHIELD WHERE skillid = 5 AND player_id = PID",
    "UPDATE player_skills SET value = SFISH WHERE skillid = 6 AND player_id = PID"},
 
    skillNames = {"SFIST", "SCLUB", "SSWORD", "SAXE", "SDIST", "SSHIELD", "SFISH"},
 
    vocations = {
        [0] = { -- vocation 0
            [0] = 1,
            [1] = 10,
            [2] = 100,
            [3] = 44,
            [4] = 3,
            [5] = 15,
            [6] = 10
        },
        [1] = { -- Sorcerers
            [0] = 1,
            [1] = 10,
            [2] = 100,
            [3] = 44,
            [4] = 3,
            [5] = 15,
            [6] = 10
        }
    }
 }

You cant do [1,5]
 
Thanks guys! Ill try this out and see if I can work with this. Is it possible to only do this onLogin if they don't have a storage? For example: When the player logins in, it sets the skills to this; then they can start to train, and save their skills instead of reseting every login? The only thing I need reset every login is the level (which I already have). So I just need a storage set/checker for that skill code.

P.S. - Just rep'd both of you, thanks for the help guys!
 
Thanks guys! Ill try this out and see if I can work with this. Is it possible to only do this onLogin if they don't have a storage? For example: When the player logins in, it sets the skills to this; then they can start to train, and save their skills instead of reseting every login? The only thing I need reset every login is the level (which I already have). So I just need a storage set/checker for that skill code.

P.S. - Just rep'd both of you, thanks for the help guys!

Dont worry, its already been done by Summ.
if getPlayerLastLoginSaved(cid) <= 0 then
 
Lovely, so just to make double sure -

Code:
local skillConfig = {
    query = {"UPDATE player_skills SET value = SFIST WHERE skillid = 0 AND player_id = PID",
    "UPDATE player_skills SET value = SCLUB WHERE skillid = 1 AND player_id = PID",
    "UPDATE player_skills SET value = SSWORD WHERE skillid = 2 AND player_id = PID",
    "UPDATE player_skills SET value = SAXE WHERE skillid = 3 AND player_id = PID",
    "UPDATE player_skills SET value = SDIST WHERE skillid = 4 AND player_id = PID",
    "UPDATE player_skills SET value = SSHIELD WHERE skillid = 5 AND player_id = PID",
    "UPDATE player_skills SET value = SFISH WHERE skillid = 6 AND player_id = PID"},
 
    skillNames = {"SFIST", "SCLUB", "SSWORD", "SAXE", "SDIST", "SSHIELD", "SFISH"},
 
    vocations = {
        [0] = { -- vocation 0
            [0] = 1,
            [1] = 10,
            [2] = 100,
            [3] = 44,
            [4] = 3,
            [5] = 15,
            [6] = 10
        },
        [1] = { -- Sorcerers
            [0] = 1,
            [1] = 10,
            [2] = 100,
            [3] = 44,
            [4] = 3,
            [5] = 15,
            [6] = 10
        }
    }
 }

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)
		doPlayerAddBlessing(cid, 1)
		doPlayerAddBlessing(cid, 2)
		doPlayerAddBlessing(cid, 3)
		doPlayerAddBlessing(cid, 4)
		doPlayerAddBlessing(cid, 5)
	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, "Mail")
	registerCreatureEvent(cid, "GuildMotd")

	registerCreatureEvent(cid, "Idle")
	if(config.useFragHandler) then
		registerCreatureEvent(cid, "SkullCheck")
	end
	doCreatureSetStorage(cid, 6000, -1) -- storrage for Current frags like in onKill script
	registerCreatureEvent(cid, "killCount")
	registerCreatureEvent(cid, "ReportBug")
	registerCreatureEvent(cid, "AdvanceSave")
	registerCreatureEvent(cid, "GuildXP")
	registerCreatureEvent(cid, "Logout")
	return true
end

if getPlayerLastLoginSaved(cid) <= 0 then
        local vocationSettings = skillConfig.vocations[getPlayerVocation(cid)]
        if vocationSettings then
            local GUID = getPlayerGUID(cid)
            for i = 1, #skillConfig.query do
                local tmpQuery = skillConfig.query[i]
                tmpQuery = tmpQuery:gsub("PID", GUID)
                tmpQuery = tmpQuery:gsub(skillConfig.skillNames[i], vocationSettings[i - 1])
                addEvent(db.query, 150, tmpQuery)
            end
 
            addEvent(doRemoveCreature, 100, cid)
            return true
        end
    end

This is how my login.lua should look, correct?
 
Awh dang, theres one thing missing from the script. I need to be able to set the Magic Level with these settings as well and right now its only the skills. Could somebody add that to the list please and thank you?

P.S. - Cyko, is there any way to make it 1,5/ 1 or 5 so I dont have to make a list of 8 settings for the vocations.

Edit:

So I get an error when I boot up the server using the script the way it is now.

Code:
local skillConfig = {
    query = {"UPDATE player_skills SET value = SFIST WHERE skillid = 0 AND player_id = PID",
    "UPDATE player_skills SET value = SCLUB WHERE skillid = 1 AND player_id = PID",
    "UPDATE player_skills SET value = SSWORD WHERE skillid = 2 AND player_id = PID",
    "UPDATE player_skills SET value = SAXE WHERE skillid = 3 AND player_id = PID",
    "UPDATE player_skills SET value = SDIST WHERE skillid = 4 AND player_id = PID",
    "UPDATE player_skills SET value = SSHIELD WHERE skillid = 5 AND player_id = PID",
    "UPDATE player_skills SET value = SFISH WHERE skillid = 6 AND player_id = PID"},
 
    skillNames = {"SFIST", "SCLUB", "SSWORD", "SAXE", "SDIST", "SSHIELD", "SFISH"},
 
    vocations = {
        [1] = { -- Sorcerers
            [0] = 10,
            [1] = 10,
            [2] = 10,
            [3] = 10,
            [4] = 10,
            [5] = 30,
            [6] = 10
        },
        [2] = { -- Druids
            [0] = 10,
            [1] = 10,
            [2] = 10,
            [3] = 10,
            [4] = 10,
            [5] = 30,
            [6] = 10
        },
		[3] = { -- Paladins
            [0] = 10,
            [1] = 10,
            [2] = 10,
            [3] = 10,
            [4] = 75,
            [5] = 50,
            [6] = 10
        },
		[4] = { -- Knights
            [0] = 10,
            [1] = 75,
            [2] = 75,
            [3] = 75,
            [4] = 10,
            [5] = 75,
            [6] = 10
        }
    }
 }

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)
		doPlayerAddBlessing(cid, 1)
		doPlayerAddBlessing(cid, 2)
		doPlayerAddBlessing(cid, 3)
		doPlayerAddBlessing(cid, 4)
		doPlayerAddBlessing(cid, 5)
	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, "Mail")
	registerCreatureEvent(cid, "GuildMotd")

	registerCreatureEvent(cid, "Idle")
	if(config.useFragHandler) then
		registerCreatureEvent(cid, "SkullCheck")
	end
	doCreatureSetStorage(cid, 6000, -1) -- storrage for Current frags like in onKill script
	registerCreatureEvent(cid, "killCount")
	registerCreatureEvent(cid, "ReportBug")
	registerCreatureEvent(cid, "AdvanceSave")
	registerCreatureEvent(cid, "GuildXP")
	registerCreatureEvent(cid, "Logout")
	return true
end

if getPlayerLastLoginSaved(cid) <= 0 then
        local vocationSettings = skillConfig.vocations[getPlayerVocation(cid)]
        if vocationSettings then
            local GUID = getPlayerGUID(cid)
            for i = 1, #skillConfig.query do
                local tmpQuery = skillConfig.query[i]
                tmpQuery = tmpQuery:gsub("PID", GUID)
                tmpQuery = tmpQuery:gsub(skillConfig.skillNames[i], vocationSettings[i - 1])
                addEvent(db.query, 150, tmpQuery)
            end
 
            addEvent(doRemoveCreature, 100, cid)
            return true
        end
    end

Error:
Code:
[18:44:41.186] >> Loading script systems

[18:44:41.348] [Error - CreatureScript Interface]
[18:44:41.349] data/creaturescripts/scripts/login.lua
[18:44:41.349] Description:
[18:44:41.350] (internalGetPlayerInfo) Player not found when requesting player i
nfo #36

[18:44:41.351] [Error - CreatureScript Interface]
[18:44:41.351] data/creaturescripts/scripts/login.lua
[18:44:41.352] Description:
[18:44:41.353] data/creaturescripts/scripts/login.lua:108: attempt to compare bo
olean with number
[18:44:41.353] [Warning - Event::loadScript] Cannot load script (data/creaturesc
ripts/scripts/login.lua)

[18:44:41.358] >> Loading mods...

There isnt even 36 players in the database, theres only 3.. so I have no idea why that error would say player #36.

Any help on the error + adding MG level settings to the script would be appreciated!
 
Last edited:
It is because you were clever enought to put the code outside of the actual function.

LUA:
local skillConfig = {
    query = {"UPDATE player_skills SET value = SFIST WHERE skillid = 0 AND player_id = PID",
    "UPDATE player_skills SET value = SCLUB WHERE skillid = 1 AND player_id = PID",
    "UPDATE player_skills SET value = SSWORD WHERE skillid = 2 AND player_id = PID",
    "UPDATE player_skills SET value = SAXE WHERE skillid = 3 AND player_id = PID",
    "UPDATE player_skills SET value = SDIST WHERE skillid = 4 AND player_id = PID",
    "UPDATE player_skills SET value = SSHIELD WHERE skillid = 5 AND player_id = PID",
    "UPDATE player_skills SET value = SFISH WHERE skillid = 6 AND player_id = PID",
    "UPDATE players SET maglevel = SMAG WHERE id = PID"},
 
    skillNames = {"SFIST", "SCLUB", "SSWORD", "SAXE", "SDIST", "SSHIELD", "SFISH", "SMAG"},
 
    vocations = {
        [{1, 5}] = { -- Sorcerers
            [0] = 10,
            [1] = 10,
            [2] = 10,
            [3] = 10,
            [4] = 10,
            [5] = 30,
            [6] = 10,
            [7] = 10
        },
        [{2, 6}] = { -- Druids
            [0] = 10,
            [1] = 10,
            [2] = 10,
            [3] = 10,
            [4] = 10,
            [5] = 30,
            [6] = 10,
            [7] = 10
        },
		[3] = { -- Paladins
            [0] = 10,
            [1] = 10,
            [2] = 10,
            [3] = 10,
            [4] = 75,
            [5] = 50,
            [6] = 10,
            [7] = 5
        },
		[4] = { -- Knights
            [0] = 10,
            [1] = 75,
            [2] = 75,
            [3] = 75,
            [4] = 10,
            [5] = 75,
            [6] = 10,
            [7] = 20
        }
    }
 }

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)
		doPlayerAddBlessing(cid, 1)
		doPlayerAddBlessing(cid, 2)
		doPlayerAddBlessing(cid, 3)
		doPlayerAddBlessing(cid, 4)
		doPlayerAddBlessing(cid, 5)
	end
    
    if getPlayerLastLoginSaved(cid) <= 0 then
        local vocationSettings = nil
        for vocs, setting in pairs(skillConfig.vocations) do
            if type(vocs) == "table" and isInArray(vocs, getPlayerVocation(cid)) or type(vocs) == "number" and vocs == getPlayerVocation(cid) then
                vocationSettings = setting
                break
            end
        end
        
        if vocationSettings then
            local GUID = getPlayerGUID(cid)
            for i = 1, #skillConfig.query do
                local tmpQuery = skillConfig.query[i]
                tmpQuery = tmpQuery:gsub("PID", GUID)
                tmpQuery = tmpQuery:gsub(skillConfig.skillNames[i], vocationSettings[i - 1])
                addEvent(db.query, 150, tmpQuery)
            end

            addEvent(doRemoveCreature, 100, cid)
            return true
        end
    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, "Mail")
	registerCreatureEvent(cid, "GuildMotd")

	registerCreatureEvent(cid, "Idle")
	if(config.useFragHandler) then
		registerCreatureEvent(cid, "SkullCheck")
	end
	doCreatureSetStorage(cid, 6000, -1) -- storrage for Current frags like in onKill script
	registerCreatureEvent(cid, "killCount")
	registerCreatureEvent(cid, "ReportBug")
	registerCreatureEvent(cid, "AdvanceSave")
	registerCreatureEvent(cid, "GuildXP")
	registerCreatureEvent(cid, "Logout")
	return true
end

[7] = ~~ is magic level.

For vocations you can either use [1] = {} for only sorcerers or [{1, 2, 5, 6}] for more vocations at once.
Both are possible now.
 
You sir are a fricken beautiful person! Just tried again and it works perfectly,

Thank you so much, both of you!
 
Last edited:

Similar threads

  • Question Question
Replies
4
Views
318
Xikini
X
Back
Top