Skip to content

CopyObject - Gold

I have come across an issue that when a player drops gold on a placeable object that does not have inventory the gold is removed from the players inventory and even though the gold does show in the objects inventory through checking with a script, there is no way for a player to retrieve the gold that they lost due to "misclicking" an object with no inventory.

I am not sure if I am explaining that right so...

A player drops gold on an object that does not have any inventory (the box has inventory not checked in the toolset).

The gold is removed from the players inventory.

The player can not click on the object to open its inventory since has inventory in the toolset is not checked for the object.

I can run a script to cycle through the objects inventory and the script does show that the object does have the players dropped gold in its inventory.

If gold is dropped multiple times on the object the script returns each one, it does not stack into one item.

Over the years I have figured out that if I use CopyItem for gold that has been dropped I can copy gold that has been dropped in an area to a chest and the amount of gold remains the same.

On the modules unacquire script I have scripted it so when this happens the gold is returned to the player using CopyItem but this makes it look like their action failed because nothing happens, you cant even see the gold amount change in the inventory screen.

However, I am fussy about things and I want to make it look like the player actually dropped the gold on the ground.

When I use CopyObject to copy the gold to the players location it does work but the amount of gold is not correct. When testing I can drop up to 65,535 gold and the amount copied is correct.

Any amount over 65,536 does not copy the exact amount of gold. If I drop 70,000 gold I only see 4,464 gold (funny thing is that 70,000 - 4,464 = 65,536)

There are a few other things that I have done to make sure the player can retrieve their gold but for simplicity I am wondering how I can make it look like the player dropped their gold on the ground and have CopyObject not change the amount of gold that was dropped?

