• 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 change gold question

domelxp

Member
Joined
Mar 1, 2010
Messages
243
Reaction score
5
Its possibile to put exhaust for change gold <<>>platinum<<<>>>crystal ??

Code:
local coins = {
	[ITEM_GOLD_COIN] = {
		to = ITEM_PLATINUM_COIN, effect = TEXTCOLOR_YELLOW
	},
	[ITEM_PLATINUM_COIN] = {
		from = ITEM_GOLD_COIN, to = ITEM_CRYSTAL_COIN, effect = TEXTCOLOR_LIGHTBLUE
	},
	[ITEM_CRYSTAL_COIN] = {
		from = ITEM_PLATINUM_COIN, effect = TEXTCOLOR_TEAL
	}
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
	if(getPlayerFlagValue(cid, PLAYERFLAG_CANNOTPICKUPITEM)) then
		return false
	end

	local coin = coins[item.itemid]
	if(not coin) then
		return false
	end

	if(coin.to ~= nil and item.type == ITEMCOUNT_MAX) then
		doChangeTypeItem(item.uid, item.type - item.type)
		doPlayerAddItem(cid, coin.to, 1)
		doSendAnimatedText(fromPosition, "$$$", coins[coin.to].effect)
	elseif(coin.from ~= nil) then
		doChangeTypeItem(item.uid, item.type - 1)
		doPlayerAddItem(cid, coin.from, ITEMCOUNT_MAX)
		doSendAnimatedText(fromPosition, "$$$", coins[coin.from].effect)
	end

	return true
end
 
I'm retired of Tibia and I lost a lot of experience with LUA, but I think it should be something like this:

Code:
[COLOR="red"]local exhaust = createConditionObject(CONDITION_EXHAUST)
setConditionParam(exhaust, CONDITION_PARAM_TICKS, 2000) -- time in milliseconds[/COLOR]

local coins = {
	[ITEM_GOLD_COIN] = {
		to = ITEM_PLATINUM_COIN, effect = TEXTCOLOR_YELLOW
	},
	[ITEM_PLATINUM_COIN] = {
		from = ITEM_GOLD_COIN, to = ITEM_CRYSTAL_COIN, effect = TEXTCOLOR_LIGHTBLUE
	},
	[ITEM_CRYSTAL_COIN] = {
		from = ITEM_PLATINUM_COIN, effect = TEXTCOLOR_TEAL
	}
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
	if(getPlayerFlagValue(cid, PLAYERFLAG_CANNOTPICKUPITEM)) then
		return false
	end

	local coin = coins[item.itemid]
	if(not coin) then
		return false
	end

	if(coin.to ~= nil and item.type == ITEMCOUNT_MAX) then
		doChangeTypeItem(item.uid, item.type - item.type)
		doPlayerAddItem(cid, coin.to, 1)
		[COLOR="red"]doAddCondition(cid, exhaust)[/COLOR]
		doSendAnimatedText(fromPosition, "$$$", coins[coin.to].effect)
	elseif(coin.from ~= nil) then
		doChangeTypeItem(item.uid, item.type - 1)
		doPlayerAddItem(cid, coin.from, ITEMCOUNT_MAX)
		[COLOR="red"]doAddCondition(cid, exhaust)[/COLOR]
		doSendAnimatedText(fromPosition, "$$$", coins[coin.from].effect)
	end
 
[9/4/2011 7:6:58] [Error - LuaInterface::loadFile] data/actions/scripts/other/changegold.lua:37: 'end' expected (to close 'function' at line 16) near '<eof>'
[9/4/2011 7:6:58] [Warning - Event::loadScript] Cannot load script (data/actions/scripts/other/changegold.lua)
[9/4/2011 7:6:58] data/actions/scripts/other/changegold.lua:37: 'end' expected (to close 'function' at line 16) near '<eof>'
 
So just go to
data/lib/050-function.lua
and add this in the end of file
Lua:
function checkExhausted(cid, storage, seconds)
	local v = exhaustion.get(cid, storage)
	if(not v) then
		exhaustion.set(cid, storage, seconds)
	else
		doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "Please wait " .. v .. " seconds before trying this command again.")
		return false
	end

	return true
end
Then you can use this function in your scripts.
(Just after main function)
if(not checkExhausted(cid, 666, 10)) then
return false
end
BY View Profile: slawkens - OtLand! NOT TESTED!!!
 
Lua:
local coins = {
	[ITEM_GOLD_COIN] = {
		to = ITEM_PLATINUM_COIN, effect = TEXTCOLOR_YELLOW
	},
	[ITEM_PLATINUM_COIN] = {
		from = ITEM_GOLD_COIN, to = ITEM_CRYSTAL_COIN, effect = TEXTCOLOR_LIGHTBLUE
	},
	[ITEM_CRYSTAL_COIN] = {
		from = ITEM_PLATINUM_COIN, effect = TEXTCOLOR_TEAL
	}
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
        if(not checkExhausted(cid, 6660666, 10)) then
            return false
        end
	if(getPlayerFlagValue(cid, PLAYERFLAG_CANNOTPICKUPITEM)) then
		return false
	end

	local coin = coins[item.itemid]
	if(not coin) then
		return false
	end

	if(coin.to ~= nil and item.type == ITEMCOUNT_MAX) then
		doChangeTypeItem(item.uid, item.type - item.type)
		doPlayerAddItem(cid, coin.to, 1)
		doSendAnimatedText(fromPosition, "$$$", coins[coin.to].effect)
	elseif(coin.from ~= nil) then
		doChangeTypeItem(item.uid, item.type - 1)
		doPlayerAddItem(cid, coin.from, ITEMCOUNT_MAX)
		doSendAnimatedText(fromPosition, "$$$", coins[coin.from].effect)
	end

	return true
end
But u first need to add to
data/lib/050-function.lua
what I sad before.
 
You can just add a new line like this under it.
Code:
[ITEM_CRYSTAL_COIN] = {
from = ITEM_PLATINUM_COIN, effect = TEXTCOLOR_TEAL
}
Change ITEM_CRYSTAL_COIN to 20311 and ITEM_PLATINUM_COIN to ITEM_CRYSTAL_COIN and change the cystal coin line like the platinum coin line.
Code:
[ITEM_CRYSTAL_COIN] = {
from = ITEM_PLATINUM_COIN, to = 20311, effect = TEXTCOLOR_TEAL
},
 

Similar threads

Back
Top