Action Perfect Addon Lever!

Azi

Banned User
Joined
Aug 12, 2007
Messages
1,167
Reaction score
51
Location
Włocławek
Hello, today I wanted to present to you the script, which gives us the addons for the items, using the drag lever.
The script is distinguished by unique features ...
A first of which is that items can be placed in
not turn stackpos, and the second is that by double-clicking to show us a list of addons and items that are needed to get the addon.

Items needed addons and you have set themselves in Config, because I do not have the time ... :)

data/actions/scripts/addons.lua:
PHP:
	local addons = { -- addons setting
		{
		which="Second",
		name="Citizen",
		addon = 2,
		outfits = {128,136},
		storage=9100,
		items = {
			{5890, 100},
			{5902, 50}
			}
		},
		
		{
		which="First",
		name="Citizen",
		addon = 1,
		outfits = {128,136},
		storage=9101,
		items = {
			{5910, 100},
			{5911, 50},
			{5912, 75}
			}
		}, 
	
	}
local config = {
	itemsPos = {986, 1080, 7}, --  items table position
	stackpos = {2,3,4,5,6,7,8,9,10} -- stackpos to scan for items.
}
local addonID = 0
local getItems = 0
local timer = (timer~=nil) and timer or 0
local str=""
function onUse(cid, item, fromPosition, itemEx, toPosition)
	if isPremium(cid) == FALSE then
		doPlayerSendCancel(cid, "Sorry, only premium players may use addon lever.")
		return TRUE
	end
	
	for id,addon in ipairs(addons) do
		local needItems = #addon.items
		for i=1, #addon.items do
			for j=1,#config.stackpos do
				local getAddonItems = getThingfromPos({x=config.itemsPos[1],y=config.itemsPos[2],z=config.itemsPos[3],stackpos=config.stackpos[j]})
				if getAddonItems.itemid > 0 then
					if addon.items[i][1] == getAddonItems.itemid and addon.items[i][2] == getAddonItems.type then
						getItems = getItems+1
						break
					end
				end
			end
			if getItems == needItems then
				addonID = id
				break
			end
		end
	end
	
	
	if addonID ~= 0 then
		if getPlayerStorageValue(cid,addons[addonID].storage) == -1 then	
			for i=1,getItems do
				local getItem = getThingfromPos({x=config.itemsPos[1],y=config.itemsPos[2],z=config.itemsPos[3],stackpos=2})
				if getItem.itemid > 0 then
					doRemoveItem(getItem.uid,getItem.type)
				else
					break
				end
			end
			setPlayerStorageValue(cid,addons[addonID].storage,1)
			for i=1, #addons[addonID].outfits do
				doPlayerAddOutfit(cid,addons[addonID].outfits[i],addons[addonID].addon)
			end
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations, You have unlocked "..addons[addonID].which.." "..addons[addonID].name.." addon!")
			doSendMagicEffect({x=config.itemsPos[1],y=config.itemsPos[2],z=config.itemsPos[3]}, CONST_ME_HITBYFIRE)
			if(item.itemid == 1945) then
				doTransformItem(item.uid, 1946)
			elseif(item.itemid == 1946) then
				doTransformItem(item.uid, 1945)
			end
		else
			doPlayerSendCancel(cid, "You arleady have "..addons[addonID].which.." "..addons[addonID].name.." addon!")
		end
	else
		if (os.time()-timer) > 0 then
			timer = os.time()
			doPlayerSendCancel(cid, "Please collect items for addon and go back!")
		else
			timer = 0
			for _, i in ipairs(addons) do
				local status = (getPlayerStorageValue(cid,i.storage) == 1) and " (done) " or ""
				str=str..i.which.." "..i.name.." addon"..status..":"
				for _, j in ipairs(i.items) do
					str=str.."\n - "..j[2].." "..getItemNameById(j[1])
				end
				str=str.."\n\n"
			end
			doShowTextDialog(cid, 6579, str)
		end
	end
	str = ""
	getItems = 0
	addonID = 0
	return TRUE
end
and in data/actions/actions.xml:
PHP:
<action uniqueid="9456" event="script" value="addons.lua"/>
now place in map lever with unique id: 9456 and next from lever table to put items!

Yours,
Azi.
 

Shawak

Legendary OT User
Joined
Sep 11, 2008
Messages
1,976
Reaction score
98
Location
Germany
I always love your ideas ^_^.
Great works :thumbup:.
 

rexgandi

Well-Known Member
Joined
Oct 22, 2011
Messages
65
Reaction score
3
Hello. How I can change script to get any addons?
Etc. One Lever can give all addons , not only Citizen?
 
Top