• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Need some help with a script :d

Serginov

Onkonkoronkonk
Joined
Jun 28, 2008
Messages
1,321
Reaction score
18
Location
Sweden - Dalarna
I want the text to be like "You found a that, a that, a that and a that" and to get the cap out of all items(I don't know if it will work as I have it now) when you open the chest depending how many items there is configured. Here's the script so far(Please correct any misstakes too or stuff that won't work :p);
Code:
local chests = {
    [8560] = {storage = 1000, items = {1234, 1235, 1236}},
    [8561] = {storage = 1001, items = {2412, 3431}},
    [8562] = {storage = 1002, items = {3531, 9481, 3987, 9313}},
    }
    
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local v = chests[item.uid]
    for _,c in ipairs(v.items) do
        if v then
            if getCreatureStorage(cid, v.storage) ~= 1 then
                if getPlayerFreeCap(cid) >= getItemWeightById(c) then
                    doCreatureSetStorage(cid, v.storage, 1)
                    doPlayerAddItem(cid, c, 1)
                    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You found a that a that a that a that and a that!")
                else
                    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You don't have enough capiticity!")
                end
            else
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "It is empty.")
            end
        end
    end
    return true
end
 
Code:
local chests = {
    [8560] = {storage = 1000, items = {1234, 1235, 1236}},
    [8561] = {storage = 1001, items = {2412, 3431}},
    [8562] = {storage = 1002, items = {3531, 9481, 3987, 9313}},
    }
    
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local v = chests[item.uid]
    for _,c in ipairs(v.items) do
        if v then
            if getPlayerStorageValue(cid, v.storage) ~= 1 then
                if getPlayerFreeCap(cid) >= getItemWeightById(c) then
                    SetPlayerStorageValue(cid, v.storage, 1)
                    doPlayerAddItem(cid, c, 1)
                    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You found a " ..getItemNameById(c).. ".")
                else
                    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You don't have enough capiticity!")
                end
            else
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "It is empty.")
            end
        end
    end
    return true
end

fixed some problems, but currently you have it only set to 1 item to receive, do you want it to get all of the items?
 
try this

LUA:
local chests = {
	[8560] = {storage = 1000, items = {1234, 1235, 1236}},
	[8561] = {storage = 1001, items = {2412, 3431}},
	[8562] = {storage = 1002, items = {3531, 9481, 3987, 9313}},
}
    
function onUse(cid, item, fromPosition, itemEx, toPosition)
local l,lc = {},0
local v = chests[item.uid]
	if v then
		if getCreatureStorage(cid, v.storage) ~= 1 then
			for i = 1,#v.items do
				lc = lc+getItemWeightById(v.items[i])
			end
			if getPlayerFreeCap(cid) >= lc then
				doCreatureSetStorage(cid, v.storage, 1)
				for i = 1,#v.items do
					doPlayerAddItem(cid,v.items[i],1)
					table.insert(l,getItemNameById(v.items[i]))
				end
				doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR,'You found these items: '..table.concat(l,', ')..'.')
			else
				doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You don't have enough capiticity!")
			end
		else
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "It is empty.")
		end
	end
return true
end
 
Back
Top