Electric counters not working properly
I have a counter in passthrough mode, and a counter with a target of 2 set. The non-passthrough counter has a button for increment and decrement. Both counters have a device after them, and show an expected value in Fortify, and have 100 power comming in.

In RB the counters both load in as passthrough.

In CopyPaste the counters both load in with targets set as 10, (not as passthrough and target of 2)

So it seems in both, RB and CopyPaste, counters do not seem to save their state. Could this be a Fortify issue perhaps? I looked in the JSON, but saw nothing referencing their states.

Saw a few posts regarding electricity, and that you were working on those issues. Not sure if these are covered by those fixes, or if I need to raise this issue with CP or Fortify.

My community is just in love with these bases and the things they can do in them. Great work!
Nope, definitely an issue with 1.5.2 screwing up many different electronics haha

I'll have my changes reverted with 1.5.3

For now you can download this and save it as RaidableBases.cs

This fixes a few issues introduced with 1.5.13 and 1.5.2 including this one

Also, CopyPaste does not save the information so that's why it's incorrect. It isn't saving the information because it wasn't accessible until recently. The plugin will require an update

Merged post

Open CopyPaste.cs and replace

                /*var counter = ioEntity.GetComponent<PowerCounter>();
                if (counter != null)
                {
                    ioData.Add("targetNumber", counter.GetTarget());
                }*/​

with 

var counter = ioEntity.GetComponentInParent<PowerCounter>();
if (counter != null && ioData.ContainsKey("targetNumber"))
{
    counter.targetCounterNumber = Convert.ToInt32(ioData["targetNumber"]);
}
​

and replace

                /*var counter = ioEntity.GetComponent<PowerCounter>();
                if (counter != null)
                {
                    ioData.Add("targetNumber", counter.GetTarget());
                }*/​

with

                var counter = ioEntity.GetComponent<PowerCounter>();
                if (counter != null)
                {
                    ioData.Add("targetNumber", counter.GetTarget());
                }​


Merged post

I've submitted the patch for this as well @misticos
Wow. Just amazing, much appreciated. Will dig into this now.

Merged post

Actually @nivex can you confirm those pastes? Your asking me to replace the same commented if with 2 different replacements.

Line 824 
/*var counter = ioEntity.GetComponent<PowerCounter>();
                if (counter != null)
                {
                    ioData.Add("targetNumber", counter.GetTarget());
                }*/​


and line 1473
// Realized counter.targetCounterNumber is private, leaving it in in case signature changes.
                    /*var counter = ioEntity.GetComponentInParent<PowerCounter>();
                    if (counter != null)
                    {
                        counter.targetCounterNumber = Convert.ToInt32(ioData["targetNumber"]);
                    }*/​
oh woops, my bad

Merged post

                /*var counter = ioEntity.GetComponent<PowerCounter>();
                if (counter != null)
                {
                    ioData.Add("targetNumber", counter.GetTarget());
                }*/

with

                var counter = ioEntity.GetComponent<PowerCounter>();
                if (counter != null)
                {
                    ioData.Add("targetNumber", counter.GetTarget());
                }

and

                    /*var counter = ioEntity.GetComponentInParent<PowerCounter>();
                    if (counter != null)
                    {
                        counter.targetCounterNumber = Convert.ToInt32(ioData["targetNumber"]);
                    }*/

with

                    var counter = ioEntity.GetComponentInParent<PowerCounter>();
                    if (counter != null && ioData.ContainsKey("targetNumber"))
                    {
                        counter.targetCounterNumber = Convert.ToInt32(ioData["targetNumber"]);
                    }
@nivex I dont think that solves it, but am still not sure where the issue is. Here are the Fortify file, and the JSON file for my small test platform with items that are not working right. Just in-case that helps any. 

Fortify file: https://pastebin.com/chSEGk3c
JSON file: https://pastebin.com/PZwui2nz

Test 1:
Power -> target -> anything

Result in CopyPaste:
Nothing is powered past target until target is tripped. As expected.

Result in RB:
Items after target are powered initially, and once target is triggered 1st time, it behaves normally.

Test 2:
Power -> splitter -> counters -> blue lights/other things

Counters:
  • Target of 2
  • Passthrough with 33 power comming in
  • Passthrough with 3 power comming in
