Aller au contenu

Photo

Odd behaviour with object


  • Veuillez vous connecter pour répondre
12 réponses à ce sujet

#1
sillyrobot

sillyrobot
  • Members
  • 171 messages
I'm working on a bag of holding: an item that exists in inventory and can be activated to access additional inventory space.

I have the item linked to a created placeable container through an additional local variable bult into the item.  The container is placed in the char_stage area for safekeeping. 

Everything is working fine initially.  The bag is created and placed in inventory, activating it presents the inventory screen.  It functions after area transitions.  I thought I was making good progress.

However, it doesn't work from a save game.  The object local variable continues to hold the original value, but it is no longer considered an valid object.

What needs to be done to survive a save game?  Im uncertain what to try next.  It looks pretty straightforward, but the placeable container is either gone or no longer under the same object reference or ????

I've transported the hero to the char_stage area and tried to GetObjectByTag() call to see if I can find the original container, but I can't find it there.

The module script is below, if it helps.


#include "utility_h"
#include "placeable_h"
#include "plt_bagofholdingplot"
void main()
{
    event ev = GetCurrentEvent();
    int nEventType = GetEventType(ev);
    switch ( nEventType )
    {
        case EVENT_TYPE_MODULE_LOAD:
        {
            if ( WR_GetPlotFlag( PLT_BAGOFHOLDINGPLOT, CHESTADDEDTOCAMP ) == 0 )
            {
                object oBag = CreateItemOnObject( R"bagofholding.uti",
                        GetHero(), 1, "BagOfHolding", TRUE, TRUE );  // Add bag to player inventory
                object oCamp2 = GetArea( GetHero());
                vector vChestLocation = Vector(148.77, 117.68, -0.94);  //arbitrary placement that works for my intial test location (party camp)
                object oChest = CreateObject( OBJECT_TYPE_PLACEABLE,
                        R"bohContainer.utp",
                        Location(oCamp2, vChestLocation, 0.0), "", TRUE, TRUE);  // create background inventory nearby
                SetLocalObject( oBag, "ContainerReference", oChest );
                object oCamp = GetObjectByTag("char_stage", 0);
                SetLocation( oChest, Location( oCamp, vChestLocation, 0.0)); // move inventory to char_stage area for safekeeping
                WR_SetPlotFlag( PLT_BAGOFHOLDINGPLOT, CHESTADDEDTOCAMP, 1 );
            }
            break;
        }
        case EVENT_TYPE_UNIQUE_POWER:  // Sent when a player activates the Bag of Holding
        {
            object oBag = GetEventObject(ev, 0);
            object oChest = GetLocalObject( oBag, "ContainerReference" );
            object oUser = GetEventObject(ev, 1);
            DisplayFloatyMessage( GetHero(), "Chest Object: " + ObjectToString( oChest ),
                        0, 16777215, 2.5);
            DisplayFloatyMessage( GetHero(), "Valid: "
                    + IntToString(IsObjectValid( oChest )), 0, 16777215, 2.5);

            if ( IsObjectValid( oChest ))
            {
                OpenInventory( oChest, oUser, TRUE );
            }
            break;
        }
    }
}

#2
georage

georage
  • Members
  • 247 messages
i would look into a quasi array that stores the resource ids as an uber string, and then save that onto a declared module variable, which should persist.

of course, i have not tried it.

EDIT: and yes, i believe the object ID/pointer is reset when you restart the game, so that is why the object is not valid.

Modifié par georage, 25 novembre 2009 - 03:39 .


#3
sillyrobot

sillyrobot
  • Members
  • 171 messages
Thanks for the reply. I've adjusted the module script to look for the container and update the item object reference on a load. It works from a save so long as the container is in the same area as the hero. Unfortunately, that means using the char_stage area for safekeeping becomes problematic as I can't locate the container onvce it is there.

I'll look for some way to find an object in a different area and/or consider having the container follow the player through area transitions first.

Modifié par sillyrobot, 25 novembre 2009 - 04:31 .


#4
Craig Graff

Craig Graff
  • Members
  • 608 messages
You're probably going to want to give the chest a unique tag and use GetObjectByTag, but you will also likely want to jump the chest back into the player's area before opening the inventory. You can move it below the ground if you don't want the player to see it.

#5
georage

georage
  • Members
  • 247 messages
I guess we have no Null Human? Those guys were pure gold.

#6
sillyrobot

sillyrobot
  • Members
  • 171 messages

Craig Graff wrote...

You're probably going to want to give the chest a unique tag and use GetObjectByTag, but you will also likely want to jump the chest back into the player's area before opening the inventory. You can move it below the ground if you don't want the player to see it.



While the chest is in char_stage area, I can access its inventory without a problem so the only reason to move the chest from char_stage is to provide storage across save games (a pretty big reason). 

The chest has an unique tag already.  I've tried using GetObjectByTag, but have only had success when the object exists in the same area as hero.  I was hoping to be able to find the chest while it was in char_stage, but alas I haven't had any luck with that yet.  Is there a method to achieve that?

As for the player not seeing it, if I leave the chest in the hero's location I set the chest as inactive -- the inventory functions seem unimpeded.  If necessary, I'll explore using the begin travel / finish tavel events to store the chest in char_stage and retrieve it to the new location.  I'm hesitant to do that since I'm uncertain if there are area transitions that don't trigger those events and any uncaught transition will shut the bag down if it is set up this way.

#7
sillyrobot

sillyrobot
  • Members
  • 171 messages

georage wrote...

I guess we have no Null Human? Those guys were pure gold.


What's a Null Human?  I suppose I could use a creature instead of a placeable, but I think I'll have the same set of issues.

#8
Craig Graff

Craig Graff
  • Members
  • 608 messages
And you are using GetObjectByTag and not UT_GetNearestObjectByTag? I've had no trouble using GetObjectByTag to get objects in the char_stage area.

Edit: I see the problem. My char_stage idea is apparently rather broken. I'll do some more testing, but I may have gotten hopes up for nothing there.

Modifié par Craig Graff, 25 novembre 2009 - 05:53 .


#9
Nodrak

Nodrak
  • Members
  • 144 messages
It might be that char_stage, while persistent during runtime, is not serialized?

#10
Craig Graff

Craig Graff
  • Members
  • 608 messages
I haven't tested thoroughly, but there seem to be two problems - one is that SetLocation doesn't seem to actually move the chest into the char_stage area, but instead to 0,0 of the current area. It is possible to add a chest to the char_stage area in the toolset and have that area in override and it may also be possible to create the chest in the char_stage area while the party picker is actually open (there are a number of module events that might be useful here.
The other problem is that char_stage is not serialized, so changes made to objects in it are not persistent across save and load. This could be worked around by using EVENT_TYPE_MODULE_PRESAVE and either a PRCSCR script with "any" as the area list or possibly module load.

It is likely still worth experimenting with, but it's far less promising than my initial tests led me to believe.

Modifié par Craig Graff, 25 novembre 2009 - 09:40 .


#11
Quildra

Quildra
  • Members
  • 45 messages
The EVENT_TYPE_MODULE_PRESAVE override works, that how me and AND04 did our chest mods. although im probably going to change mine so i override the EVENT_TYPE_ENTER so i spawn the chest to the players area and then call DoAutoSave to make sure the items are saved.

#12
sillyrobot

sillyrobot
  • Members
  • 171 messages
Thanks for the insight everyone!



I adjusted the module to move the chest back to the player during the PRESAVE event and all appears well.

#13
AND04

AND04
  • Members
  • 154 messages
don't forget to move it back to char_stage on the EVENT_TYPE_EXIT event too