• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

Action Sell Key

tetra20

DD
Joined
Jan 17, 2009
Messages
1,315
Solutions
4
Reaction score
323
Location
Egypt
I am a new Scripter... Newbie:)D)

Sell key i think everyone know it
Go To Data/Actions/scripts/ and make a new text and add this

Code:
function onUse(cid, item, toPosition, itemEx, fromPosition)
local place = getPlayerPosition(cid)
if itemEx.itemid == 2464 then
	doRemoveItem(itemEx.uid)
	doPlayerAddMoney(cid, 10000)
	doSendMagicEffect(place, 14)
	doSendAnimatedText(getPlayerPosition(cid), "$$", 15)
elseif itemEx.itemid == 2465 then
	doRemoveItem(itemEx.uid)
	doPlayerAddMoney(cid, 10000)
	doSendMagicEffect(place, 14)
        doSendAnimatedText(getPlayerPosition(cid), "$$", 15)
	end
	end
then go To Actions/Actions
Code:
<action itemid="2091" script="test.lua"/>

Note:to add more items add this line
Code:
elseif itemEx.itemid ==[COLOR="#B22222"] 2465[/COLOR] then
	doRemoveItem(itemEx.uid)
	doPlayerAddMoney(cid, 10000)
	doSendMagicEffect(place, 14)
doSendAnimatedText(getPlayerPosition(cid), "$$", 15)
don't forget to change the Id and the Money


To Change Money . Change This Line
Code:
doPlayerAddMoney(cid, [COLOR="#FF0000"]10000[/COLOR])

Sry for my English​
 
Some ways to improve your scripting:
- Try to tab your scripts correctly
- Use constants for example in the magic effect line instead of 14 use CONST_ME_MAGIC_GREEN, makes it compatible and readable.
- Consider creating a config table and/or using tables as it would make this script shorter even with many items to sell.
 
kk Ty Summ and himii

btw summ i can't find any nice tutorial for tables and i am a newbie scripter just 1~1.5 week

:D
 
As Summ said this is how it could have been done:

Lua:
local config = {
	[2464] = 10000,
	[2465] = 20000
	-- [id] = money
}
	
function onUse(cid, item, toPosition, itemEx, fromPosition)
	if(config[itemEx.itemid]) then
		doRemoveItem(itemEx.uid)
		doPlayerAddMoney(cid, config[itemEx.itemid])
		doSendMagicEffect(toPosition, CONST_ME_MAGIC_GREEN)
		doSendAnimatedText(fromPosition, "$$", COLOR_GREEN)
	end
	return true
end
 
ty guys for the advice

Ty Evan for that the table tutorial

- - - Updated - - -

Code:
local config = {
	[1] = {itemid=2465, money=10000},
	[2] = {itemid=2464, money=20000}
}
	function onUse(cid, item, toPosition, itemEx, fromPosition)
	for i,v in ipairs(config) do
	if	doRemoveItem(itemEx.uid) then
	doPlayerAddMoney(cid, config[itemEx.itemid])
	doSendMagicEffect(toPosition, CONST_ME_MAGIC_GREEN)
	doSendAnimatedText(fromPosition, "$$", COLOR_GREEN)
	end
	return TRUE
	end
it isn't working it sell any item i use the key on
 
Edited Version..Working+tested :p
Code:
local config = {
   [2463] = {money=5000},
   [2464] = {money=20000}
}
   function onUse(cid, item, toPosition, itemEx, fromPosition)
   for i,v in pairs(config) do
       if itemEx.itemid == i then
         doPlayerAddMoney(cid, v.money)
         doRemoveItem(itemEx.uid, 1)
         doSendMagicEffect(getPlayerPosition(cid), CONST_ME_MAGIC_GREEN)
         doSendAnimatedText(fromPosition, "$$", COLOR_GREEN)
         doPlayerSendCancel(cid,"Successfully Sold!")
       elseif not(itemEx.itemid) == i then
       doPlayerSendCancel(cid,"Sorry Doesn't Have Price")
       doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
       end
     end
     return true
   end

Don't Forget the Comma after you copy another itemid
 
Last edited:
Edited Version..Working+tested :p
Code:
local config = {
   [2463] = {money=5000},
   [2464] = {money=20000}
}
   function onUse(cid, item, toPosition, itemEx, fromPosition)
   for i,v in pairs(config) do
       if itemEx.itemid == i then
         doPlayerAddMoney(cid, v.money)
         doRemoveItem(itemEx.uid, 1)
         doSendMagicEffect(getPlayerPosition(cid), CONST_ME_MAGIC_GREEN)
         doSendAnimatedText(fromPosition, "$$", COLOR_GREEN)
         doPlayerSendCancel(cid,"Successfully Sold!")
       elseif not(itemEx.itemid) == i then
       doPlayerSendCancel(cid,"Sorry Doesn't Have Price")
       doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
       end
     end
     return true
   end

Don't Forget the Comma after you copy another itemid

You basicly don't need the "for" loop in this case, as you've given the table "key" the value of the itemid.
So you can easily access it without looping through the entire table first, as it'll search the index by itself.
example:
Code:
local config = {
[2463] = {money=5000},
[2464] = {money=20000}
}

if config[itemEx.itemid] then
    -- happens if the itemid is listed in the table
else
   -- happens if the itemid is not listed in the table
end

If you have any further questions feel free to ask :)
 
You basicly don't need the "for" loop in this case, as you've given the table "key" the value of the itemid.
So you can easily access it without looping through the entire table first, as it'll search the index by itself.
example:
Code:
local config = {
[2463] = {money=5000},
[2464] = {money=20000}
}

if config[itemEx.itemid] then
    -- happens if the itemid is listed in the table
else
   -- happens if the itemid is not listed in the table
end

If you have any further questions feel free to ask :)
Thanks For the advice

i want to know if i am going to add money it will be like this?
Code:
doPlayerAddMoney(cid, config[money])

another question

how to make a random from array
like this
Code:
local array = {15,16,17,18}
doPlayerSendTextMessage(cid, 27, ""..math.random(?).."")

Thanks Again :)
 
Thanks For the advice

i want to know if i am going to add money it will be like this?
Code:
doPlayerAddMoney(cid, config[money])

another question

how to make a random from array
like this
Code:
local array = {15,16,17,18}
doPlayerSendTextMessage(cid, 27, ""..math.random(?).."")

Thanks Again :)

1:
Code:
doPlayerAddMoney(cid, config[itemEx.itemid].money)
this is the way to access it.

2:
Code:
local array = {15,16,17,18}
doPlayerSendTextMessage(cid, 27, ""..array[math.random(1,#array)].."")
#array = gives you the number of how much key's the table has.
in this case 4.
 
1:
Code:
doPlayerAddMoney(cid, config[itemEx.itemid].money)
this is the way to access it.

2:
Code:
local array = {15,16,17,18}
doPlayerSendTextMessage(cid, 27, ""..array[math.random(1,#array)].."")
#array = gives you the number of how much key's the table has.
in this case 4.
Thanks :)
I Really Appreciate that
 
Very nice! I will use this! I have alot of custom items and i have a crappy npc that you speak to sell items and it will sell equipted items so this is a safe alternative for me :)
 
Very nice! I will use this! I have alot of custom items and i have a crappy npc that you speak to sell items and it will sell equipted items so this is a safe alternative for me :)
You should! I've tried it and it works perfect :)
 
Back
Top