Main
Projects
Art
Music
Scripting
LiveJournal
Forum
Links
If you want the hero to only be able to hold a certain number of items, then this is the script for you. I was thinking about making one, actually.


#the following scripts are used to place limits on how many different items a hero can hold in
#his inventory at one time.


define script (1,Item Limits Shopping,none)
define script (2,Item Limits Obtainable,none)
define script (3,Inventory Check,none)
define script (4,Strip Items,none)
define script (5,Item Tag Reset,none)
define script (6,Shopkeeper,none)
define script (7,Collecting,none)

global variable (1,items) #item marker tags--will be explained in detail later.


#Special Note--all items in the game file must have tags assigned to them for these scripts
#to work.  It is also important to make sure the tags are assigned in order.  Otherwise you'll
#have to write everything out the long way.

#Special Note 2--these specific examples limit the player to 8 items maximum at a time.  The
#number of items allowed will depend on how many items the script is set to limit.

#--------------------------------------------------------

#this first script tests HOW MANY items the player is currently carrying.  It works by activating
#a tag every time it finds a new item.  Items are found by their inventory tag markers, which you
#must assign in the items edit list.

#This example is used for item shops.

script,Item Limits Shopping,begin

variable (i) #looks for each individual item
variable (n) #turns each inventory tag off
variable (t) #inventory tags--the tags that are turned on whenever a new item is found
variable (item tag) #the tag you assign to a specific item
variable (inventory tag) #turns each inventory tag on


# this section turns all the inventory tags off so that the script starts with a clean slate.

#please note that the example calls for 8 inventory tags, which is how many items the scripts
#are limiting the player to carry at one time.  The tags range from Tag 14 to Tag 21.

 
set variable (t,14) #in this case, Tag 14 is the first inventory tag.  Adjust to fit your script.

for (n,1,8) #this runs through all your inventory tags.  In this case, there are 8 tags.
do(
set tag (t,OFF) #starts by setting Tag 14 off.
set variable (t,t+1) #then it sets the variable to turn off Tag 15, 16, 17, etc., all the way
                     #to Tag 21.
)


#okay, now it's time to see how many different items you're carrying.
#please note that it is not searching for the quantity of each specific item.


set variable (item tag,2) #in this case, Tag 2 is the first tag used on an item--the first item.
set variable (inventory tag,14) #same as the section above

for (i,1,12) #begins searching your inventory.  In this case, there are 12 items in the game.
do(
if (checktag (item tag)) then( #checks to see if the first item is present by testing its tag.
set tag (inventory tag,ON)) #if the item is detected, it turns on the first inventory tag.
set variable (item tag,item tag+1) #prepares the script to check for the next item.
if (checktag (inventory tag)) then( #if an item is found and the inventory tag is activated...
set variable (inventory tag,inventory tag+1)) #it prepares the next inventory tag.
)
end


#please note that this script will check for every possible item, but only return those items
#that are currently in your inventory.  Also know that the first seven inventory tags are mostly
#unimportant to setting your limits, but the last assigned inventory tag is vitally important.
#In this case, Tag 21 represents the eighth item, which makes any item acquired past that in
#violation of the set item limits.

#if you want to allow a different amount of items to be carried at one time, set a different
#amount of inventory tags.
 
#-----------------------------------------------------------------------------

#the next script is exactly like the first script, but carries a different name for a point
#of reference.  In this case, this script is used specifically for items picked up on the field.


script,Item Limits Obtainable,begin

variable (i)
variable (n)
variable (t)
variable (item tag)
variable (inventory tag)
set variable (t,14)
for (n,1,8)
do(
set tag (t,OFF)
set variable (t,t+1)
)
set variable (item tag,2)
set variable (inventory tag,14)
for (i,1,12)
do(
if (checktag (item tag)) then(
set tag (inventory tag,ON))
set variable (item tag,item tag+1)
if (checktag (inventory tag)) then(
set variable (inventory tag,inventory tag+1))
)
end


#Last Minute Note--

