set-remove data on installed items

Freeform discussion about anything related to modding Transcendence.
Post Reply
User avatar
digdug
Fleet Admiral
Fleet Admiral
Posts: 2620
Joined: Mon Oct 29, 2007 9:23 pm
Location: Decoding hieroglyphics on Tan-Ru-Dorem

So, what I want to do is to place and remove data on installed weapons on the playership.
Using itmSetData I can create a new itm with the data I want and install it.

To remove the data, I simply remove the item, and install a fresh one created with itmCreate.

Code: Select all

(setq alpha_setLinkData (lambda (itm) 
             (block Nil
                (objRemoveItem gSource (shpRemoveDevice gSource itm))
                (setq itm (itmSetData itm "alpha_linked" True 1))
                (objAddItem gSource itm)
                (shpInstallDevice gSource itm)
            )))
            
            (setq alpha_removeLinkData (lambda (itm) 
             (block Nil
                (objRemoveItem gSource (shpRemoveDevice gSource itm))
                (setq itm (itmCreate (itmGetUNID itm) 1))
                (objAddItem gSource itm)
                (shpInstallDevice gSource itm)
            )))
The problem is: the device is not reinstalled on the ship, but it's merely placed back in the cargo.
What am I doing wrong ? :?
User avatar
alterecco
Fleet Officer
Fleet Officer
Posts: 1658
Joined: Wed Jan 14, 2009 3:08 am
Location: Previously enslaved by the Iocrym

