• 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 Item who give random item (with advanced config)

Erexo

Kage
Premium User
Joined
Mar 27, 2010
Messages
741
Solutions
5
Reaction score
194
Location
Pr0land
GitHub
Erexo
Hello,
I would like to present my very simple script, but with nice config :3

Lua:
local list = {
{["id"] = 2160, ["name"] = "Crystal Coin", ["count"] = 1, ["chance"] = 25},
{["id"] = 2160, ["name"] = "Crystal Coin", ["count"] = 1, ["chance"] = 25},
{["id"] = 2160, ["name"] = "Crystal Coin", ["count"] = 1, ["chance"] = 25},
{["id"] = 2160, ["name"] = "Crystal Coin", ["count"] = 1, ["chance"] = 25},
{["id"] = 2160, ["name"] = "Crystal Coin", ["count"] = 1, ["chance"] = 25}  -- <-- Remember to delete point from last one
}

local config = {
Effect = 2,					--magic effect appears when player use item
Erexo_is_author = true,
chance_system_on = false
}

--[[
*Chance System*
If false, all items have same chance for roll
If true, get amount of chance's, then roll one of it, so if you set in first chance=5, in second=10 it will roll one number between 1 and 15, (so first have ~33% chance, and second ~66%)
]]--


--Script section
local sum = 0
function onUse(cid, item, frompos, item2, topos)
	if (config.Erexo_is_author) then
		if (chance_system_on) then
			for j = 1, #list do 
				sum = sum + list[i].chance -- Idk += will works...
			end
			rand = math.random(1,sum)
			sum = 0
			for i = 1, #list do
				if sum + list[i].chance <= rand then
					doPlayerAddItem(cid, list[i].id, list[i].count)
					doSendMagicEffect(getCreaturePosition(cid), config.Effect)
					doPlayerSendTextMessage(cid,22, "You have recived " .. list[i].name .. ".")  
					doRemoveItem(item.uid, 1)
					return true
				else
					sum = sum + list[i].chance
				end
			end
		else
			rand = math.random(1,#list)
			doPlayerAddItem(cid, list[rand].id, list[rand].count)
			doSendMagicEffect(getCreaturePosition(cid), config.Effect)
			doPlayerSendTextMessage(cid,22, "You have recived " .. list[rand].name .. ".")  
			doRemoveItem(item.uid, 1)
			return true
		end
	else
		while(config.Erexo_is_author ~= true) do
			print(":c")
		end
	end
	return true
end

Not tested, but if someone really need this script, just post here if something wrong :)

Greetings,
Erexo.
 
How does this works?, I mean, Where do I place the item ID i'll be opening, to get those items?
 
actions.xml
XML:
<action itemid="X" script="rollBox.lua"/>
put itemid instead of X.
 
Back
Top