#one thing to keep in mind is that these scripts handle shop limits and field item limits a
#little differently.  Even though the 8 inventory tags detect 8 items perfectly on field items,
#which are those items collected through NPCs, I have found that the eighth inventory tag
#prevents the player from buying the eighth item from a shop.  You may want to consider making
#Tag 22 a spare inventory tag and set the script to check for 9 inventory tags.  That's up to you
#though.

#------------------------------------------------------------------------

#this next script tests WHICH items the hero is carrying.  This script is allows the game to
#remember what the hero already has before adding a new item.

#please note that this script is vitally important to allow the hero to keep items collected
#within the limit boundaries.

#also note that Tags 22-33 in this example reference secondary item tags.  These tags serve as
#item markers, which means if the player is carrying a specific item, the script will turn on
#its corresponding marker.  This idea will make more sense in the next script.


script,Inventory Check,begin

variable (n) #counts how many of each item the hero is carrying
variable (c) #searches for the presence of all possible items
variable (i) #the assigned item number--not the tag number

set variable (i,0) #starts the inventory check with the first item.  This number should always
                   #be zero.
set variable (items,22) #global variable--prepares the first item marker (Tag 22) for use.

for (c,1,12) #tests all 12 items
do(
set variable (n,inventory (i)) #writes the quantity of a specific item to the variable
if (n>=1) then( #this essentially tests whether or not the item is present.  If there are one
                #or more copies of the tested item, it will move on to the next step.
set tag (items,ON)) #if the item is present, it will turn on its assigned item marker tag.
set variable (i,i+1) #this prepares the next item on the list
set variable (items,items+1) #this prepares the next item marker on the list.
)
end


#please note that the item markers work differently than the inventory tags from the previous
#scripts.  Item markers progress with each loop counter, while the inventory tags from the
#Item Limits scripts only progress when a new item is found. 

#--------------------------------------------------------------------

#the next script acts like a police officer in that it takes away any item(s) that exceeds
#the item limit.  This is especially useful for those shopping moments when the player thinks
#he can be slick and get away with buying 10 or more items at a time.


script,Strip Items,begin

variable (num) #the quantity of a specific item--used for replenishing an existing supply
variable (n) #the quantity of a specific item--used for testing an item's presence
variable (c) #tests all available items
variable (i) #the item number

set variable (i,0) #sets the variable to the first item number (always zero).
set variable (items,22) #sets the global variable to the first item marker.

#please note that the rest of the script will strip away all items completely, and add back
#only the items that have their corresponding item marker tags turned on.

for (c,1,12) #searches for all items
do(
set variable (num,inventory (i)) #sets the quantity of the tested item.
set variable (n,inventory (i)) #same as above
if (n>=1) then( #tests if the item is present.
delete item (i,num)) #deletes all copies of a specific item from the inventory.
if (checktag (items)) then( #tests to see if the item marker has been turned on.  This step is
                            #necessary for getting back valid items.
if (num==0) then( #if the item marker is found but the corresponding item isn't, then...
set variable (num,num+1)) #this changes the quantity of that item to one.  This is more relevant
                          #to collecting items on the field, as I have found that leaving this
                          #equation out of the script will mean the player can never actually
                          #obtain the item.
get item (i,num)) #this adds a previously collected item and its quantity back into inventory.
                  #Obviously, if (num) is still zero, that's how many copies of the item will be
                  #returned to your inventory, so make sure to set the [num] variable to +1.
set variable (i,i+1) #prepares the next item on the list.
set variable (items,items+1) #prepares the next item marker on the list.
)
end


#as you can probably tell, the purpose of the item markers is to make sure this script doesn't
#rob you of items that you legitimately obtained within the limits.  Since this script removes
#ALL ITEMS from your inventory, it's important that you run the Inventory Check script first,
#so that the items it found can be given back to you once all illegal items are removed from
#your inventory.

#---------------------------------------------------------------------------

