• 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 Action script CAP

Lbtg

Advanced OT User
Joined
Nov 22, 2008
Messages
2,394
Reaction score
162
Hey again , can i request/ask to remake this script so it adds 100 cap on use , tryed different ways all didint worked.. xD

script
Code:
items = {

    [0] = {id = 2328, count = 1, chance = 2},
    [1] = {id = 2157, count = 1, chance = 5},
    [2] = {id = 7722, count = 1, chance = 10},
    [3] = {id = 2195, count = 1, chance = 15},
    [4] = {id = 2160, count = 10, chance = 30},
    [5] = {id = 6569, count = 50, chance = 100}
}
function onUse(cid, item, fromPos, itemEx, toPos)
    for i = 0, #items do
        if (items[i].chance > math.random(1, 100)) then
            doPlayerAddItem(cid, items[i].id, items[i].count)   
            doRemoveItem(item.uid, 1)
            return doCreatureSay(cid, 'I congratulate you won item! This item is '..getItemNameById(items[i].id)..'!', TALKTYPE_MONSTER)
        end
    end
    doRemoveItem(item.uid, 1)
    return doCreatureSay(cid, 'Sorry, have not won anything!', TALKTYPE_MONSTER)
end

Thanks in advance :)
 
Code:
doPlayerSetMaxCapacity(cid, cap)
This only set's the players cap to a specific number though.
You'll have to calculate the players cap using a combination of method's, or force the player to be naked and use
Code:
getPlayerFreeCap(cid) + X
 
doPlayerSetMaxCapacity(cid, getPlayerFreeCap(cid) + 100)
? well i tryed lots of different writes none didint work only it sets 100 cap to player but doesnt add :(
 
Right, that will work, but only if you force the character to be naked when consuming the item.
Code:
getPlayerSlotItem(cid, slot)
Use above and loop through each slot verifying if there is an item there.

If your still having trouble with it after attempting some stuff, post what you've tried, then myself or another forum member can guide you back on track. :)

-- Edit

Of course this is my personal experience.
It may not be the best way to accomplish the script.
 
Last edited by a moderator:
Haven't tested it. Try it and post any possible errors @Lbtg

Code:
items = {

    [0] = {id = 2328, count = 1, chance = 2},
    [1] = {id = 2157, count = 1, chance = 5},
    [2] = {id = 7722, count = 1, chance = 10},
    [3] = {id = 2195, count = 1, chance = 15},
    [4] = {id = 2160, count = 10, chance = 30},
    [5] = {id = 6569, count = 50, chance = 100}
}
function onUse(cid, item, fromPos, itemEx, toPos)
  
    local slo = {CONST_SLOT_NECKLACE, CONST_SLOT_BACKPACK, CONST_SLOT_HEAD, CONST_SLOT_ARMOR, CONST_SLOT_LEGS, CONST_SLOT_FEET, CONST_SLOT_RING, CONST_SLOT_RIGHT, CONST_SLOT_LEFT, CONST_SLOT_AMMO}
  
    for i = 1, #slo do
    if getPlayerSlotItem(cid, slo[i]).itemid) >= 1 then
        doCreatureSay(cid, "Please empty out all your slots first including backpack.", 19)
        return true
    end
  
  
    for i = 1, #slo do
    if getPlayerSlotItem(cid, slo[i]).itemid) == 0 then
    for i = 0, #items do
        if (items[i].chance > math.random(1, 100)) then
            doPlayerSetMaxCapacity(cid, getPlayerFreeCap(cid) + 100)
            doPlayerAddItem(cid, items[i].id, items[i].count) 
            doRemoveItem(item.uid, 1)
            return doCreatureSay(cid, 'I congratulate you won item! This item is '..getItemNameById(items[i].id)..'!', TALKTYPE_MONSTER)
            end
        end
    end
end
    doRemoveItem(item.uid, 1)
    return doCreatureSay(cid, 'Sorry, have not won anything!', TALKTYPE_MONSTER)
end
 
Haven't tested it. Try it and post any possible errors @Lbtg

