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

botter1234

Member
Joined
Jun 20, 2008
Messages
103
Reaction score
7
All set fully functional

Lua:
local amuletid = {
	[1] = 7890, -- Inferno
	[2] = 7887, -- Nature
	[3] = 2198, -- Ice Shard
	[4] = 2196 -- Newborn Scarabs
}

local successchance = 90 -- Percent out of 100 / Chance to Succeed
local extrachance = 60 -- Percent out of 100 / Chance to add an extra charge

function onUse(cid, item, frompos, item2, topos)
	local amulet, lefthand, righthand = getPlayerSlotItem(cid, CONST_SLOT_NECKLACE), getPlayerSlotItem(cid, CONST_SLOT_LEFT), getPlayerSlotItem(cid, CONST_SLOT_RIGHT)
	
	if(item.itemid == 1945) or (item.itemid == 1946) then
		if not isInArray(amuletid, amulet.itemid) then
			local info = "You can use these amulets.\n\n"
			for i=1, #amuletid do
				info = info .. getItemNameById(amuletid[i]) .. "\n"
			end
			info = info .. "\nEquip the amulet that you would like to charge."
			info = info .. "\nPut an amulet with only one charge in each hand of the same type."
			info = info .. "\n\nIf you fail it will destroy the amulets in your hands. Success Rate: " .. successchance .. "%"
			info = info .. "\n\nUsing 2 amulets (one in each hand) has a " .. extrachance .. "% chance to add an extra charge."
			return doPlayerPopupFYI(cid, info)
		elseif getItemAttribute(amulet.uid, 'charges') >= 100 then
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Cool, I have max charges on this amulet")
			return false
		end
		for i=1, #amuletid do
			if amulet.itemid == amuletid[i] then
				if amulet.itemid == lefthand.itemid or amulet.itemid == righthand.itemid then
				-- Both Hands Two Amulets
					if isInArray(amuletid, lefthand.itemid) and isInArray(amuletid, righthand.itemid) then
						if getItemAttribute(lefthand.uid, 'charges') > 1 or getItemAttribute(righthand.uid, 'charges') > 1 then
							doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Oh, the amulets in my hands can only have one charge")
							return false
						end
						if(math.random(1,100) <= successchance) then
							if(math.random(1,100) <= extrachance) then
								doChangeTypeItem(amulet.uid, amulet.type + 3)
								doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Great, I got an extra charge, 3 charges added.")
							else
								doChangeTypeItem(amulet.uid, amulet.type + 2)
								doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Success 2 charges added.")
							end
							doRemoveItem(lefthand.uid)
							doRemoveItem(righthand.uid)
						else
							doRemoveItem(lefthand.uid)
							doRemoveItem(righthand.uid)
							doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Darn, I failed.")
						end
				-- Left Hand One Amulet
					elseif isInArray(amuletid, lefthand.itemid) then
						if getItemAttribute(lefthand.uid, 'charges') > 1 then
							doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Oh, the amulets in my hands can only have one charge")
							return false
						end
						if(math.random(1,100) <= successchance) then
							doChangeTypeItem(amulet.uid, amulet.type + 1)
							doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Success 1 charge added.")
							doRemoveItem(lefthand.uid)
						else
							doRemoveItem(lefthand.uid)
							doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Darn, I failed.")
						end
				-- Right Hand One Amulet
					elseif isInArray(amuletid, righthand.itemid) then
						if getItemAttribute(righthand.uid, 'charges') > 1 then
							doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Oh, the amulets in my hands can only have one charge")
							return false
						end
						if(math.random(1,100) <= successchance) then
							doChangeTypeItem(amulet.uid, amulet.type + 1)
							doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Success 1 charge added.")
							doRemoveItem(righthand.uid)
						else
							doRemoveItem(righthand.uid)
							doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Darn, I failed.")
						end
					end
				else
					doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "I forgot to put the same amulet type with only one charge in each hand.")
				end
			end
		end
		return doTransformItem(item.uid, item.itemid == 1945 and 1946 or 1945)
	end
end
 
Last edited:
Use isInArray, looks something like this:

Lua:
if not isInArray(amuletid, amulet.itemid) then
-- do something
 
Last edited:
LOL omg I can't believe I completely overlooked that thank you =d haha

also is there a function to check how many charges are on the amulet?
 
Depending on your TFS version, you can use getItemAttribute().

It would be something like:
Lua:
getItemAttribute(item.uid, 'charges')

I'm pretty sure 'charges' is a possible attribute to use.
 
Okay, I've updated the script so that now if anyone wants it they can take it

- - - Updated - - -

thanks Evan that worked

Just need to know if there is a way to get the number of items in the array so instead of having
local amuletnum

it will be i=1, <amountinarray>
 
Last edited:
If you use #array, it will return the number of contents in the array.

Lua:
for i=1,#amuletid do

This means it starts at position 1 in the array and goes until the number of contents in the array (in your case, it would be 4).
 
Back
Top