Jump to content

Item Limits and Other Item-Related Questions


St.Matthew

Recommended Posts

*If it helps, I'm using Urwigo. I'm trying to set up my first Wherigo Cartridge that utilizes Items.

 

Question 1: Is there a way to limit the number of items a zone can contain? For example, a zone is a treasure chest. The player tries to put an item in the chest, but since the chest already contains an item, the player receives a message that states, "Sorry, a treasure chest may only hold one item at a time."

 

Question 2: In the cartridge, each item in the game has two commands, "Take" and "Place," which are used to move items from zones to inventory and back as needed. Imagine that the player goes to a zone that is a treasure chest. He moves to that zone, looks at his items, and sees his sword. He clicks on sword, and using the "Place" command, moves the item from his inventory to the zone. He receives a message, "You have successfully placed the sword in the treasure chest." Up to this point, I'm fine in the programming. My concern is this: After clicking "ok" on the "You have successfully placed the sword in the treasure chest" message, the screen is still in the item's commands, despite the fact that the item has been successfully moved out of their inventory and into the zone. The player could get confused and continue to hit "Place" and keep getting the message over and over. Is there a way to force a player back to the main menu, or are there other ways to prevent what I have mentioned?

 

Most appreciated,

-Matt

Link to comment

*If it helps, I'm using Urwigo. I'm trying to set up my first Wherigo Cartridge that utilizes Items.

 

Question 1: Is there a way to limit the number of items a zone can contain? For example, a zone is a treasure chest. The player tries to put an item in the chest, but since the chest already contains an item, the player receives a message that states, "Sorry, a treasure chest may only hold one item at a time."

 

Question 2: In the cartridge, each item in the game has two commands, "Take" and "Place," which are used to move items from zones to inventory and back as needed. Imagine that the player goes to a zone that is a treasure chest. He moves to that zone, looks at his items, and sees his sword. He clicks on sword, and using the "Place" command, moves the item from his inventory to the zone. He receives a message, "You have successfully placed the sword in the treasure chest." Up to this point, I'm fine in the programming. My concern is this: After clicking "ok" on the "You have successfully placed the sword in the treasure chest" message, the screen is still in the item's commands, despite the fact that the item has been successfully moved out of their inventory and into the zone. The player could get confused and continue to hit "Place" and keep getting the message over and over. Is there a way to force a player back to the main menu, or are there other ways to prevent what I have mentioned?

 

Most appreciated,

-Matt

 

1. There's a way to check the number of items, I never used it but someone will let you know how to do it...

 

2.

You can ativate and disactivate item commands.

If the player has the item in his posession it's logical that it only has the command "Place" activated. Once you drop it, it ony makes sence that the item have the command "Take"...That way the playerwill always know what he can do with the object...

Link to comment

Sorry, a little bit late.

 

1. You had to count all items in your inventory by a function:

 

function CountItems()
 local varNum = 0
 -- Number of items in Player.Inventory
 for k,v in pairs(Player.Inventory) do
   if v.Visible == true then
     varNum = varNum + 1
   end
 end
 return varNum
end

 

2. The answer of MightyReek is correct. If you didn't want thinking about your standard commands, use some function.

 

-- You should change here your text for take and drop
ComfortItemsTakeText = "Take"
ComfortItemsDropText = "Drop"
ComfortItemsDropError = "Sorry, you couldn't drop this item here."
ComfortItemsTakeMax = 1
ComfortItemsTakeMaxText = "Sorry, you are already carrying one item."""

