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

[Simple] dotradeitem(cid,olditem,count,newitem,amount)

Andrespro

New Member
Joined
Mar 18, 2009
Messages
125
Reaction score
4
Location
Santa Cruz - Bolivia
Explanation:

Lua:
-- doTradeItem(cid,olditem,count,newitem,amount)

dotradeitem is used to trade items.

- olditem = Item to be traded
- count = 'olditem' count

- newitem = Item to be given
- amouont = 'newitem' count

-- Examples:
		doTradeItem(cid,2160,50,2472,1)
		-- Change '50' of '2160' for '1' of '2472'
		-- It's useful when you want to trade items with NPC

Well, go to data/lib/ folder and search for function.lua, go to the first line and add:

Lua:
  function doTradeItem(cid, olditem, count, newitem, amount)
        if getPlayerItemCount(cid, olditem) >= count then
                doPlayerRemoveItem(cid, olditem, count)
                return (doPlayerAddItem(cid, newitem, amount) and TRUE or FALSE
        end
end


Very simple, very useful
 
Last edited:
Yeah nice one, but you cant't use:
Lua:
if dotradeitem(..) == TRUE then

Try this one, not tested:
Lua:
function doTradeItem(cid, olditem, count, newitem, amount)
	if getPlayerItemCount(cid, olditem) >= count then
		doPlayerRemoveItem(cid, olditem, count)
		return doPlayerAddItem(cid, newitem, amount)
	else
		return FALSE
	end
end

Regards,
Shawak
 
Shawak's one looks neater.

Thanks? :D

@Script:
Update (shorter):
Lua:
function doTradeItem(cid, olditem, count, newitem, amount)
        if getPlayerItemCount(cid, olditem) >= count then
                doPlayerRemoveItem(cid, olditem, count)
                return (doPlayerAddItem(cid, newitem, amount) and TRUE or FALSE
        end
end
 
Nice function though.
:thumbup:
 
Lua:
function doTradeItem(cid, olditem, count, newitem, amount)
    return (doPlayerRemoveItem(cid, olditem, count) == true) and doPlayerAddItem(cid, newitem, amount) or false
end

?? :p
 
Lua:
function doTradeItem(cid, olditem, count, newitem, amount)
    return (doPlayerRemoveItem(cid, olditem, count) == true) and doPlayerAddItem(cid, newitem, amount) or false
end

?? :p
Lua:
        if getPlayerItemCount(cid, olditem) >= count then
??:p
 
@Shawak:

Code:
(doPlayerRemoveItem(cid, olditem, count) == true)
It will also check count ;)
 
Already used test script..

Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
		if doTradeItem(cid, 2472,1,2160,100) == true then
		doSendAnimatedText(fromPosition, "$$$", TEXTCOLOR_YELLOW)
		end
end

Results:

With Shawak's one:

It works fine, and function:

Lua:
		doSendAnimatedText(fromPosition, "$$$", TEXTCOLOR_YELLOW)

Works when doTradeItem(cid,X,X,X,X) == true

But, using Nahruto's one:

It works, but when you put function:

Lua:
		doSendAnimatedText(fromPosition, "$$$", TEXTCOLOR_YELLOW)

After:

Lua:
if doTradeItem(cid, 2472,1,2160,100) == true then

It trade the items but, code:


Lua:
		doSendAnimatedText(fromPosition, "$$$", TEXTCOLOR_YELLOW)

DOESN'T WORK

So, I recommend to use Shawak's one
 
Code:
    return (doPlayerRemoveItem(cid, olditem, count) == true) and doPlayerAddItem(cid, newitem, amount) and true or false
?!?!
 
return (doPlayerRemoveItem(cid, olditem, count) == true) and doPlayerAddItem(cid, newitem, amount) or false


if im not wrong

doPlayerAddItem(cid, newitem, amount)

should return true

try

print(pcall(doPlayerAddItem, cid, newitem, amount))


EDITTTTT !!!

use rizz one with the "and true" part <- i think doPlayerAddItem(cid, newitem, amount) dont return anything ;< by itself

but you could do

return (doPlayerRemoveItem(cid, olditem, count) == true) and pcall(doPlayerAddItem, cid, newitem, amount) or false
 
return (doPlayerRemoveItem(cid, olditem, count) == true) and doPlayerAddItem(cid, newitem, amount) or false


if im not wrong

doPlayerAddItem(cid, newitem, amount)

should return true

try

print(pcall(doPlayerAddItem, cid, newitem, amount))


EDITTTTT !!!

use rizz one with the "and true" part <- i think doPlayerAddItem(cid, newitem, amount) dont return anything ;< by itself

but you could do

return (doPlayerRemoveItem(cid, olditem, count) == true) and pcall(doPlayerAddItem, cid, newitem, amount) or false

I think doPlayerAddItem() returns item's uid.
 
using pcall it should return true >=(


yep it does

try

print(pcall(doPlayerAddItem, cid, 2170, 1))

and you will see
 
Last edited:
Haven't access to any server atm. will try later ;p
 
Back
Top