I think for this you should use objSetItmData (i think that is what it is called, can't look it up right now)

Basically it sets data on an item without having to go through the hassle of installing/placing on the playership
User avatar
digdug
Fleet Admiral
Fleet Admiral
Posts: 2620
Joined: Mon Oct 29, 2007 9:23 pm
Location: Decoding hieroglyphics on Tan-Ru-Dorem

resolved!
it seems that the problem was in my use of shpInstallDevice

I resolved it by cheating with objEnumItems :D (and that's basically what I was doing in WE3 for removing/installing weapons on the fly)

Code: Select all

(setq alpha_setLinkData (lambda (itm numberSlot) 
             (block Nil
                (objRemoveItem gSource (shpRemoveDevice gSource itm))
                (setq itm (itmSetData itm "alpha_linked" True 1))
                (objAddItem gSource itm)
                ;we also set the data after creating the new weapon, otherwise error occours.
                (objSetData gSource (cat "alphastrike" numberSlot) itm)
                (objEnumItems gSource "wU" tempWeapon
                 (if (eq (itmGetUnid tempWeapon) (itmGetUNID itm))
                  (shpInstallDevice gSource tempWeapon)
                  )
                 )
            )))
            
            (setq alpha_removeLinkData (lambda (itm) 
             (block Nil
                (objRemoveItem gSource (shpRemoveDevice gSource itm))
                (setq itm (itmCreate (itmGetUNID itm) 1))
                (objAddItem gSource itm)
                (objEnumItems gSource "wU" tempWeapon
                 (if (eq (itmGetUnid tempWeapon) (itmGetUNID itm))
                  (shpInstallDevice gSource tempWeapon)
                  )
                 )
            )))
So this 2 helper functions can remove an item, install the new one with itemdata on it. (I'm also placing data on the spaceobject to be retrieved later)
the second one will create a new item and replace the one with itemdata, effectively "cleaning" the itemdata.

Now I have to make the dockscreen filter using itemdata, and I'm stuck again :P
User avatar
Prophet
Militia Captain
Militia Captain
Posts: 826
Joined: Tue Nov 18, 2008 6:09 pm

Argh, alterecco beat me to it!

In Boarding Parties I used objSetItemData to keep track of the bots and commander equipment. The dockscreens were written in DSF but the vanilla equivalents aren't too bad to work with.

this little screen will take care of adding/removing the data from the items:

Code: Select all

<DockScreen UNID="&dsAlphaStrike;"
        name=				"alpha strike selector"
        type=				"customPicker"
        backgroundID=		"&rsItemListScreen;"
        >
    <Main>
		<Panes>
			<Default>
                <Initialize>
                    (block (desc)
                        (setq desc (cat "Alpha strike is AWESOME!!!!1!!!one!!!!"))
                        (scrEnableAction gScreen 0 (not (itmGetData (scrGetItem gScreen) "alpha_linked")))
                        (scrEnableAction gScreen 1 (itmGetData (scrGetItem gScreen) "alpha_linked"))
                    )
                </Initialize>
                <Actions>
                    <Action name="Set alpha link" key="S" default="1">
                        (block (slot)
                            (setq slot 0)
                            (enum (objGetItems gSource "*") itm (if (itmGetData itm "alpha_linked") (setq slot (add slot 1))))
                            (alpha_setLinkData (scrGetItem gScreen) (add slot 1))
                        )
                    </Action>
                    <Action name="Remove alpha link" key="R">
                        (block Nil
                            (alpha_removeLinkData (scrGetItem gScreen))
                        )
                    </Action>
                    <Action name="Done" key="D" cancel="1">
                    </Action>
                </Actions>
            </Default>
        </Panes>
    </Main>
</Dockscreen>
At least I thought that's what the DS would be used for :)
Hope that helps.
Coming soon: The Syrtian War adventure mod!
A Turret defense genre mod exploring the worst era in Earth's history.
Can you defend the Earth from the Syrtian invaders?
Stay tuned for updates!
User avatar
alterecco
Fleet Officer
Fleet Officer
Posts: 1658
Joined: Wed Jan 14, 2009 3:08 am
Location: Previously enslaved by the Iocrym

Prophet wrote:Argh, alterecco beat me to it!
And I'm not even really here!!

Nice job giving a real example though :P
User avatar
digdug
Fleet Admiral
Fleet Admiral
Posts: 2620
Joined: Mon Oct 29, 2007 9:23 pm
Location: Decoding hieroglyphics on Tan-Ru-Dorem

Code: Select all

	<DockScreen UNID="&dsAlphaStrikeConfigurator;"
    name=				"Alpha Strike Configurator"
    type=				"itemPicker"
    backgroundID=		"&rsItemListScreen;"
    >

    <ListOptions
			dataFrom=	"player"
			list=		"wI~l -AlphaStrike; -Launcher;"
			>
			;(scrSetListFilter gScreen (itmGetData "alpha_linked"))
			</ListOptions>
 
	<Panes>
		<Default>
		<Initialize>
                (block (weaponlist weaponindex alphastrike1 alphastrike2 alphastrike3 alphastrike4 alphastrike5) 
                 
                 
                 
                 ;recover the weapons
			     (setq alphastrike1 (objGetData gSource "alphastrike1"))
			     (setq alphastrike2 (objGetData gSource "alphastrike2"))
			     (setq alphastrike3 (objGetData gSource "alphastrike3"))
			     (setq alphastrike4 (objGetData gSource "alphastrike4"))
			     (setq alphastrike5 (objGetData gSource "alphastrike5"))
			     
			     
			     (scrSetDesc gScreen (cat "Welcome to the Alpha Strike Configurator!\nSlot 1 is " (itmGetName alphastrike1 1) "\nSlot 2 is " (itmGetName alphastrike2 1) "\nSlot 3 is " (itmGetName alphastrike3 1) "\nSlot 4 is " (itmGetName alphastrike4 1) "\nSlot 5 is " (itmGetName alphastrike5 1)))
                
			     ;we also deactivate the actions by checking the item data
			     (if (itmGetData (scrGetItem gScreen) "alpha_linked")
			      (block Nil
			       (scrEnableAction gScreen 0 Nil)
			       (scrEnableAction gScreen 1 Nil)
			       (scrEnableAction gScreen 2 Nil)
			       (scrEnableAction gScreen 3 Nil)
			       (scrEnableAction gScreen 4 Nil)
			     ))
			     
			     )
                </Initialize>
                
			<Actions>
                

                <Action name="Set Slot 1" key="1">
                    (block (PickedItem)
                        (setq PickedItem (scrGetItem gScreen))
                        ;(objSetData gSource "alphastrike1" PickedItem)
                        (objSetData gSource "alphastrike1_name" (alpha_tokenizeInWords (itmgetname PickedItem 0)))
                        (alpha_setLinkData PickedItem 1)
                        )
                </Action>
                <Action name="Set Slot 2" key="2">
                    (block (PickedItem)
                        (setq PickedItem (scrGetItem gScreen))
                        ;(objSetData gSource "alphastrike2" PickedItem)
                        (objSetData gSource "alphastrike2_name" (alpha_tokenizeInWords (itmgetname PickedItem 0)))
                        (alpha_setLinkData PickedItem 2)
                        )
                </Action>
                <Action name="Set Slot 3" key="3">
                    (block (PickedItem)
                        (setq PickedItem (scrGetItem gScreen))
                        ;(objSetData gSource "alphastrike3" PickedItem)
                        (objSetData gSource "alphastrike3_name" (alpha_tokenizeInWords (itmgetname PickedItem 0)))
                        (alpha_setLinkData PickedItem 3)
                        )
                </Action>
                <Action name="Set Slot 4" key="4">
                    (block (PickedItem)
                        (setq PickedItem (scrGetItem gScreen))
                        ;(objSetData gSource "alphastrike4" PickedItem)
                        (objSetData gSource "alphastrike4_name" (alpha_tokenizeInWords (itmgetname PickedItem 0)))
                        (alpha_setLinkData PickedItem 4)
                        )
                </Action>
                <Action name="Set Slot 5" key="5">
                    (block (PickedItem)
                        (setq PickedItem (scrGetItem gScreen))
                        ;(objSetData gSource "alphastrike5" PickedItem)
                        (objSetData gSource "alphastrike5_name" (alpha_tokenizeInWords (itmgetname PickedItem 0)))
                        (alpha_setLinkData PickedItem 5)
                        )
                </Action>
                
                <Action name="Disconnect Weapon Links" key="D">
                    (block Nil
                         ;delete the links
                         (objSetData gSource "alphastrike1" Nil)
                         (objSetData gSource "alphastrike2" Nil)
                         (objSetData gSource "alphastrike3" Nil)
                         (objSetData gSource "alphastrike4" Nil)
                         (objSetData gSource "alphastrike5" Nil)
                         ;we also reset the timers
                         (objSetData gSource "shottimer1" Nil)
                         (objSetData gSource "shottimer2" Nil)
                         (objSetData gSource "shottimer3" Nil)
                         (objSetData gSource "shottimer4" Nil)
                         (objSetData gSource "shottimer5" Nil)
                         ;we also reset the name lists
                         (objSetData gSource "alphastrike1_name" Nil)
                         (objSetData gSource "alphastrike2_name" Nil)
                         (objSetData gSource "alphastrike3_name" Nil)
                         (objSetData gSource "alphastrike4_name" Nil)
                         (objSetData gSource "alphastrike5_name" Nil)
                         
                         ;also remove attributes of the weapons
                         (enum (objGetItems gSource "wI") tempWeapon
                          (alpha_removeLinkData tempWeapon)
                          )
                        )
                </Action>
                
                <Action name="Exit" cancel="1" key="X">
                    <Exit/>
                </Action>
            </Actions>

        </Default>

        
	</Panes>

</DockScreen>
ok, at first I wanted to filter out the weapons with itemdata using scrSetListFilter, however it didn't work (read as: I have no clue how to use it)
So the second approach was to use Prophet's idea and use scrEnableAction to disable the weapon that is already linked (and has the data)
This works very well, besides a minor problem that I don't know how to resolve: If you replace the linkage (let's say slot 1) with another weapon, the item data is not removed from the first, and I don't know how to do it without screwing the weapons up in case the player installs multiple weapons of the same type.
For the rest it works.

Now I "just" have to make some script code that can interpret the configurations outputted by typGetDataField to recreate any configuration.
Everything else is already done including firing the sounds and using up the power of the reactor with objSetDeviceActivationDelay.
Post Reply