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

Lua Scripts Outdated

_Aion_

Nothing Else
Joined
Jan 19, 2010
Messages
401
Solutions
4
Reaction score
10
Location
Jequie,Bahia,Brazil
Please can someone help fix some scripts?
always the same errors in various scripts, and scripts are essential to my OT.
Erro N°1 = attempt to compare number with string
Erro N°2 = attempt to perform arithmetic on a nil value

and the database is not getting the values​​, the script is corrupting and is getting some strange symbols (see the image below)
Capturar.JPG

I do not know what to do if someone has a "light" and wants to help me.

NOTE: Most of the scripts that are giving this error, scripts are the TFS 0.3.4

Thanks to all and sorry my bad english, because i'm brazilian.
 
tonumber (e [, base])
Tries to convert its argument to a number. If the argument is already a number or a string convertible to a number, then tonumber returns this number; otherwise, it returns nil.

Code:
number1 = "10"
number2 = "5"
print (number1, " + ", number2, " = ", tonumber (number1) + tonumber (number2))

Output 	10 + 5 = 15
 
im building some functions for you.. will get back later when its finnished, ill rebuild your script.. if i can.
 
Last edited:
updated it, read again :)

- - - Updated - - -

This is what ive finnished so far, dont use it yet.. it wont work. (im building in a mod file.. easier to edit and test that way.

SQL Query:
PHP:
				ALTER TABLE `players` ADD
				`attrstorage` bigint(20) NOT NULL DEFAULT 0;

Functions:
LUA:
<lib name="pagots-lib"><![CDATA[
--#1
function getPlayerAttrStorage(cid)
	local random = db.getResult("SELECT `attrstorage` FROM `players` WHERE `id` = '" .. getPlayerGUID(cid) .. "' LIMIT 1")
       if random:getID() ~= LUA_ERROR then
        	local attrstorage=random:getDataInt("attrstorage")
        	random:free()
        	return attrstorage
    	end
     	return LUA_ERROR
end

--#2
function setPlayerAttrStorage(cid, param)
			param = (tonumber(param))
			if(not param) then
				return LUA_ERROR

			end
			if param == (tonumber(param)) then
				if param > 99999999999999 then
					return LUA_ERROR
				end
				if (param == 99999999999999) or (param < 99999999999999) then
					db.query("UPDATE `players` SET `attrstorage` = "..param.."  WHERE `name` = '" .. getPlayerName(cid) .. "';")
				end
			end
end

--#3
function onAdvance(cid, skill, oldlevel, newlevel)
local attr = getPlayerAttrStorage(cid)
local nl = tonumber(newlevel)
local ol = tonumner(oldlevel)
local addattribute = (attr+(nl-ol)*2)
    if skill == 8 then
        if ol < nl then
            local pos = getCreaturePosition(cid)
            doSendAnimatedText(pos, "Level UP", 129) -- Animated text is now a deprecated function, change to doCreatureSay(cid,pos,"Level UP",TALKTYE_MONSTER_SAY) ?
            doSendMagicEffect(pos, math.random(28, 30))
            doCreatureAddHealth(cid, getCreatureMaxHealth(cid))
            doPlayerAddMana(cid, getPlayerMaxMana(cid))
            setPlayerAttriStorage(cid, addattribute)
        end
    end
    return true
end
]]></lib>

Talkactions for testing purpose:
XML:
<talkaction log="yes" words="/whatismyattrstorage" access="5" event="script"><![CDATA[
domodlib('pagots-lib')
function onSay(cid, words, param, channel)
	local this = (getPlayerAttrStorage(cid))
	doPlayerSendTextMessage(cid,4, "[Plain Awesome]: Your attrstorage is "..this..".")
	return true
end
]]></talkaction>

<talkaction log="yes" words="/setattrstorage" access="5" event="script"><![CDATA[
domodlib('pagots-lib')
function onSay(cid, words, param, channel)
		if(param == '') then
			doPlayerSendTextMessage(cid,4, "[Plain Awesome]: You need a parameter for this command.")
			return true
		end

		param = tonumber(param)
		if(not param) then
			doPlayerSendTextMessage(cid,4, "[Plain Awesome]: You need a numeric parameter for this command.")
			return true
		end
		storage = param
		if (storage == 0) or (storage < 0) then
			doPlayerSendTextMessage(cid,4, "[Plain Awesome]: You cant set the storage to nil or a negative value.")
			return true
		end
		if storage > 1 then
			setPlayerAttrStorage(cid, param)
			doPlayerSendTextMessage(cid,4, "[Plain Awesome]: You set the attrstorage of yourself to "..storage..".")
			return true
		end
end
]]></talkaction>

attrstorage.png
attrstoragefix.png



- - - Updated - - -

My kids are yelling at me because they want to go outside, ill be back later.


- - - Updated - - -

Why i chose bigint:

All arithmetic is done using signed BIGINT or DOUBLE values, so you should not use unsigned big integers larger than 9223372036854775807 (63 bits) except with bit functions! If you do that, some of the last digits in the result may be wrong because of rounding errors when converting a BIGINT value to a DOUBLE.

MySQL can handle BIGINT in the following cases:

When using integers to store large unsigned values in a BIGINT column.

In MIN(col_name) or MAX(col_name), where col_name refers to a BIGINT column.

When using operators (+, -, *, and so on) where both operands are integers.


- - - Updated - - -

okey so.. heres all the stuff:


SQL Query:
PHP:
				ALTER TABLE `players` ADD
				`attrstorage` bigint(20) NOT NULL DEFAULT 0;

Goto your tfs folder/lib/ create a file called pheenix.lua and paste:

LUA:
--#1
function getPlayerAttrStorage(cid)
	local random = db.getResult("SELECT `attrstorage` FROM `players` WHERE `id` = '" .. getPlayerGUID(cid) .. "' LIMIT 1")
       if random:getID() ~= LUA_ERROR then
        	local attrstorage=random:getDataInt("attrstorage")
        	random:free()
        	return attrstorage
    	end
     	return LUA_ERROR
end

--#2
function setPlayerAttrStorage(cid, param)
			param = (tonumber(param))
			if(not param) then
				return LUA_ERROR
 
			end
			if param == (tonumber(param)) then
				if param > 99999999999999 then
					return LUA_ERROR
				end
				if (param == 99999999999999) or (param < 99999999999999) then
					db.query("UPDATE `players` SET `attrstorage` = "..param.."  WHERE `name` = '" .. getPlayerName(cid) .. "';")
				end
			end
end

the function that was giving you errors, dunno where it was located but here it is:

LUA:
--#3
function onAdvance(cid, skill, oldlevel, newlevel)
local attr = getPlayerAttrStorage(cid)
local nl = tonumber(newlevel)
local ol = tonumner(oldlevel)
local addattribute = (attr+(nl-ol)*2)
    if skill == 8 then
        if ol < nl then
            local pos = getCreaturePosition(cid)
            doSendAnimatedText(pos, "Level UP", 129) -- Animated text is now a deprecated function, change to doCreatureSay(cid,pos,"Level UP",TALKTYE_MONSTER_SAY) ?
            doSendMagicEffect(pos, math.random(28, 30))
            doCreatureAddHealth(cid, getCreatureMaxHealth(cid))
            doPlayerAddMana(cid, getPlayerMaxMana(cid))
            setPlayerAttriStorage(cid, addattribute)
        end
    end
    return true
end

the.. NPC script?
LUA:
--# 4 No changes
local focuses = {}
local function isFocused(cid)
	for i, v in pairs(focuses) do
		if(v == cid) then
			return true
		end
	end
	return false
end
 
local function addFocus(cid)
	if(not isFocused(cid)) then
		table.insert(focuses, cid)
	end
end
local function removeFocus(cid)
	for i, v in pairs(focuses) do
		if(v == cid) then
			table.remove(focuses, i)
			break
		end
	end
end
local function lookAtFocus()
	for i, v in pairs(focuses) do
		if(isPlayer(v) == TRUE) then
			doNpcSetCreatureFocus(v)
			return
		end
	end
	doNpcSetCreatureFocus(0)
end

--#5
local function doPlayerAddAttributePoint(cid, amount)
local current = getPlayerAttrStorage(cid)
local new = (current+amount)
setPlayerAttrStorage(cid, new)
return LUA_NO_ERROR
end

--#6
local function doPlayerCheckAttributePoint(cid)
local amt = getPlayerAttrStorage(cid)
return amt
end

--#7 No changes
function onCreatureAppear(cid)
end
 
function onCreatureDisappear(cid)
	if(isFocused(cid)) then
		selfSay("Hmph!")
		removeFocus(cid)
		if(isPlayer(cid) == TRUE) then
			closeShopWindow(cid)
		end
	end
end
 
function onCreatureSay(cid, type, msg)
local Vitality = 
{ [1] = {name = 'Sorcerer', cost = 100000, amount = 100000},  
				[2] = {name = 'Druid', cost = 100000, amount = 100000},
				[3] = {name = 'Paladin', cost = 100000, amount = 200000},
				[4] = {name = 'Knight', cost = 100000, amount = 200000},
				[5] = {name = 'Master Sorcerer', cost = 100000, amount = 100000},
				[6] = {name = 'Elder Druid', cost = 100000, amount = 100000},
				[7] = {name = 'Royal Paladin', cost = 100000, amount = 200000},
				[8] = {name = 'Elite Knight', cost = 100000, amount = 200000},
				[9] = {name = 'Illusionist Mage', cost = 100000, amount = 200000},
				[10] = {name = 'Elemental Master', cost = 100000, amount = 200000},
				[11] = {name = 'Sniper', cost = 100000, amount = 300000},
				[12] = {name = 'Blade Master', cost = 100000, amount = 300000},
}
 
local Energy = 
{ [1] = {name = 'Sorcerer', cost = 100000, amount = 200000}, ---[1] = Vocation,  Name = Vocation Name, Cost = Amount of Attribute Points Needed, Amount = MaxMana Added
				[2] = {name = 'Druid', cost = 100000, amount = 200000},
				[3] = {name = 'Paladin', cost = 100000, amount = 200000},
				[4] = {name = 'Knight', cost = 100000, amount = 100000},
				[5] = {name = 'Master Sorcerer', cost = 100000, amount = 200000},
				[6] = {name = 'Elder Druid', cost = 100000, amount = 200000},
				[7] = {name = 'Royal Paladin', cost = 100000, amount = 200000},
				[8] = {name = 'Elite Knight', cost = 100000, amount = 100000},
				[9] = {name = 'Illusionist Mage', cost = 100000, amount = 300000},
				[10] = {name = 'Elemental Master', cost = 100000, amount = 300000},
				[11] = {name = 'Sniper', cost = 100000, amount = 200000},
				[12] = {name = 'Blade Master', cost = 100000, amount = 200000},
}
 
	if((msg == "hi") and not (isFocused(cid))) then
		selfSay("Ola "..getCreatureName(cid)..", Quer aprender sobre {Attribute Points}? Voce possui "..doPlayerCheckAttributePoint(cid).." attribute points.", cid)
		addFocus(cid)
		talk_state = 1
	elseif((isFocused(cid)) and (msg == "attribute" or msg == "points" or msg == "help" or msg == "job" or msg == "attribute point" or msg == "attribute points")) and talk_state == 1 then
		selfSay("Quando voce ganha levels, voce ganha attribute points. Voce pode gastar seus pontos em {vitality} ou {energy} para melhorar seu char.", cid)
	elseif((isFocused(cid)) and (msg == "energy")) and talk_state == 1 then
		selfSay("Como um "..(Energy[getPlayerVocation(cid)].name).." voce pode aumentar sua {energy} em "..(Energy[getPlayerVocation(cid)].amount)..".  Vai custar "..(Energy[getPlayerVocation(cid)].cost).." attribute points.", cid)
		selfSay("Voce quer gastar seus attribute points em energy?", cid)
		talk_state = 2
	elseif((isFocused(cid)) and (msg == "yes" or msg == "ye")) and talk_state == 2 then
		if doPlayerCheckAttributePoint(cid) >= Energy[getPlayerVocation(cid)].amount then
			local maxmana = getCreatureMaxMana(cid)
			setCreatureMaxMana(cid, (maxmana+Energy[getPlayerVocation(cid)].amount))
			local mana = (getCreatureMaxMana(cid)-getCreatureMana(cid))
			doCreatureAddMana(cid, mana)
			doPlayerAddAttributePoint(cid, -(Energy[getPlayerVocation(cid)].cost))
			selfSay("Sua energy foi aumentada em "..(Energy[getPlayerVocation(cid)].amount).."!", cid)
			selfSay("Ate mais, volte sempre!", cid)
			talk_state = 0
			removeFocus(cid)
		else
			selfSay("Voce nao tem attribute points suficientes!", cid)
			selfSay("Vai upar e volte depois.", cid)
			talk_state = 0
			removeFocus(cid)
		end
	elseif((isFocused(cid)) and (msg == "vitality")) and talk_state == 1 then
		selfSay("Como um "..(Vitality[getPlayerVocation(cid)].name).." voce pode aumentar sua {vitality} em "..(Vitality[getPlayerVocation(cid)].amount)..".  Vai custar "..(Vitality[getPlayerVocation(cid)].cost).." attribute points.", cid)
		selfSay("Voce quer gastar seus pontos em vitality?", cid)
		talk_state = 3
	elseif((isFocused(cid)) and (msg == "yes" or msg == "ye")) and talk_state == 3 then
		if doPlayerCheckAttributePoint(cid) >= Vitality[getPlayerVocation(cid)].cost then -- attempt to compare number with string, error that show in console
			local maxhp = getCreatureMaxHealth(cid)
			setCreatureMaxHealth(cid, (maxhp+Vitality[getPlayerVocation(cid)].amount))
			local health = (getCreatureMaxHealth(cid)-getCreatureHealth(cid))
			doCreatureAddHealth(cid, health)
			doPlayerAddAttributePoint(cid, -(Vitality[getPlayerVocation(cid)].cost))
			selfSay("Sua vitality foi aumentada em "..(Vitality[getPlayerVocation(cid)].amount).."!", cid)
			selfSay("Ate mais, volte sempre!", cid)
			talk_state = 0
			removeFocus(cid)	
		else
			selfSay("Voce nao tem attribute points suficientes!", cid)
			selfSay("Vai upar e volte depois.", cid)
			talk_state = 0
			removeFocus(cid)
		end
	elseif((isFocused(cid)) and (msg == "bye" or msg == "goodbye" or msg == "cya")) then
		selfSay("Ate mais!", cid, TRUE)
		closeShopWindow(cid)
		removeFocus(cid)
	end
end
 
function onPlayerCloseChannel(cid)
	if(isFocused(cid)) then
		selfSay("Afff!")
		closeShopWindow(cid)
		removeFocus(cid)
	end
end
 
function onPlayerEndTrade(cid)
	selfSay("Foi um prazer fazer negocios com voce.", cid)
end
 
function onThink()
	for i, focus in pairs(focuses) do
		if(isCreature(focus) == FALSE) then
			removeFocus(focus)
		else
			local distance = getDistanceTo(focus) or -1
			if((distance > 4) or (distance == -1)) then
				selfSay("Afff!")
				closeShopWindow(focus)
				removeFocus(focus)
			end
		end
	end
	lookAtFocus()
end

If the storage value 47061 is called elswhere change that to getPlayerAttrStorage(cid) no params.
 

Attachments

Last edited:
was not quite what I wanted.
I'll try to explain.

this system is atributes points and in my server system is reset, then the player will reset the accumulated these "points" and then return the NPC.
how high exp, involves high values​​, the player vai resetting, resetting and then gives this error: (
here in otland has a similar system
http://otland.net/f81/level-points-system-162379/
only tested it and it does not accumulate points, in the hours when tested at least did not give this error.
NOTE: only caught part of CreatureEvents because the NPC system has no problem, the script that was "ruining" everything.

can you help me with this?
 
I dont really understand but in your scripts, anywhere where the storage 47061 is called you can use the function getPlayerAttrStorage(cid) or setPlayerAttrStorage(cid, param) instead.. i can rewrite it all if you post it. btw, what version of TFS are you using?
 
I could not fix yet, even putting "onAdvance" TFS 0.3.4, continued giving this error ...
that this forum is so great, no one has gone through something and managed to fix it?
 
the script is for the player to win X points to level up ...
but as the server is high exp and with reset system, so that was in this TFS 0.3.6 and tested in TFS 0.3.4 was normal
 
does anyone know how to solve this?
I am almost pretty sure that is the sourcer, because it is not recognizing
(newlevel-oldlevel) * 2) - Here is where it gives the error and corrupts the database, if anyone knows where I can move to recognize or something.
 
the problem is that the script "apparently" has no bugs.
But to spend some time using the script, he buga the storage being performed (47061), getting those strange symbols instead of values.

# SCRIPT
is a script of points where the player will earn 2 points per level, but as my server is high-exp and reset system, is complicated.
I tested the same script on TFS 0.3.4 and it worked normal, from 0.3.6 it started giving this bug
 
Back
Top