Code:
items = {

    [0] = {id = 2328, count = 1, chance = 2},
    [1] = {id = 2157, count = 1, chance = 5},
    [2] = {id = 7722, count = 1, chance = 10},
    [3] = {id = 2195, count = 1, chance = 15},
    [4] = {id = 2160, count = 10, chance = 30},
    [5] = {id = 6569, count = 50, chance = 100}
}
function onUse(cid, item, fromPos, itemEx, toPos)
 
    local slo = {CONST_SLOT_NECKLACE, CONST_SLOT_BACKPACK, CONST_SLOT_HEAD, CONST_SLOT_ARMOR, CONST_SLOT_LEGS, CONST_SLOT_FEET, CONST_SLOT_RING, CONST_SLOT_RIGHT, CONST_SLOT_LEFT, CONST_SLOT_AMMO}
 
    for i = 1, #slo do
    if getPlayerSlotItem(cid, slo[i]).itemid) >= 1 then
        doCreatureSay(cid, "Please empty out all your slots first including backpack.", 19)
        return true
    end
 
 
    for i = 1, #slo do
    if getPlayerSlotItem(cid, slo[i]).itemid) == 0 then
    for i = 0, #items do
        if (items[i].chance > math.random(1, 100)) then
            doPlayerSetMaxCapacity(cid, getPlayerFreeCap(cid) + 100)
            doPlayerAddItem(cid, items[i].id, items[i].count)
            doRemoveItem(item.uid, 1)
            return doCreatureSay(cid, 'I congratulate you won item! This item is '..getItemNameById(items[i].id)..'!', TALKTYPE_MONSTER)
            end
        end
    end
end
    doRemoveItem(item.uid, 1)
    return doCreatureSay(cid, 'Sorry, have not won anything!', TALKTYPE_MONSTER)
end

error mate
Code:
[0:9:43.126] [Error - LuaInterface::loadFile] data/actions/scripts/rondomgift.lua:15: 'then' expected near ')'
[0:9:43.126] [Warning - Event::loadScript] Cannot load script (data/actions/scripts/rondomgift.lua)
[0:9:43.126] data/actions/scripts/rondomgift.lua:15: 'then' expected near ')'
 
error mate
Code:
[0:9:43.126] [Error - LuaInterface::loadFile] data/actions/scripts/rondomgift.lua:15: 'then' expected near ')'
[0:9:43.126] [Warning - Event::loadScript] Cannot load script (data/actions/scripts/rondomgift.lua)
[0:9:43.126] data/actions/scripts/rondomgift.lua:15: 'then' expected near ')'
Woops, my fault
Code:
items = {

    [0] = {id = 2328, count = 1, chance = 2},
    [1] = {id = 2157, count = 1, chance = 5},
    [2] = {id = 7722, count = 1, chance = 10},
    [3] = {id = 2195, count = 1, chance = 15},
    [4] = {id = 2160, count = 10, chance = 30},
    [5] = {id = 6569, count = 50, chance = 100}
}
function onUse(cid, item, fromPos, itemEx, toPos)
    local slo = {CONST_SLOT_NECKLACE, CONST_SLOT_BACKPACK, CONST_SLOT_HEAD, CONST_SLOT_ARMOR, CONST_SLOT_LEGS, CONST_SLOT_FEET, CONST_SLOT_RING, CONST_SLOT_RIGHT, CONST_SLOT_LEFT, CONST_SLOT_AMMO}
    for i = 1, #slo do
    if getPlayerSlotItem(cid, slo[i]).itemid >= 1 then
        doCreatureSay(cid, "Please empty out all your slots first including backpack.", 19)
        return true
    end
    for i = 1, #slo do
    if getPlayerSlotItem(cid, slo[i]).itemid == 0 then
    for i = 0, #items do
        if (items[i].chance > math.random(1, 100)) then
            doPlayerSetMaxCapacity(cid, getPlayerFreeCap(cid) + 100)
            doPlayerAddItem(cid, items[i].id, items[i].count)
            doRemoveItem(item.uid, 1)
            return doCreatureSay(cid, 'I congratulate you won item! This item is '..getItemNameById(items[i].id)..'!', TALKTYPE_MONSTER)
            end
        end
end
    doRemoveItem(item.uid, 1)
    return doCreatureSay(cid, 'Sorry, have not won anything!', TALKTYPE_MONSTER)
end
 
