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

Problem Fixed!

Lava Titan

Developer
Joined
Jul 25, 2009
Messages
1,571
Solutions
3
Reaction score
98
Location
Portugal
Yo otland ppl.
I wanted to request help in a script:

A chest that gives 1 random item.
When you use the chest it haves 10 items inside but it will only give 1 item randomly.

And after a player open the chest it will say:

You found a "itemname"!

After you open the chest it will set the storage value: 11994

When you try to open the chest on the 2nd time it will says:

You already opened this chest!
 
Here, just change the XXXX's to what you want. I know the script is messy, but I tried my best. Also, I can't figure out how to make it say "You've recieved |ITEMNAME|." Maybe a more experienced scripter will help you.

LUA:
local prizes = {
    { item = xxxx, count = 1 },
    { item = xxxx, count = 1 },
    { item = xxxx, count = 1 },
    { item = xxxx, count = 1 },
    { item = xxxx, count = 1 },
    { item = xxxx, count = 1 },
    { item = xxxx, count = 1 },
    { item = xxxx, count = 1 },
    { item = xxxx, count = 1 },
    { item = xxxx, count = 1 }
}

local storage = 11994

function onUse(cid, item, fromPosition, itemEx, toPosition)
	if getPlayerStorageValue(cid, storage) ~= 1 then
local random = math.random(1, #prizes)
		doPlayerAddItem(cid, prizes[random].item, prizes[random].count)
		 doPlayerSendTextMessage(cid, 22, "You've found an item!!")
		setPlayerStorageValue(cid, storage, 1)
	 else
	 doPlayerSendTextMessage(cid, 22, "You already opened this chest!")
end
return TRUE
end
 
Here, just change the XXXX's to what you want. I know the script is messy, but I tried my best. Also, I can't figure out how to make it say "You've recieved |ITEMNAME|." Maybe a more experienced scripter will help you.

LUA:
local prizes = {
    { item = xxxx, count = 1 },
    { item = xxxx, count = 1 },
    { item = xxxx, count = 1 },
    { item = xxxx, count = 1 },
    { item = xxxx, count = 1 },
    { item = xxxx, count = 1 },
    { item = xxxx, count = 1 },
    { item = xxxx, count = 1 },
    { item = xxxx, count = 1 },
    { item = xxxx, count = 1 }
}

local storage = 11994

function onUse(cid, item, fromPosition, itemEx, toPosition)
	if getPlayerStorageValue(cid, storage) ~= 1 then
local random = math.random(1, #prizes)
		doPlayerAddItem(cid, prizes[random].item, prizes[random].count)
		 doPlayerSendTextMessage(cid, 22, "You've found an item!!")
		setPlayerStorageValue(cid, storage, 1)
	 else
	 doPlayerSendTextMessage(cid, 22, "You already opened this chest!")
end
return TRUE
end

Dont be so harsh on yourself mate :D it is a clean script :) Probably some pr0pr0 can shorten it like always but I dont think it is messy at all, good job Ill +Reppek you :thumbup:

Btw for the item name part, you only need to add the getItemNameById(itemid) function in there, like this:

LUA:
doPlayerSendTextMessage(cid, 22, "You've found a " .. getItemNameById(prizes[random].item) .. "!")

And thats all :)

Cheerz.
 
Dont be so harsh on yourself mate :D it is a clean script :) Probably some pr0pr0 can shorten it like always but I dont think it is messy at all, good job Ill +Reppek you :thumbup:

Btw for the item name part, you only need to add the getItemNameById(itemid) function in there, like this:

LUA:
doPlayerSendTextMessage(cid, 22, "You've found a " .. getItemNameById(prizes[random].item) .. "!")

And thats all :)

Cheerz.

Thanks for the tips, and yeah I just recently started trying to learn lua etc. I repped you for the help :p
Thanks
 
Sorry for desturbing but need again help >.<

I had a new idea and i want to remove the storage value to the item be used many times =/.

How can i remove it? (the storage value)

Script:

