Ummm... i am rewriting that stuff now
I was expecting that (objGetData) can return pointers and data-variables can store pointers on some object.
Plan:
itEMC has:
1. Variable - W (collected watts)
2. Variable - LW (limit of watts to be collected)
3. Variable - kg (obviously, it's mass)
4. Variable - mode (0 - not ready to fire, don't gather energy, 1 - is gathering energy, 2 - ready to fire)
5. Function (Event) - Ready (called when it have finished collecting)
6. Function - Fire (Last step. At this point it creates virtual dynamic weapon with custom damages and calls sysCreateWeaponFire with it)
7. Function - PowerFailure (It's called when something had been uninstalled or disabled when it was collecting power.)
dsEMC.
It's just a dockscreens.
But! There's big problem - i can't get caller (itEMC) to obtain variables. gSource returns gPlayership, not an itEMC. I have tried different globals, but it's all the same - or not itEMC, or [No binding].
Well, after that i made that itEMC don't have any variables, instead that, gSource gets them (user ship).
So, now, ship-holder has next variables
1. EMC_W (watts)
2. EMC_LW (limit of watts)
3. EMC_kg (kg)
4. EMC_mode (mode)
5. EMC_parent (pointer to an EMC)
Bullets and missiles. Their variables, function, events.
And i stuck with a problem: virtual energy load don't want to be installed on a ship.
Code:
<ItemType UNID="&vtELoad;"
name = "Energy load"
virtual = "1"
>
<MiscellaneousDevice
powerUse= "1"
deviceSlots= "0"
external= "false"
/>
<Events>
<OnUpdate>
(block Nil
(setq EMC (objGetData gSource "EMC_parent"))
(setq plM (divide (objGetMaxPower gSource) 2))
(setq currW (objGetData EMC "EMC_W"))
(setq lastW (subtract (objGetData EMC "EMC_LW") currW))
(setq currW (add (currW plM)))
(if (geq currW lastW)
(block Nil
(objFireEvent EMC "Ready")
(objRemoveItem gSource gItem (objHasItem gSource gItem))
)
(block Nil
(objSetData EMC "EMC_W" currW)
)
)
)
</OnUpdate>
<OnDisable>
(block Nil
(setq EMC (objGetData gSource "EMC_parent"))
(objFireEvent EMC "PowerFailure")
(objRemoveItem gSource gItem (objHasItem gSource gItem))
)
</OnDisable>
</Events>
</ItemType>
shpInstallDevice doesn't work, it says "Unable to find specified item in object"
It's all the same if i add a bunch of vtELoad to the ship.
Code:
<ItemType UNID="&vtELoad;"
name = "Energy load"
virtual = "1"
>
<MiscellaneousDevice
powerUse= "1"
deviceSlots= "0"
external= "false"
/>
<Events>
<OnUpdate>
(block Nil
(setq EMC (objGetData gSource "EMC_parent"))
(setq plM (divide (objGetMaxPower gSource) 2))
(setq currW (objGetData EMC "EMC_W"))
(setq lastW (subtract (objGetData EMC "EMC_LW") currW))
(setq currW (add (currW plM)))
(if (geq currW lastW)
(block Nil
(objFireEvent EMC "Ready")
(objRemoveItem gSource gItem (objHasItem gSource gItem))
)
(block Nil
(objSetData EMC "EMC_W" currW)
)
)
)
</OnUpdate>
<OnDisable>
(block Nil
(setq EMC (objGetData gSource "EMC_parent"))
(objFireEvent EMC "PowerFailure")
(objRemoveItem gSource gItem (objHasItem gSource gItem))
)
</OnDisable>
</Events>
</ItemType>
shpInstallDevice doesn't work, it says "Unable to find specified item in object"
It's all the same if i add a bunch of vtELoad to the ship.
Actually, it is possible to store data on an itemstruct using objSetItemData and itmGetData.TVR wrote:Solution: As far as I know, it is impossible to store data on an itemStruct. Instead, try storing the data about the item on the ship withand retrieving it withCode: Select all
(objSetData gSource (cat (item gItem 0) (item gItem 1) "identifier") data)
Code: Select all
(objGetData gSource (cat (item gItem 0) (item gItem 1) "identifier") data)
The canonical example is in StKatharines.xml:
Code: Select all
(setq stkFreshFoodUpdate (lambda (theSource theItem)
(block ((status (itmGetData theItem "status"))
(expireTime (itmGetData theItem "expireTime")))
(switch
; If the food has rotted, mark it
(and (not (eq status 'rotted)) (gr (unvGetTick) expireTime))
(block Nil
(objSetItemData theSource theItem "status" 'rotted (itmGetCount theItem))
(if (eq theSource gPlayerShip)
(plyMessage gPlayer "The " (itmGetName theItem 0x80) " in your cargo hold have rotted")
)
)
; If the food has turned ripe, mark it
(and (not status) (gr (add (unvGetTick) 1800) expireTime))
(block Nil
(objSetItemData theSource theItem "status" 'ripe (itmGetCount theItem))
(if (eq theSource gPlayerShip)
(plyMessage gPlayer "The " (itmGetName theItem 0x80) " in your cargo hold look ripe")
)
)
)
)
))
Literally is the new Figuratively
- digdug
- Fleet Admiral
- Posts: 2620
- Joined: Mon Oct 29, 2007 9:23 pm
- Location: Decoding hieroglyphics on Tan-Ru-Dorem
Might sounds stupid, but, did you create the itmstruct and added it to the cargo of the ship before doing shpInstallDevice ? Otherwise it won't work.shpInstallDevice doesn't work, it says "Unable to find
specified item in object"