Woops, my fault
Code:
items = {

    [0] = {id = 2328, count = 1, chance = 2},
    [1] = {id = 2157, count = 1, chance = 5},
    [2] = {id = 7722, count = 1, chance = 10},
    [3] = {id = 2195, count = 1, chance = 15},
    [4] = {id = 2160, count = 10, chance = 30},
    [5] = {id = 6569, count = 50, chance = 100}
}
function onUse(cid, item, fromPos, itemEx, toPos)
    local slo = {CONST_SLOT_NECKLACE, CONST_SLOT_BACKPACK, CONST_SLOT_HEAD, CONST_SLOT_ARMOR, CONST_SLOT_LEGS, CONST_SLOT_FEET, CONST_SLOT_RING, CONST_SLOT_RIGHT, CONST_SLOT_LEFT, CONST_SLOT_AMMO}
    for i = 1, #slo do
    if getPlayerSlotItem(cid, slo[i]).itemid >= 1 then
        doCreatureSay(cid, "Please empty out all your slots first including backpack.", 19)
        return true
    end
    for i = 1, #slo do
    if getPlayerSlotItem(cid, slo[i]).itemid == 0 then
    for i = 0, #items do
        if (items[i].chance > math.random(1, 100)) then
            doPlayerSetMaxCapacity(cid, getPlayerFreeCap(cid) + 100)
            doPlayerAddItem(cid, items[i].id, items[i].count)
            doRemoveItem(item.uid, 1)
            return doCreatureSay(cid, 'I congratulate you won item! This item is '..getItemNameById(items[i].id)..'!', TALKTYPE_MONSTER)
            end
        end
    end
end
    doRemoveItem(item.uid, 1)
    return doCreatureSay(cid, 'Sorry, have not won anything!', TALKTYPE_MONSTER)
end

it hits error again
Code:
[0:13:10.221] [Error - LuaInterface::loadFile] data/actions/scripts/rondomgift.lua:31: 'end' expected (to close 'function' at line 10) near '<eof>'
[0:13:10.221] [Warning - Event::loadScript] Cannot load script (data/actions/scripts/rondomgift.lua)
[0:13:10.221] data/actions/scripts/rondomgift.lua:31: 'end' expected (to close 'function' at line 10) near '<eof>'
 
it hits error again
Code:
[0:13:10.221] [Error - LuaInterface::loadFile] data/actions/scripts/rondomgift.lua:31: 'end' expected (to close 'function' at line 10) near '<eof>'
[0:13:10.221] [Warning - Event::loadScript] Cannot load script (data/actions/scripts/rondomgift.lua)
[0:13:10.221] data/actions/scripts/rondomgift.lua:31: 'end' expected (to close 'function' at line 10) near '<eof>'
Remove an end under "return doCreatureSay"
 
Remove an end under "return doCreatureSay"
Code:
items = {

    [0] = {id = 2328, count = 1, chance = 2},
    [1] = {id = 2157, count = 1, chance = 5},
    [2] = {id = 7722, count = 1, chance = 10},
    [3] = {id = 2195, count = 1, chance = 15},
    [4] = {id = 2160, count = 10, chance = 30},
    [5] = {id = 6569, count = 50, chance = 100}
}
function onUse(cid, item, fromPos, itemEx, toPos)
    local slo = {CONST_SLOT_NECKLACE, CONST_SLOT_BACKPACK, CONST_SLOT_HEAD, CONST_SLOT_ARMOR, CONST_SLOT_LEGS, CONST_SLOT_FEET, CONST_SLOT_RING, CONST_SLOT_RIGHT, CONST_SLOT_LEFT, CONST_SLOT_AMMO}
    for i = 1, #slo do
    if getPlayerSlotItem(cid, slo[i]).itemid >= 1 then
        doCreatureSay(cid, "Please empty out all your slots first including backpack.", 19)
    end
    for i = 1, #slo do
    if getPlayerSlotItem(cid, slo[i]).itemid == 0 then
    for i = 0, #items do
        if (items[i].chance > math.random(1, 100)) then
            doPlayerSetMaxCapacity(cid, getPlayerFreeCap(cid) + 100)
            doPlayerAddItem(cid, items[i].id, items[i].count)
            doRemoveItem(item.uid, 1)
            return doCreatureSay(cid, 'I congratulate you won item! This item is '..getItemNameById(items[i].id)..'!', TALKTYPE_MONSTER)
            end
        end
    end
end
    doRemoveItem(item.uid, 1)
    return doCreatureSay(cid, 'Sorry, have not won anything!', TALKTYPE_MONSTER)