Results in CopyPaste:
Counters all load in with targets of 10, none as passthrough. None allowing power through since target is not met.

Results in RB:
Counters all load in with targets of 10, none as passthrough. All allowing power through despite targets not being met.
I guess I should've mentioned you need to re-copy the base from CopyPaste :)

Also they have power because everything gets power automatically in RB. I'll exclude PowerCounter.

And re-download from https://pastebin.com/m7Lvg7ea

Merged post

If you could tell me what other IO shouldn't get infinite power automatically and why, like PowerCounter, then I can exclude them also
Created new test platform with same features, and same results regarding the counters.

I think things that are connected to a power source should not be overridden by the magic power source (sorry just not sure what to call it hehe)

Speakers, targets, branches, etc, all these seem to be powered even though they are connected to a power source that is currently not sending power through a device in the chain.

A flag to enable/disable the power source I think would be best instead of having to check each device maybe. I would expect that to be a global toggle, and not per base (that would be a pita I bet)

Two use cases for mine are:
  • Locked door, knocking target triggers door unlock and fires off a tesla coil to push player inward.
  • Counters placed throughout a base with a passthrough set to show a specific number (used later in a puzzle).
  • If the user finds the numbers and puts them in correct order, using buttons/counters it unlocks a door only when the counters match that number set.

If things are powered initially then, theres no way to really control the scenario using the electrical items other than basic palcement.
Yea, infinite power seems to be a problem on everything except turrets, samsites and door controllers

Turrets have always worked without power. I have no solution for them atm since they activate (when players enter) and deactivate (when players leave) on their own now. But I will in the future detect if their power source is dead and leave them offline in that case. I don't know how right now

Door controllers shouldn't need it either so I'll have to figure that out when I have time

So I've removed infinite power from all IO except turrets, samsites and door controllers

You can re-download from https://pastebin.com/m7Lvg7ea
@nivex Thanks again, as always. I will go post in the CopyPaste help section regarding the counters, because even after that code change you suggested, they arent pasting in properly (just pasting not using RB to load them)

Im on vacation this week, and foresee me spending most of it playing with all the ideas I have for this plugin on our server HAHA
Did you re-copy the base after making the changes to the CopyPaste.cs file?
I did yes, made an entirely new platform. I can make a new structure and share it again if you want.
If you followed the instructions properly then it should've worked. So I don't why it isn't. Let's hope you goofed eh

Send me a message with the links to the base and your modified CopyPaste.cs file. We'll continue to post here afterwards.
Right on, my money is on me having goofed. I will restart from scratch w a test base here shortly after I get a break in stream. Then post back here with links.

Merged post

@nivex I have created a single foundation in Fortify with 1 power box and 1 counter. Reloaded all plugins. Server has been rebooted (its my local test box)

Using your edits to CopyPaste.cs results in counter set with target of 10 instead of how it was saved in Fortify as target of 2. (this is the default state for newly placed counters, right?)

Call me crazy, but in the JSON, shouldn't I be seeing some reference to the settings of not only the counter but also the power generator? Its power is set to "321". Nowhere in the JSON does that exist. I dont think this is a copypaste issue, or a RB issue now, I think its Fortify.

Thoughts? Posting in their discord to see what they have to say as well.

Same outcome in RB as expected, since it uses the paste from CP.

CopyPaste file with your edits: https://pastebin.com/hsZvL0y7
Fortify Text: https://pastebin.com/eanXSrtT
Fortify JSON: https://pastebin.com/afX7n4QY

Merged post

@nivex Fortify help channel, Ferg says that that info is not saved in the JSON, as I suspected and they havent included it because the code in CopyPaste is commented out.

They hope a patch is soon for this as well as other issues. So with your changes to CopyPaste my monies on the issue being resolved. I will post the same info in CopyPaste as well.

Once again, Nivex, thank you for your help even when it was not an issue with your plugin.
So Fortify isn't including it?

The commented out section is what we edited...
nivex
So Fortify isn't including it?

The commented out section is what we edited...
Correct on both counts. I mentioned the code changes regarding the commented out sections etc, and they implied they would include them in next patch.

If you look at the JSON I posted, there is no data regarding the values for the counters. So now, once Fortify updates that, we can confirm for real if the changes you suggest to CopyPaste did the job.

Either way, glad to know its finally confirmed as to what/where the issue is.