• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

SQL Fuction how to add in script?

Ghazer

Member
Joined
Mar 13, 2009
Messages
350
Reaction score
6
How I can use this script with SQL "update players set mag_level = 60" because that set magic level to 60...
and doPlayerAddMagLevel add one by one and that produce lag

I create that can you repair or optmize please?

LUA:
function onLogin(cid)
    if getPlayerVocation(cid) == 1 or getPlayerVocation(cid) == 2 or getPlayerVocation(cid) == 5 or getPlayerVocation(cid) == 6 then
	    doRemoveCreature(cid)
        db.query('UPDATE `players` SET `mag_level` = 60 WHERE `name` = ' .. getPlayerName(cid) .. ';')
        getPlayerStorageValue(cid, 56364)
    end
    return true
end

When I use i have this error
wawPl.png
 
Last edited:
@Polat Alemdar, I think you dont understand what I want...

I think that scripts is good but not work in doRemoveCreature... its possible to set magic level 60 when druid or sorcerer is created? before of first login

- - - Updated - - -

ye it is
LUA:
function onLogin(cid)
    if getPlayerStorageValue(cid, 56364) < 1 and (getPlayerVocation(cid) == 1 or getPlayerVocation(cid) == 2 or getPlayerVocation(cid) == 5 or getPlayerVocation(cid) == 6) then
	    doRemoveCreature(cid)
        db.query('UPDATE `players` SET `mag_level` = 60 WHERE `name` = ' .. db.escapeString(getPlayerName(cid)) .. ';')
        doCreatureSetStorage(cid, 56364, 1)
    end
    return true
end


Yes it is possible but you dont need to create a script for it you can only edit Druid Sample and Sorcerer Sample magic level to 60 you can find this in your database

Easy!!
 
maglevel ? :o
Code:
db.query('UPDATE `players` SET `[COLOR="#FF0000"]mag_level[/COLOR]` = 60 WHERE `name` = ' .. db.escapeString(getPlayerName(cid)) .. ';')
 
Last edited:
Error
xAwo0.png


- - - Updated - - -

I think need ' but i edit and without work

LUA:
function onLogin(cid)
    if getPlayerStorageValue(cid, 56364) < 1 and isInArray({1,2,5,6}, getPlayerVocation(cid)) then
        doCreatureSetStorage(cid, 56364, 1)
	    doRemoveCreature(cid)
        db.query('UPDATE `players` SET `maglevel` = 60 WHERE `name` = ' .. db.escapeString(getPlayerName(cid)) .. ';')
    end
    return true
end

- - - Updated - - -

its possible to set magic level 60 when druid or sorcerer is created? before of first login

because that doesnt work
 
You remove the creature first, then you attempt to get the creatures name while he's removed.

Code:
function onLogin(cid)
    if getPlayerStorageValue(cid, 56364) < 1 and isInArray({1,2,5,6}, getPlayerVocation(cid)) then
        doCreatureSetStorage(cid, 56364, 1)
        local name = getPlayerName(cid);
	doRemoveCreature(cid)
        db.query('UPDATE `players` SET `maglevel` = 60 WHERE `name` = ' .. db.escapeString(name) .. ';')
    end
    return true
end
 
login.lua
LUA:
		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
			if(isInArray({1,2,5,6}, getPlayerVocation(cid))) then
				doPlayerAddMagLevel(cid, 60)
			end
			str = str .. " Please choose your outfit."
			doPlayerSendOutfitWindow(cid)
		end
 
login.lua
LUA:
		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
			if(isInArray({1,2,5,6}, getPlayerVocation(cid))) then
				doPlayerAddMagLevel(cid, 60)
			end
			str = str .. " Please choose your outfit."
			doPlayerSendOutfitWindow(cid)
		end

That not work produce lag when give ML... :S

- - - Updated - - -

The problem is doPlayerAddMagLevel(cid, 60) because that give ml one by one... thats is reason for I want use query, to set magic level to 60 in one time.

- - - Updated - - -

You remove the creature first, then you attempt to get the creatures name while he's removed.

Code:
function onLogin(cid)
    if getPlayerStorageValue(cid, 56364) < 1 and isInArray({1,2,5,6}, getPlayerVocation(cid)) then
        doCreatureSetStorage(cid, 56364, 1)
        local name = getPlayerName(cid);
	doRemoveCreature(cid)
        db.query('UPDATE `players` SET `maglevel` = 60 WHERE `name` = ' .. db.escapeString(name) .. ';')
    end
    return true
end

That not work, doRemoveCreature(cid) continue without working...

- - - Updated - - -

Look this talkaction that...
LUA:
function onSay(cid, words, param, channel)
        local x = {
                item = 9971,
                amount = 10,
                amountskill = 10,
                limitskill = 340
        }
 
        local xml = {
                item = 9971,
                amount = 15,
                amountml = 5,
                limitml = 195
        }
 
        local pid = getPlayerGUID(cid)
 
        local id = {
                ["skillclub"] = 1,
                ["skillsword"]= 2,
                ["skillaxe"] = 3,
                ["skilldistance"] = 4,
                ["skillshielding"] = 5
        }
 
        local voc = {
                ["skillclub"] = {4, 8},
                ["skillsword"] = {4, 8},
                ["skillaxe"] = {4, 8},
                ["skilldistance"] = {3, 7},
                ["skillshielding"] = {4, 8}
        }
 
        local vocml = {1, 2, 5, 6}
 
        local pz = "yes"
 
        if(pz == "yes") and (getTilePzInfo(getCreaturePosition(cid)) == false) then
           doPlayerSendCancel(cid, "You need be in protect zone to buy.")
           return true
        end
 
        if (param == '') then
           doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Example: !buy skillshielding.")
           return true
        end
 
        if (param == 'magiclevel') then
            if getPlayerMagLevel(cid) <= xml.limitml then
                    if isInArray(vocml, getPlayerVocation(cid)) == true then
                            if doPlayerRemoveItem(cid, xml.item, xml.amount) then
                                            doRemoveCreature(cid, true)
                                            db.executeQuery("UPDATE `players` SET `maglevel` = `maglevel` + ".. xml.amountml .." WHERE `id` = ".. pid .. "")
                                    else
                                            doPlayerSendCancel(cid, "You don't have required item.")
                                    end
                        else
                                   doPlayerSendCancel(cid, "You can't buy magic level.")
                        end
            else
                    doPlayerSendCancel(cid, "You've reached the limit of magic level.")
            end