function ComfortItemsAdd(parCart,parItems)
 -- Add the commands Take and Drop to all items or to all items in the list parItems
 local tabItems = {}
 -- Get all items
 -- Did this, because GetAllOfType did not work for OpenWIG
 for k,v in pairs(parCart.AllZObjects) do
   if tostring(v) == "a ZItem instance" then
     if parItems == nil then
       -- Do it for all items
       table.insert(tabItems,v)
     else
       -- Do it for selected items
       for j,w in pairs(parItems) do
         if w == v then
           table.insert(tabItems,v)
         end
       end     
     end
   end
 end
 -- Now add commands to all items in tabItems
 for k,v in pairs(tabItems) do
   local tabCommands = {}
   -- Add all existing commands to table
   for j,w in pairs(v.Commands) do
     tabCommands[w.Text] = w
   end
   -- Add new commands
   if tabCommands[ComfortItemsTakeText] == nil then
     tabCommands[ComfortItemsTakeText] = Wherigo.ZCommand{Text=ComfortItemsTakeText, CmdWith=false, Enabled=true, Custom = true, WorksWithAll = true}
     v["On"..ComfortItemsTakeText] = ComfortItemsTake
   end
   if tabCommands[ComfortItemsDropText] == nil then
     tabCommands[ComfortItemsDropText] = Wherigo.ZCommand{Text=ComfortItemsDropText, CmdWith=false, Enabled=false, Custom = true, WorksWithAll = true}
     v["On"..ComfortItemsDropText] = ComfortItemsDrop
   end
   v.Commands = tabCommands
 end
end

function ComfortItemsDrop(self)
  -- Get first active zone the player is in
  local varZone = nil
  if # Player.InsideOfZones > 0 then
    varZone = Player.InsideOfZones[1]
  end
  -- Is player in a zone
  if varZone ~= nil then
    -- Yes, player is in a zone
    -- Move item zo active zone
    self:MoveTo(varZone)
    -- Change command buttons
    if self.Commands[ComfortItemsTakeText] ~= nil then self.Commands[ComfortItemsTakeText].Enabled = true end
    if self.Commands[ComfortItemsDropText] ~= nil then self.Commands[ComfortItemsDropText].Enabled = false end
    -- Special code for only one item
    -- if self == zitemYourItem then
      -- Do it here
    -- end
  else
    -- No, player is not in a zone
    Wherigo.MessageBox{Text=ComfortItemsDropError,Buttons={"Ok",},}
  end
end

function ComfortItemsTake(self)
 if (ComfortItemsTakeMax > 0) and (CountItems() >= ComfortItemsTakeMax) then
    -- Player has already ComfortItemsTakeMax items in inventory
    Wherigo.MessageBox{Text=ComfortItemsTakeMaxText,Buttons={"Ok",},}
    return
 end
 -- Move item to inventory
 self:MoveTo(Player)
 -- Change command buttons
 if self.Commands[ComfortItemsTakeText] ~= nil then self.Commands[ComfortItemsTakeText].Enabled = false end
 if self.Commands[ComfortItemsDropText] ~= nil then self.Commands[ComfortItemsDropText].Enabled = true end
 -- Special code for only one item
 -- if self == zitemYourItem then
   -- Do it here
 -- end
end

function CountItems()
 local varNum = 0
 -- Number of items in Player.Inventory
 for k,v in pairs(Player.Inventory) do
   if v.Visible == true then
     varNum = varNum + 1
   end
 end
 return varNum
end

How to use it? Put the code in your Author Script section and call the function ComfortItemsAdd(parCart,parItems) with the name of your cartridge and a table with items, which you want to have standard take and drop, like ComfortItemsAdd(cartTest) (for all items) or ComfortItemsAdd(cartTest,{zitemItem1,zitemItem2,zitemItem4}) (only for special items) in OnStart. Ready. You now have the commands "Take" and "Drop" for all items or the items zitemItem1,zitemItem2,zitemItem4. You could carry only ComfortItemsTakeMax (if is greater than 0). If you have more, you get a message with text ComfortItemsTakeMaxText. If you try to drop an item outside a zone, you get the message ComfortItemsDropError. That's it.

 

If your items have other commands, no problem, they are not replaced. If some of your items have their own Take and Drop commands, no problem, they are not replaced. If you want special code for one item, place it below the line -- Special code for only one item (example is already there.

 

Good luck!

Link to comment

It takes 10 minutes to answer in english, I better waste 5 minutes for the source code <_< You have a hammer and a flashlight, you can only place 1 item. If an item was put, the command becomes invisible and the take command appears. And in the example the player must be inside the zone.

 

post-3481440-007667100 1355588428_thumb.jpg

 

Thanks everyone, espcially jonny! Your Urwigo screenshot is so helpful, and it works perfectly.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...