end
like this ?
 
Code:
items = {

    [0] = {id = 2328, count = 1, chance = 2},
    [1] = {id = 2157, count = 1, chance = 5},
    [2] = {id = 7722, count = 1, chance = 10},
    [3] = {id = 2195, count = 1, chance = 15},
    [4] = {id = 2160, count = 10, chance = 30},
    [5] = {id = 6569, count = 50, chance = 100}
}
function onUse(cid, item, fromPos, itemEx, toPos)
    local slo = {CONST_SLOT_NECKLACE, CONST_SLOT_BACKPACK, CONST_SLOT_HEAD, CONST_SLOT_ARMOR, CONST_SLOT_LEGS, CONST_SLOT_FEET, CONST_SLOT_RING, CONST_SLOT_RIGHT, CONST_SLOT_LEFT, CONST_SLOT_AMMO}
    for i = 1, #slo do
    if getPlayerSlotItem(cid, slo[i]).itemid >= 1 then
        doCreatureSay(cid, "Please empty out all your slots first including backpack.", 19)
    end
    for i = 1, #slo do
    if getPlayerSlotItem(cid, slo[i]).itemid == 0 then
    for i = 0, #items do
        if (items[i].chance > math.random(1, 100)) then
            doPlayerSetMaxCapacity(cid, getPlayerFreeCap(cid) + 100)
            doPlayerAddItem(cid, items[i].id, items[i].count)
            doRemoveItem(item.uid, 1)
            return doCreatureSay(cid, 'I congratulate you won item! This item is '..getItemNameById(items[i].id)..'!', TALKTYPE_MONSTER)
            end
        end
    end
end
    doRemoveItem(item.uid, 1)
    return doCreatureSay(cid, 'Sorry, have not won anything!', TALKTYPE_MONSTER)
end
like this ?
Code:
items = {

    [0] = {id = 2328, count = 1, chance = 2},
    [1] = {id = 2157, count = 1, chance = 5},
    [2] = {id = 7722, count = 1, chance = 10},
    [3] = {id = 2195, count = 1, chance = 15},
    [4] = {id = 2160, count = 10, chance = 30},
    [5] = {id = 6569, count = 50, chance = 100}
}
function onUse(cid, item, fromPos, itemEx, toPos)
    local slo = {CONST_SLOT_NECKLACE, CONST_SLOT_BACKPACK, CONST_SLOT_HEAD, CONST_SLOT_ARMOR, CONST_SLOT_LEGS, CONST_SLOT_FEET, CONST_SLOT_RING, CONST_SLOT_RIGHT, CONST_SLOT_LEFT, CONST_SLOT_AMMO}
    for i = 1, #slo do
    if getPlayerSlotItem(cid, slo[i]).itemid >= 1 then
        doCreatureSay(cid, "Please empty out all your slots first including backpack.", 19)
        return true
    end
    for i = 1, #slo do
    if getPlayerSlotItem(cid, slo[i]).itemid == 0 then
    for i = 0, #items do
        if (items[i].chance > math.random(1, 100)) then
            doPlayerSetMaxCapacity(cid, getPlayerFreeCap(cid) + 100)
            doPlayerAddItem(cid, items[i].id, items[i].count) 
            doRemoveItem(item.uid, 1)
            return doCreatureSay(cid, 'I congratulate you won item! This item is '..getItemNameById(items[i].id)..'!', TALKTYPE_MONSTER)
            end
        end
end
    doRemoveItem(item.uid, 1)
    return doCreatureSay(cid, 'Sorry, have not won anything!', TALKTYPE_MONSTER)
end
 
Before you guys get more frustrated, here's my version that I explained would work in my last post..
Code:
getPlayerSlotItem(cid, slot)
Use above and loop through each slot verifying if there is an item there.
Code:
local items = {
     [0] = {id = 2328, count = 1, chance = 2},
     [1] = {id = 2157, count = 1, chance = 5},
     [2] = {id = 7722, count = 1, chance = 10},
     [3] = {id = 2195, count = 1, chance = 15},
     [4] = {id = 2160, count = 10, chance = 30},
     [5] = {id = 6569, count = 50, chance = 100}
}
function onUse(cid, item, fromPos, itemEx, toPos)
     for i = 1, 10 do
         if getPlayerSlotItem(cid, i).itemid ~= 0 then
             doPlayerSendCancel(cid, "All inventory slots must be empty to consume this item.")
             doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
             return true
         end
     end
     for i = 0, #items do
         if (items[i].chance > math.random(1, 100)) then
             -- doPlayerSetMaxCapacity(cid, getPlayerFreeCap(cid) + 100)
             doPlayerAddItem(cid, items[i].id, items[i].count)   
             doRemoveItem(item.uid, 1)
             return doCreatureSay(cid, 'I congratulate you won item! This item is '..getItemNameById(items[i].id)..'!', TALKTYPE_MONSTER)
         end
     end
     doRemoveItem(item.uid, 1)
     return doCreatureSay(cid, 'Sorry, have not won anything!', TALKTYPE_MONSTER)
