• 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 magic wand add action id

ConAn Edujawa

Member
Joined
Feb 23, 2015
Messages
457
Reaction score
17
hello guys i need help in my idea.
magic wand when use on box player got chance to add action id on his weapon or armor or shield.
if items 8301 and 8302 and 8305 with sword in box and and chance = 10% add action id 45874 to weapon or armor or shield.
like in photo
dsd.png
if he have items and chance ~= 10% remove one items from box { but don't remove weapons or armor}
0.4
 
What's the importance of the box though?
The script would be infinitely easier if it was just inside the player inventory
 
What's the importance of the box though?
The script would be infinitely easier if it was just inside the player inventory
box will be in special room just one player can enter
and he will add weapon or armor or helmet or shield with ingredients {like 8301-8302} etc and if chance <= 10% add attribute on items { weapon or armor etc} if not remove one items from ingredients
 
I think the easiest thing to do for this case, would be to create a script in the actions folder. In it you would add all the items normally, but in the items you want for an AID, you can use a math.random to do this.

Example:
Lua:
local chance = math.random(1, 10)

Check the chance:
Lua:
if chance == 1 then -- 10% chance


EDIT:
And to add a AID to the item, only use this:
Lua:
item:setActionId(45874) -- AID number
 
I think the easiest thing to do for this case, would be to create a script in the actions folder. In it you would add all the items normally, but in the items you want for an AID, you can use a math.random to do this.

Example:
Lua:
local chance = math.random(1, 10)

Check the chance:
Lua:
if chance == 1 then -- 10% chance
i know its action script and i know how to set chance but how i can script check items in box
because if items = 8301 and 8302 add 74215 action id
if items 8300 and 8305 add 74216 action id
 
idk if it'll work, but try this.
Not tested.

Lua:
function getAllItemsInContainer(container)
    local containers = {}
    local items = {}

    if isContainer(container.uid) then
        table.insert(containers, container.uid)
    end

    while #containers > 0 do
        for k = (getContainerSize(containers[1]) - 1), 0, -1 do
            local tmp = getContainerItem(containers[1], k)
            if isContainer(tmp.uid) then
                table.insert(containers, tmp.uid)
            else
                table.insert(items, tmp)
            end
        end
        table.remove(containers, 1)
    end

    return items
end
 
idk if it'll work, but try this.
Not tested.

Lua:
function getAllItemsInContainer(container)
    local containers = {}
    local items = {}

    if isContainer(container.uid) then
        table.insert(containers, container.uid)
    end

    while #containers > 0 do
        for k = (getContainerSize(containers[1]) - 1), 0, -1 do
            local tmp = getContainerItem(containers[1], k)
            if isContainer(tmp.uid) then
                table.insert(containers, tmp.uid)
            else
                table.insert(items, tmp)
            end
        end
        table.remove(containers, 1)
    end

    return items
end
use this like if getAllItemsInContainer(9302) == true ??
 
use this like if getAllItemsInContainer(9302) == true ??
Lua:
local container = -- get the container object
local items_in_container = getAllItemsInContainer(container)

for i = 1, #items_in_container do
    -- do stuff
end
 
Lua:
local container = -- get the container object
local items_in_container = getAllItemsInContainer(container)

for i = 1, #items_in_container do
    -- do stuff
end
i mad this script for test but give me error
Lua:
local function getAllItemsInContainer(container)
    local containers = {}
    local items = {}

    if isContainer(container.uid) then
        table.insert(containers, container.uid)
    end

    while #containers > 0 do
        for k = (getContainerSize(containers[1]) - 1), 0, -1 do
            local tmp = getContainerItem(containers[1], k)
            if isContainer(tmp.uid) then
                table.insert(containers, tmp.uid)
            else
                table.insert(items, tmp)
            end
        end
        table.remove(containers, 1)
    end

    return items
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local chance = math.random(1, 10)
    local poweritems = 9664
    local container = 8305
local items_in_container = getAllItemsInContainer(container)

for i = 1, #items_in_container do
    if poweitems.actionid == 1800 and chance == 1 then
  doRemoveItem(container, 1)
  doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "hahahahahahhah.")
end
end
    return true
end
ddfr.png
i need to remove items {local container} and remove {local poweritems} and add items 11254
 
Back
Top