Comments

  • 4BOLTMAIN4BOLTMAIN Member Posts: 90
    My solution...

    I created a loot bag in the toolset with inventory.

    On the unacquire script I checked if the item was gold and if the object possessor contained inventory.

    If the item was gold and the object did not contain inventory I created the loot bag at the pc's location and then copied the item (gold) to the loot bag.

    If the loot bag was empty on closed then it was destroyed.
  • ProlericProleric Member Posts: 1,283
    Silly question, but why not flag the placeables as having inventory?

    If the intention is for the PC to retrieve items from the chest by opening it, that's the simplest solution.

    Alternatively, you could use CreateItemOnObject() for gold. I have this working for chests with
    • not Static, not Useable, not Inventory
    • not Static, Useable, Inventory but empty

    The maximum stack size for gold is 65,535 (64k - 1) so scripts that copy gold to a placeable's inventory need to look something like this:
            int nAmount = GetGold(oPC);
    
            while (nAmount > 50000)
              {
                CreateItemOnObject("NW_IT_GOLD001", oChest, 50000);
                AssignCommand(oPC,TakeGoldFromCreature(50000,oPC,TRUE));
                nAmount -= 50000;
              }
    
            if(nAmount > 0)
                {
                  CreateItemOnObject("NW_IT_GOLD001", oChest, nAmount);
                  AssignCommand(oPC,TakeGoldFromCreature(nAmount,oPC,TRUE));
                }
    
    I prefer to use 50000 because I like round numbers.
  • 4BOLTMAIN4BOLTMAIN Member Posts: 90
    It was discovered that its possible to drop gold on placeables not intended to have inventory like a usable sign or a chair and you loose your gold with no way to retrieve it.

    So rather than just using CopyItem to copy the gold back to the players inventory in the unacquire script, I wanted something that looked like factory game mechanics. After several hours of testing and trying different things I found the best option was to create a loot bag at the players location, have the player do a GET_LOW animation and then use CopyItem to copy the lost gold (oItem) to the loot bag. The loot bag is destroyed if it has no inventory after the gold is retrieved from it.

    I am having a hard time understanding why CopyItem works with gold no matter what the amount is but CopyObject doesnt. Obviously if CopyItem could use a location like CopyObject that would be ideal but with a little more work I have it working like I want.
  • TarotRedhandTarotRedhand Member Posts: 1,481
    Just making sure but is it necessary for all the items this happens with to be flagged as usable? Could at least some of them be flagged as static?

    TR
  • ForSeriousForSerious Member Posts: 446
    Maybe I'm just me, but it would only take doing that once to learn not to ever do it again. I've been playing since about 2006 and never even thought of blindly dropping gold onto a placeable. The closest I have come is dropping gold into a placebale while viewing the contents of its inventory.

    I'm glad you've been able to find a working fix. I had no such luck trying to block pick-pocketing. When it comes to gold, there's no way to deal with it.
  • 4BOLTMAIN4BOLTMAIN Member Posts: 90
    Just making sure but is it necessary for all the items this happens with to be flagged as usable? Could at least some of them be flagged as static?

    TR

    The main objects are weapon racks that players use to choose different options for merchants when buying and selling items. Every usable object with no inventory has a purpose.
    ForSerious wrote: »
    Maybe I'm just me, but it would only take doing that once to learn not to ever do it again. I've been playing since about 2006 and never even thought of blindly dropping gold onto a placeable. The closest I have come is dropping gold into a placebale while viewing the contents of its inventory.

    I'm glad you've been able to find a working fix. I had no such luck trying to block pick-pocketing. When it comes to gold, there's no way to deal with it.

    Yeah, I would never do this but there's always that one person who likes to try things and then carry on about it in shout, lol!

    During testing I noticed that you can not drop gold on doors or transitions. What is strange is when I try to drop gold on a dungeon portal it opens the conversation and doesn't remove any gold. The weapon racks are set up to open a conversation also but your gold is removed. All the flags on both objects are exactly the same, the scripts follow the same format (clear actions, then start conversation) but yet they behave differently... SOLVED: After a few minutes of looking at the area both objects do the same thing. I have a trigger around the portal that also opens the conversation when you get near it so the trigger was clearing the actions before my character would actually reach the portal to drop the gold. Good to know.

    I removed the PVP aspect from my module in 1.69. There was just too much drama for me to keep up with. I think we all can agree that there are certain things missing that would make PVP a lot easier to admin but that's another topic.

    Thanks for the response everyone. I appreciate the feedback and comments.
  • MelkiorMelkior Member Posts: 181
    Hmm... The first thing I'd try would be an OnInventoryDisturb script which returned any gold directly to the PC through GiveItem. If that didn't work and CopyObject was glitchy, then my next thing to try would be GetItemStackSize followed by CreateItemOnObject and a DestroyObject to clean up the gold in the inventory.

    It's really weird that you can drop gold into the inventory of a no-inventory placeable object in the first place. That sounds like a bug to me.
  • MelkiorMelkior Member Posts: 181
    I did some testing and using the following script I discovered that attempting to drop a non-gold item into the inventory of a no-inventory placeable which you can interact with doesn't do anything. However, dropping gold into the same placeable does trigger the inventory disturb event. The script returns the gold to the PC with a little message.
    If you want to use the script, you can just remove the else and the bracketed section after it. If you don't want or need feedback, then erase the speakstring line.
    void main()
    {
      object oThing=GetInventoryDisturbItem();
      int iType=GetInventoryDisturbType();
      object oPC=GetLastDisturbed();
      if(!GetIsPC(oPC) || !GetIsObjectValid(oThing)) return;
      int iStack=GetItemStackSize(oThing);
      string sThing=GetResRef(oThing);
      if(sThing=="nw_it_gold001")
      {
        GiveGoldToCreature(oPC,iStack);
        DestroyObject(oThing);
        SpeakString("I don't want your gold...");
      }
      else
      {
        ActionGiveItem(oThing,oPC);
        SpeakString("You can keep that...");
      }
    }
    

    No-feedback, gold-only script:
    void main()
    {
      object oThing=GetInventoryDisturbItem();
      int iType=GetInventoryDisturbType();
      object oPC=GetLastDisturbed();
      if(!GetIsPC(oPC) || !GetIsObjectValid(oThing)) return;
      int iStack=GetItemStackSize(oThing);
      string sThing=GetResRef(oThing);
      if(sThing=="nw_it_gold001")
      {
        GiveGoldToCreature(oPC,iStack);
        DestroyObject(oThing);
      }
    }
    
Sign In or Register to comment.