May 25, 2020, 11:26 am

Author Topic: [E2 Tutorial] MP-Tracker  (Read 2075 times)

Offline Spoofzor

  • ByB Fanatic
  • ****
  • Posts: 902
  • What do you mean that's as loud as it can go!?!
    • View Profile
[E2 Tutorial] MP-Tracker
« on: September 16, 2011, 09:18 pm »
Again, these tutorials are for people who want to learn. As long as 1 person is getting help here then these are worth it. You keep reading and I'll keep posting them ;)

Just a quick tutorial for you guys on the Money Printer Tracker I did about a week ago.

We will start with our header:

Code: [Select]
@name MP-Tracker
@inputs Ranger:entity
@outputs Total Count
@persist Printers:array TotalM
@trigger all

For this you will need to have Output Entity + EntID checked on the ranger.
Wire Ranger:entity to Entity
Wire A and B from your screen to Total and Count respectively.

Code: [Select]
if(first()){
    PrintedAmount = 0
}

Pretty easy, just setting the money to 0 if the chip is updated/pasted.

Code: [Select]
if(Ranger:printerType()!=""){
    NO = 0
    A = Ranger:id()
    for(I =1, Printers:count()){
        if(A==Printers[I,entity]:id()){
            NO = 1
        }
    }
    if(NO == 0){
        Printers:pushEntity(Ranger)
    }
}

The reason I used this if-statement condition instead of :isPrinter() is because it acts like a double condition statment.

First it has to be a printer to have a printerType, then the printerType.
Also, isPrinter wasn't working for me for some reason.

Variable NO is like our "Lose" variable in Blackjack if you read that tutorial. We set NO equal to 0 and later we will use this to determin if the printer is already on the list.

Code: [Select]
A = Ranger:id()
for(I =1, Printers:count()){
        if(A==Printers[I,entity]:id()){
            NO = 1
        }
    }
A is a random variable I chose.
We set it equal to the id of the entity (printer in this case) inside the rangers range

We use this id to check it against the already existing Printers array
for loop woop!

Run as many times as there are printers in the array.
If the printer in the ranger 'A' is equal to any of the printers in the array set NO equal to 1

Code: [Select]
if(NO == 0){
        Printers:pushEntity(Ranger)
    }
}

Later in our first if statement, only if NO is still equal to 0 will it add the printer to the list.

Code: [Select]
for(B=1,Printers:count()) {
        PrintedAmount += Printers[B,entity]:printedMoney()
    }

Pretty easy stuff.
Run as many times as there are printers.
PrintedAmount += Printers[B,entity]:printedMoney()
is the same as saying
PrintedAmount = PrintedAmount + Printers[B,entity]:printedMoney()

So it will add each printers money to the total amount.

Code: [Select]
for(C=1,Printers:count()){
        if(!Printers[C,entity]:isPrinter()){
                Printers:remove(C)
            }
    }
To fix a bug I found after releasing the first version of this where,
The printer count wouldn't decrease after a printer exploded.

To fix that all we need to do is use a simple loop to check that every item in the array is a printer

Code: [Select]
if(!Printers[C,entity]:isPrinter()){

this is the same as saying
if The item located at index C is not a printer then:
Code: [Select]
Printers:remove(C)
Remove it from the array.


Now that we have all this information we need to display it

Code: [Select]
Total = PrintedAmount
Count = Printers:count()

Total is equal to our variable PrintedAmount
Count is equal to the number of items in the array Printers

Offline Becki

  • ByB Newbie
  • *
  • Posts: 0
  • Becki <3
    • View Profile
Re: [E2 Tutorial] MP-Tracker
« Reply #1 on: September 16, 2011, 11:26 pm »
You know, you could use E2 entity discovery to eliminate the need for a ranger. <3

suck it pantho.

Offline Hitori the Lone Wolf

  • ByB Champion
  • *****
  • Posts: 2270
  • Cake is so utterly delightful.
    • View Profile
    • Used to own a website and several private servers. Closed them all. Took up sorcery.
Re: [E2 Tutorial] MP-Tracker
« Reply #2 on: September 16, 2011, 11:28 pm »
To be honest I prefer using rangers for scanners and such. Looks more realistic/RP

Offline Spoofzor

  • ByB Fanatic
  • ****
  • Posts: 902
  • What do you mean that's as loud as it can go!?!
    • View Profile
Re: [E2 Tutorial] MP-Tracker
« Reply #3 on: September 16, 2011, 11:51 pm »
You know, you could use E2 entity discovery to eliminate the need for a ranger. <3

I could also use findByModel.
The reason I decided to use a ranger is because I know some people would warp it to find other peoples printers.
And I am not going to be in any way involved in that situation.

<3