end
 
Before you guys get more frustrated, here's my version that I explained would work in my last post..

Code:
local items = {
     [0] = {id = 2328, count = 1, chance = 2},
     [1] = {id = 2157, count = 1, chance = 5},
     [2] = {id = 7722, count = 1, chance = 10},
     [3] = {id = 2195, count = 1, chance = 15},
     [4] = {id = 2160, count = 10, chance = 30},
     [5] = {id = 6569, count = 50, chance = 100}
}
function onUse(cid, item, fromPos, itemEx, toPos)
     for i = 1, 10 do
         if getPlayerSlotItem(cid, i).itemid ~= 0 then
             doPlayerSendCancel(cid, "All inventory slots must be empty to consume this item.")
             doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
             return true
         end
     end
     for i = 0, #items do
         if (items[i].chance > math.random(1, 100)) then
             -- doPlayerSetMaxCapacity(cid, getPlayerFreeCap(cid) + 100)
             doPlayerAddItem(cid, items[i].id, items[i].count)  
             doRemoveItem(item.uid, 1)
             return doCreatureSay(cid, 'I congratulate you won item! This item is '..getItemNameById(items[i].id)..'!', TALKTYPE_MONSTER)
         end
     end
     doRemoveItem(item.uid, 1)
     return doCreatureSay(cid, 'Sorry, have not won anything!', TALKTYPE_MONSTER)
end
i get this doPlayerSendCancel(cid, "All inventory slots must be empty to consume this item.") message even if i have space in bp or inventory
 
Let's add some prints then.
Send some screenshots of your client + console if it doesn't work.
Code:
local items = {
    [0] = {id = 2328, count = 1, chance = 2},
    [1] = {id = 2157, count = 1, chance = 5},
    [2] = {id = 7722, count = 1, chance = 10},
    [3] = {id = 2195, count = 1, chance = 15},
    [4] = {id = 2160, count = 10, chance = 30},
    [5] = {id = 6569, count = 50, chance = 100}
}
function onUse(cid, item, fromPos, itemEx, toPos)
    for i = 1, 10 do
        print("item_id " .. getPlayerSlotItem(cid, i).itemid .. " found in slot " .. i .. ".")
        if getPlayerSlotItem(cid, i).itemid ~= 0 then
            print("Inventory slot " .. i .." is not empty. Stopping script. Sending player cancel message.")
            doPlayerSendCancel(cid, "All inventory slots must be empty to consume this item.")
            doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
            return true
        end
    end
    print("All inventory slots are empty! Attempting rest of script.")
    for i = 0, #items do
        if (items[i].chance > math.random(1, 100)) then
            -- doPlayerSetMaxCapacity(cid, getPlayerFreeCap(cid) + 100)
            doPlayerAddItem(cid, items[i].id, items[i].count) 
            doRemoveItem(item.uid, 1)
            return doCreatureSay(cid, 'I congratulate you won item! This item is '..getItemNameById(items[i].id)..'!', TALKTYPE_MONSTER)
        end
    end
    doRemoveItem(item.uid, 1)
    return doCreatureSay(cid, 'Sorry, have not won anything!', TALKTYPE_MONSTER)
end
 
And people say i cannot script...What TFS are you using?

edit: If you are using tfs 0.3.6 - 0.4.0 try using this maybe?

Code:
<attribute key="Capacity" value="10"/>
<attribute key="addCap" value="8"/>
<attribute key="cappoints" value="5"/>

Will edit this post for more solutions.

Code:
doPlayerSetMaxCapacity(cid, getPlayerFreeCap(cid)-anything)
 

Similar threads

Back
Top