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

Choose between 2 rewards.

Majeski20

New Member
Joined
Apr 21, 2008
Messages
602
Reaction score
4
Location
Sweden
Hello! :w00t:

I want to know how i can choose only 1 reward from 2 chests.

example:

I will make a quest, and you can choose between Necromancer shield and Nightmare shield.

Thanks! :)
 
Do like this:
Place two chests next to each other and when the player opens a chest, the player gets a storagevalue for the both chests, so he can't open the chest again...

action.xml:
XML:
<action actionid="6216" event="script" value="twochest.lua"/>
	<action actionid="6215" event="script" value="twochest2.lua"/>

twochest.lua:
LUA:
local storage = 4918410
local reward = 6433
local count = 1
function onUse(cid, item, fromPosition, itemEx, toPosition)
	if item.itemid == 1740 or item.itemid == 1747 or item.itemid == 1748 or item.itemid == 1749 then
		if getPlayerStorageValue(cid, storage) == -1 then
			doPlayerAddItem(cid, reward, count)
			setPlayerStorageValue(cid, storage, 1)
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You found a Necromancer Shield!") 
		else
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "It is empty. You've already chosed your reward.")
			return true
		end
	end
end

twochest2.lua:
LUA:
local storage = 4918410
local reward = 6391
local count = 1
function onUse(cid, item, fromPosition, itemEx, toPosition)
	if item.itemid == 1740 or item.itemid == 1747 or item.itemid == 1748 or item.itemid == 1749 then
		if getPlayerStorageValue(cid, storage) == -1 then
			doPlayerAddItem(cid, reward, count)
			setPlayerStorageValue(cid, storage, 1)
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You found a Nightmare Shield!") 
		else
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "It is empty. You've already chosed your reward.")
			return true
		end
	end
end
 
Last edited:
Do like this:
Place two chests next to each other and when the player opens a chest, the player gets a storagevalue for the both chests, so he can't open the chest again...

action.xml:
XML:
<action actionid="6216" event="script" value="twochest.lua"/>
	<action actionid="6215" event="script" value="twochest2.lua"/>

twochest.lua:
LUA:
local storage = 4918410
local reward = 6433
local count = 1
function onUse(cid, item, fromPosition, itemEx, toPosition)
	if item.itemid == 1740 or item.itemid == 1747 or item.itemid == 1748 or item.itemid == 1749 then
		if getPlayerStorageValue(cid, storage) == -1 then
			doPlayerAddItem(cid, reward, count)
			setPlayerStorageValue(cid, storage, 1)
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You found a Necromancer Shield!") 
		else
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "It is empty. You've already chosed your reward.")
			return true
		end
	end
end

twochest2.lua:
LUA:
local storage = 4918410
local reward = 6391
local count = 1
function onUse(cid, item, fromPosition, itemEx, toPosition)
	if item.itemid == 1740 or item.itemid == 1747 or item.itemid == 1748 or item.itemid == 1749 then
		if getPlayerStorageValue(cid, storage) == -1 then
			doPlayerAddItem(cid, reward, count)
			setPlayerStorageValue(cid, storage, 1)
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You found a Nightmare Shield!") 
		else
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "It is empty. You've already chosed your reward.")
			return true
		end
	end
end


Thanks man, rep !
 
Those scripts above seem to work just fine, however the following should make things more convenient by combining the two into one script. You will still obviously need two chests. The numbers within the brackets are the actionid's and the storage values that will be used.

LUA:
local t = {
	[15001] = {6433, 1},
	[15002] = {6391, 1}
}
 
function onUse(cid, item, fromPosition, itemEx, toPosition)
	local v = t[item.actionid]
	if v then
		if getCreatureStorage(cid, v) < 0 then
			doCreatureSetStorage(cid, v, 1)
 
			local reward = doCreateItemEx(v[1], v[2] or 1)
			if(doPlayerAddItemEx(cid, reward, true) ~= RETURNVALUE_NOERROR) then
				return false
			end
 
			doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
			doCreatureSay(cid, "You have found a " .. getItemInfo(v[1]).name .. "!")
		else
			doPlayerSendCancel(cid, "The " .. getItemInfo(item.uid).name .. " is empty.")
		end
	end
 
	return true
end
 
I'm having some trouble with my script, neither of the above work for me. I'm using 0.2.10 mystic spirit, and doing the following...


In actions.xml I put

Code:
<action actionid="6501" event="script" value="startingweapon1.lua"/>
In scripts/quests (startingweapon1.lua) I put

Code:
function onUse(cid, item, frompos, item2, topos)  
local config = {
[7001] = {loot=2160},
[7002] = {loot=2161},
[7003] = {loot=2162}
--etc
}
local storage = 0001 -- the quest storage
 
local cap = getPlayerFreeCap(cid)
local reward = config[item.uid].item
 
      if reward then
         if cap < (getItemWeight(always,1) + getItemWeight(reward,1)) then
            if getPlayerStorageValue(cid,storage) == -1 then
               doPlayerAddItem(cid,reward,1)
               doPlayerSendTextMessage(cid,22,"You've obtained a " ..getItemNameById(reward)"!")
            else
                doPlayerSendCancel(cid, "The Chest is Empty!")
            end
         else
             doPlayerSendCancel(cid, "You do not have enough cap!")
         end
      end
return true
end
I have 3 chests, in the action ID I put 6501 for all 3, and for the unique ID I put 7001, 7002, 7003, one in each. All it gives me are items relivant to 7001 etc in the map editor, how do I fix this? I want them to only take 1 item from the 3.
 
Last edited:
Do like this:
Place two chests next to each other and when the player opens a chest, the player gets a storagevalue for the both chests, so he can't open the chest again...

action.xml:
XML:
<action actionid="6216" event="script" value="twochest.lua"/>
	<action actionid="6215" event="script" value="twochest2.lua"/>

twochest.lua:
LUA:
local storage = 4918410
local reward = 6433
local count = 1
function onUse(cid, item, fromPosition, itemEx, toPosition)
	if item.itemid == 1740 or item.itemid == 1747 or item.itemid == 1748 or item.itemid == 1749 then
		if getPlayerStorageValue(cid, storage) == -1 then
			doPlayerAddItem(cid, reward, count)
			setPlayerStorageValue(cid, storage, 1)
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You found a Necromancer Shield!") 
		else
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "It is empty. You've already chosed your reward.")
			return true
		end
	end
end

twochest2.lua:
LUA:
local storage = 4918410
local reward = 6391
local count = 1
function onUse(cid, item, fromPosition, itemEx, toPosition)
	if item.itemid == 1740 or item.itemid == 1747 or item.itemid == 1748 or item.itemid == 1749 then
		if getPlayerStorageValue(cid, storage) == -1 then
			doPlayerAddItem(cid, reward, count)
			setPlayerStorageValue(cid, storage, 1)
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You found a Nightmare Shield!") 
		else
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "It is empty. You've already chosed your reward.")
			return true
		end
	end
end
Lfmao... you don't need this script ^^
 

Similar threads

Back
Top