#one last important note--the best way to completely disregard the usefulness of these scripts
#is to physically add an item to your inventory through "Give Item" on the NPC edit list, or
#"Add Item" through text box conditioning.  If you do it that way, the game will always add the
#item to your inventory, whether it exceeds the limit or not.  The only way to do it this way
#and actually impose the limit is to make four scripts for each individual item and have it
#call on the dialogue box or add item that contains the item.

#this is obviously a bass-ackwards way of doing things, so make your life easier by calling on
#one dialogue box that pops up when you talk to the NPC that is "holding" the item, and have
#that box run the item limits scripts.  The catch here is that each dialogue box should activate
#that specific item's marker tag in its conditional settings before the scripts are ran.  This
#way any items obtained on the field can be acquired smoothly without having to turn four scripts
#into four hundred.

#-------------------------------------------------------------------------------

#this next script is merely meant to deactivate all item marker tags.  This is important for
#making sure that any item no longer present isn't counted as being present.

#ignoring this script may inadvertantly prevent the hero from carrying more than two, three,
#five, etc. items at a time instead of the true limit.

#I won't expand on these lines since it should be clear what they do by now.

script,Item Tag Reset,begin

variable (c)
set variable (items,22)
for (c,1,12)
do(
set tag (items,OFF)
set variable (items,items+1)
)
end

#--------------------------------------------------------------------------

#the next two scripts are application scripts.  These are examples of the kind of scripts
#that should be attached to the NPCs and/or their dialogue.

#---------------------------------------------------------------------------

#the first script is used for shopkeeper NPCs.


script,Shopkeeper,begin

wait for text box    #makes sure the text activating the script isn't immediately wiped out. 
Item Tag Reset  #deactivates all item markers
Item Limits Shopping  #runs the scan of how many items are present

if (checktag (21)) then,begin(  #checks to see if the eighth item has been found.
                                #remember that Tag 21 was used as the item limiting tag
show text box (3)  #if Tag 21 is on, the shopkeeper won't let the hero buy anything.
wait for text box
)
end

else,begin(  #if Tag 21 is off...
Inventory Check  #then the game checks which items are currently in inventory...
show text box (4)  #and then calls up the items shop.
wait for text box
Item Limits Shopping  #when the hero is finished shopping, this checks to make sure he didn't
                      #exceed the item limit.
if (checktag (21)) then(  #if he did exceed the limit...
show text box (3)  #the shopkeeper will tell him so...
wait for text box
Strip Items  #and he'll take back everything the hero just bought without giving a refund!
Item Tag Reset  #after all is said and done, this will reset the item markers.
)
Item Tag Reset  #this resets the item markers even if the limit hasn't been exceeded.
)
end

else,begin(  #but if the hero still has room to buy more items...
show text box (2)  #the shopkeeper tells him so.
wait for text box
Item Tag Reset  #and thus the item markers are reset once again.
)
end
end


#remember that the item limits script makes buying the eighth item difficult, so you may want
#to set Tag 22 as the defining limit instead of 21 (or whatever tag is relevant for your game).

#I only had this problem with shops, so keep Tag 21 (or whichever) as your defining limit tag
#for specific items obtained through NPCs.

#If you do decide to use Tag 22 as a shopkeeper item limit, make sure you set the Item Limit
#Shopping script to cycle through 9 possible item tags instead of 8.

#--------------------------------------------------------------------------------

#this final script is a sample script used for limiting specific items obtained from NPCs.


script,Collecting,begin

wait for text box   #prevents the text box from wiping out the moment the script is run.
Item Limits Obtainable  #checks how many items are in inventory

if (checktag (21)) then,begin(  #if the eighth item is found...
show text box (6)  #the hero can't pick this item up.
wait for text box
Item Tag Reset  #and so the item markers are reset once again.
)

end
else,begin(  #but if Tag 21 isn't activated, and there's still some room...
show text box (5) #then it's the hero's lucky day.
wait for text box
Inventory Check  #the game just needs to make one quick check of the existing items...
Strip Items  #then add the one that the hero just picked up...
Item Tag Reset  #and viola!
)
end
end

#and thus concludes this featured presentation.  Hope it makes sense.

Site layout (c)2000 Jennifer Raby. Used by permission.