LUA:
  local prizes = {
    { item = 2196, count = 1 },
	{ item = 5958, count = 1 },
	{ item = 1967, count = 1 },
	{ item = 2345, count = 1 },
	{ item = 5802, count = 1 },
	{ item = 6103, count = 1 },
	{ item = 6119, count = 1 },
	{ item = 7722, count = 1 },
	{ item = 10503, count = 1 },
	{ item = 9778, count = 1 },
	{ item = 8879, count = 1 },
	{ item = 9928, count = 1 },
	{ item = 7892, count = 1 },
	{ item = 2537, count = 1 },
	{ item = 2128, count = 1 },
	{ item = 8880, count = 1 },
	{ item = 9777, count = 1 },
	{ item = 6391, count = 1 },
	{ item = 9933, count = 1 },
	{ item = 2275, count = 1 },
	{ item = 2297, count = 1 },
	{ item = 8855, count = 1 },
	{ item = 7840, count = 1 },
	{ item = 7411, count = 1 },
	{ item = 7422, count = 1 },
	{ item = 7408, count = 1 },
	{ item = 7451, count = 1 },
	{ item = 6534, count = 1 },
	{ item = 7461, count = 1 },
	{ item = 2505, count = 1 },
	{ item = 2507, count = 1 },
	{ item = 2358, count = 1 },
	{ item = 3975, count = 1 },
	{ item = 9775, count = 1 },
	{ item = 2267, count = 1 },
	{ item = 2296, count = 1 },
	{ item = 2300, count = 1 },
	{ item = 7427, count = 1 },
	{ item = 7435, count = 1 },
	{ item = 7416, count = 1 },
	{ item = 7438, count = 1 },
	{ item = 2352, count = 1 },
	{ item = 7426, count = 1 },
	{ item = 7958, count = 1 }
	
}

local storage = 12994

function onUse(cid, item, fromPosition, itemEx, toPosition)
        if getPlayerStorageValue(cid, storage) ~= 1 then
local random = math.random(1, #prizes)
                doPlayerAddItem(cid, prizes[random].item, prizes[random].count)
                 doCreatureSay(cid, "You've found a " .. getItemNameById(prizes[random].item) .. "!" ,19)
                setPlayerStorageValue(cid, storage, 1)
         else
         doCreatureSay(cid, "You already done this quest!" ,19)
end
return TRUE
end
 
Its no problem :p
LUA:
 local prizes = {
    { item = 2196, count = 1 },
        { item = 5958, count = 1 },
        { item = 1967, count = 1 },
        { item = 2345, count = 1 },
        { item = 5802, count = 1 },
        { item = 6103, count = 1 },
        { item = 6119, count = 1 },
        { item = 7722, count = 1 },
        { item = 10503, count = 1 },
        { item = 9778, count = 1 },
        { item = 8879, count = 1 },
        { item = 9928, count = 1 },
        { item = 7892, count = 1 },
        { item = 2537, count = 1 },
        { item = 2128, count = 1 },
        { item = 8880, count = 1 },
        { item = 9777, count = 1 },
        { item = 6391, count = 1 },
        { item = 9933, count = 1 },
        { item = 2275, count = 1 },
        { item = 2297, count = 1 },
        { item = 8855, count = 1 },
        { item = 7840, count = 1 },
        { item = 7411, count = 1 },
        { item = 7422, count = 1 },
        { item = 7408, count = 1 },
        { item = 7451, count = 1 },
        { item = 6534, count = 1 },
        { item = 7461, count = 1 },
        { item = 2505, count = 1 },
        { item = 2507, count = 1 },
        { item = 2358, count = 1 },
        { item = 3975, count = 1 },
        { item = 9775, count = 1 },
        { item = 2267, count = 1 },
        { item = 2296, count = 1 },
        { item = 2300, count = 1 },
        { item = 7427, count = 1 },
        { item = 7435, count = 1 },
        { item = 7416, count = 1 },
        { item = 7438, count = 1 },
        { item = 2352, count = 1 },
        { item = 7426, count = 1 },
        { item = 7958, count = 1 }
       
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
local random = math.random(1, #prizes)
                doPlayerAddItem(cid, prizes[random].item, prizes[random].count)
                 doCreatureSay(cid, "You've found a " .. getItemNameById(prizes[random].item) .. "!" ,19)
          return TRUE
end
 
Back
Top