User Tools

Site Tools


game:george_thoughts

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
game:george_thoughts [2013/09/09 17:05] rpcgame:george_thoughts [2014/12/27 04:40] – external edit 127.0.0.1
Line 1179: Line 1179:
  
 Hope that helps! Hope that helps!
 +==== On Items ====
 +Taken from [[http://forums.kronosaur.com/viewtopic.php?f=5&t=6375#p56912|here]]\\ 
 +The most important thing to remember about items (armor, devices, etc.) is that you can only manipulate them by value not by reference. What does that means? Here is a quick tutorial:
 +
 +When you call a function like:
 +
 +(objAddItem gPlayerShip (itmcreate 0xD518FF28 4) 4)
 +
 +you add a single item record to the player ship. The player ship's inventory will look like this:
 +
 +Player Ship Inventory:
 +[UNID: 0xD518FF28 count:4 flags:none]
 +
 +First, notice that even though you've created 4 armor segments there is only a single record. The record itself has a count of 4, which is how we keep track. This is done for efficiency. Otherwise, if you pick up 1000 rounds of ammo we would have 1000 records, which is too expensive.
 +
 +Next, notice that there is no ID field! The fact that there is no ID field means that you can't refer to the record by ID. So how do you refer to the armor segments? How do you, for example, install them?
 +
 +You need to install them by describing exactly the items that you want to install. You have to refer to them by value. Effectively, you need to do something like this:
 +
 +(shpInstallArmor gPlayerShip "the armor that looks like: [UNID: 0xD518FF28 count:4 flags:none]")
 +
 +Of course, the above won't work, but the function itmCreate essentially is a way of creating records of that form. So the following works:
 +
 +(shpInstallArmor gPlayerShip (itmCreate 0xD518FF28 1) 0)
 +
 +Indeed, the output of itmCreate is a record structure. Under the covers:
 +
 +(itmCreate 0xD518FF28 1) -> [UNID: 0xD518FF28 count:1 flags:none]
 +
 +After you do this, you will end up with inventory that looks like this:
 +
 +Player Ship Inventory:
 +[UNID: 0xD518FF28 count:3 flags:none]
 +[UNID: 0xD518FF28 count:1 flags:installed installedAt:0]
 +
 +Notice that the act of installing armor changes the record! Because the record has changed, you can't refer to it by the original name. For example, suppose I wanted to enhance the armor I just installed. I might naively try this:
 +
 +(shpEnhanceItem gPlayerShip (itmCreate 0xD518FF28 1))
 +
 +Which armor segment would get enhanced? Because the installed armor has changed (because it is installed), I can't use the same code to refer to it anymore. I need to do something like:
 +
 +(shpEnhanceItem gPlayerShip "the armor that looks like: [UNID: 0xD518FF28 count:1 flags:installed installedAt:0]")
 +
 +Unfortunately, itmCreate can't output that kind of record (it doesn't know how to set the installed flag), so you can't use it. Instead, you need to find the item on the player ship and use that. objGetItems returns a list of item records that match a specific criteria.
 +
 +(objGetItems gPlayerShip "unid:0xD518FF28;") ->
 +[UNID: 0xD518FF28 count:3 flags:none]
 +[UNID: 0xD518FF28 count:1 flags:installed installedAt:0]
 +
 +Since both records match the UNID, objGetItems returns both the installed and uninstalled. If I only want the installed item, I need the 'I' flag:
 +
 +(objGetItems gPlayerShip "unid:0xD518FF28; I") ->
 +[UNID: 0xD518FF28 count:1 flags:installed installedAt:0]
 +
 +Of course, the result is still a list, so I would need to use the '@' syntax to get the first element of the list:
 +
 +(shpEnhanceItem gPlayerShip (@ (objGetItems gPlayerShip "unid:0xD518FF28; I") 0))
 +
 +objGetItems is a way to find the item record that you want to refer to. So with that (long) tutorial out of the way, we can talk about your code.
 +
 +In your first example, there is a small bug in the criteria for objGetItems. Your code should be something like:
 +
 +<code>
 +(objadditem gplayership (itmcreate 0xD518FF28 4) 4)
 +(shpinstallarmor gplayership (@ (objgetitems gplayership "unid:0xD518FF28; U") 0) 0)
 +(shpinstallarmor gplayership (@ (objgetitems gplayership "unid:0xD518FF28; U") 0) 1)
 +(shpinstallarmor gplayership (@ (objgetitems gplayership "unid:0xD518FF28; U") 0) 2)
 +(shpinstallarmor gplayership (@ (objgetitems gplayership "unid:0xD518FF28; U") 0) 3)
 +</code>
 +
 +Notice that the "unid:..." term ends in a semi-colon. And the "U" term doesn't need a "^".
 +
 +But your second example works just as well because you've described the item perfectly. The second method would get into problems if the item were enhanced, damaged, installed, or had data associated with it. In those cases, you need to use the objGetItems syntax.
 +
 +Also, many functions return the item record after modification. For example, objSetItemData returns the newly modified item record and you can use the result to refer to the item in subsequent calls.
 +==== Shield and Level Adjustment curves ====
 +[[/modding/shield_and_level_damage_adjustment_curves1.01|Shield and Level adjustment curves]]
  
game/george_thoughts.txt · Last modified: 2016/01/06 20:43 by xephyr