return true
end
 
                if(id[param:lower()]) then
                        if(getPlayerSkill(cid, id[param:lower()]) <= x.limitskill) then
                                if isInArray(voc[param:lower()], getPlayerVocation(cid)) == true then
                                if doPlayerRemoveItem(cid, x.item, x.amount) then
                                        doRemoveCreature(cid, true)
                                        db.executeQuery("UPDATE `player_skills` SET `value` = `value` + ".. x.amountskill .." WHERE `player_id` = ".. pid .. " and `skillid` = ".. id[param:lower()] ..";")
                                else
                                        doPlayerSendCancel(cid, "You don't have required item.")
                                end
                              else
                                 doPlayerSendCancel(cid, "You can't buy this skill.")
                              end 
                        else            
                                doPlayerSendCancel(cid, "You've reached the limit of this skill.")
                        end
                else
                        doPlayerSendCancel(cid, "Unknown skill.")
                end
return true
end

- - - Updated - - -

This script do a part of I want... help!
 
Last edited:
SQL won't work for editing skills on login.lua. This code should work fine and I added a check to make sure players don't get above ml 60. If the function is causing lag then it's an issue with the hosting computer.

LUA:
function onLogin(cid)
    if getPlayerStorageValue(cid, 56364) < 1 and isInArray({1,2,5,6}, getPlayerVocation(cid)) then
	local magicNow = getPlayerMagLevel(cid)
	local magicDesired = 60 -- starting magic level
	local magicIncrease = (magicDesired - magicNow)
	if magicNow < magicDesired then
		doPlayerAddMagLevel(cid, magicIncrease)
	end
        doCreatureSetStorage(cid, 56364, 1)
    end
    return true
end
 
Last edited:
The same problem @Wangsta ml is give one by one and that produce lag...
3e43fd3057004077a2eb4ae.png


its possible give ml in one time? I think with SQL/query its possible... but IDK
 
Last edited:
What happens if you use this function:
LUA:
function doPlayerAddMagLevelOnce(cid, amount)
    local amount = amount or 1

    local magLevel = getPlayerMagLevel(cid, true)
    local manaNeeded = getPlayerRequiredMana(cid, magLevel + 1) - getPlayerSpentMana(cid)
    for i = 1, amount - 1 do
        manaNeeded = manaNeeded + getPlayerRequiredMana(cid, magLevel + 1 + i)
    end
    
    doPlayerAddSpentMana(cid, manaNeeded, false)
    return true
end


It will only add mana spent once..
 
@Summ how I can apply this? onlogin idk :S

Code:
	-- Account manager
	accountManager = true
	namelockManager = true
	newPlayerChooseVoc = true
	newPlayerSpawnPosX = 95
	newPlayerSpawnPosY = 117
	newPlayerSpawnPosZ = 7
	newPlayerTownId = 1
	newPlayerLevel = 130
	[B][COLOR="#FF0000"]newPlayerMagicLevel = 60   [/COLOR][/B]        [COLOR="#FF0000"][B]  <- this not produce lag when player login, how config.lua do this? but that add ml to all vocations[/B][/COLOR]
	generateAccountNumber = false

how config.lua can do that? I think if you know this you can use the same form to create what I want?
 
Last edited:
Goto iologindata.cpp and search for a line like this:
[cpp]query << "INSERT INTO `players` (`id`, `name`, `world_id`, `group_id`, `account_id`, `level`, `vocation`, `health`, `healthmax`, `experience`, `lookbody`, `lookfeet`, `lookhead`, `looklegs`, `looktype`, `lookaddons`, `maglevel`, `mana`, `manamax`, `manaspent`, `soul`, `town_id`, `posx`, `posy`, `posz`, `conditions`, `cap`, `sex`, `lastlogin`, `lastip`, `skull`, `skulltime`, `save`, `rank_id`, `guildnick`, `lastlogout`, `blessings`, `online`) ........[/cpp]
In function "bool IOLoginData::createCharacter(uint32_t accountId, std::string characterName, int32_t vocationId, uint16_t sex)"

In that line replace:
[cpp]g_config.getNumber(ConfigManager::START_MAGICLEVEL)[/cpp]
with:
[cpp]startMagLevel[/cpp]

Before:
[cpp] query.str("");[/cpp]
Add:
[cpp] int64_t startMagLevel = g_config.getNumber(ConfigManager::START_MAGICLEVEL);
if(vocationId == 1 || vocationId == 2)
startMagLevel = 20;
else if(vocationId == 3)
startMagLevel = 7;
else if(vocationId == 4)
startMagLevel = 2;[/cpp]
 
Back
Top