• 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 Scripting - Backward compatibility.

Diath

DIATH
Joined
Jun 4, 2010
Messages
1,973
Reaction score
101
Location
Saint Petersburg, Russian Federation
Hello, many of you are creating scripts and sometimes you post 2 versions of script for 2 versions of The Forgotten Server or sometimes people are requesting scripts for previous The Forgotten Server versions.

I'll show you how to make backward compatibility in one script.

If you call function without brackets and arguments, it'll return variable type (in this case function) and function ID or nil if function doesn't exist.

Here are few examples:
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
	local func = db.query
	if func then
		db.query('UPDATE `players` SET `comment` = \': )\';')
	else
		db.executeQuery('UPDATE `players` SET `comment = \': )\';')
	end

	return true
end

Code:
function onKill(cid, target, damage, flags)
	if isPlayer(target) then
		local item = doPlayerAddItem(cid, 5805, 1)

		local func = doItemSetAttribute
		if func then
			doItemSetAttribute(item.uid, 'description', 'It\'s reward for killing '.. getCreatureName(target) ..'.')
		else
			doSetItemSpecialDescription(item.uid, 'It\'s reward for killing '.. getCreatureName(target) ..'.')
		end
	end

	return true
end

:)
 
Last edited:
Are you retarded? Optimize it !
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
	local func = db.query or db.executeQuery;
	if func then
		func('UPDATE `players` SET `comment` = \': )\';')
	end
	return true
end
 
Back
Top