• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

[Scripting Question] Checking whether you have a Trainer's phone number? -pbHasPhoneTrainer?(trtype,trname)-

40
Posts
8
Years
  • So I've been trying to implement randomized trades into my game, thinking it would be super difficult, but so far so good! I've basically been able to figure everything out that I need, and I'm basically using a few Common Events to do it. Basically I want to make it so that your "rematch" contacts in the phone will occasionally call you and offer a semi-randomized trade. My question's not really about that, but it's related. I've got everything working how I want, I just have to make it so that your Phone Contacts will call you every so often for the Trade. The way I'm thinking of getting that to work is by having a common event that "fires" every in game hour or so that will randomly select a trainer from a list, then check if you've registered that contact into your phone yet, then just flip a switch that starts the whole trade thing.

    I can't for the life of me figure out how to have the game check if you've registered a specific trainer as a contact or not...I've been looking through the scripts and found the Contact Information section of Pitem_Phone, and I think the script I want to put in a conditional branch is "pbHasPhoneTrainer?(trtype,trname)" and I can't seem to find any information about it. I'm pretty sure that "trtype" is the trainer type ID in trainertypes.txt (10 for bugcatchers, for example) and I assumed that "trname" would be...the trainer's name, so I put in "pbHasPhoneTrainer?(10,Pete), but I got an error saying:

    ...
    Exception: NameError
    Message: (eval):1:in `pbExecuteScript'uninitialized constant Interpreter::Pete

    ***Full script:
    pbHasPhoneTrainer?(10,Pete)
    ...

    So...I have no idea what to put in for "trname", or even if this is the correct script for what I want to do, for that manner, haha. Do any of you guys know what I'm doing wrong?
     
    1,682
    Posts
    8
    Years
    • Seen today
    So the two arguments to pbHasPhoneTrainer? are the trainer type, and the trainer name.
    The type can be the symbol, for the record, which means you don't have to change all of those 10s if you end up shuffling the numbers. The name has to be a String. So you want pbHasPhoneTrainer?(:BUGCATCHER,"Pete")
     
    Last edited:
    40
    Posts
    8
    Years
  • :|

    Ha, ya, something tells me I could have figured that out on my own, lol. Just forgot the quotation marks...

    Thanks again, haha
     
    40
    Posts
    8
    Years
  • Ok, so I have a new problem, now...I get a crash again, but with a different error:

    Exception: ArgumentError
    Message: PItem_Phone:99:in `pbFindPhoneTrainer'wrong number of arguments(0 for 2)
    ***Full script:
    pbHasPhoneTrainer?(10,"Pete")

    All I did was include the quotes, and now I'm clueless again...
     
    40
    Posts
    8
    Years
  • Oh, and I tried (:BUGCATCHER,"Pete") but it still gives the "wrong number of argument (0 for 2) error above, just to clarify.
     
    1,682
    Posts
    8
    Years
    • Seen today
    i think there's an error in the code of pbHasPhoneTrainer? itself. it looks like its not passing the arguments forward.
    you'll have to edit the method to give the arguments to pbFindPhoneTrainer.

    it's not the first time unused built in stuff is broken.
     
    40
    Posts
    8
    Years
  • Oh I see. Alas, scripting is not my strong suit...but at least I know what the problem is now, I'll try and see what I can figure out.
     
    1,682
    Posts
    8
    Years
    • Seen today
    I knew I forgot something today.
    Code:
    def pbHasPhoneTrainer?(trtype,trname)
      return pbFindPhoneTrainer(trtype,trname)!=nil
    end
    That should do the trick!
     
    40
    Posts
    8
    Years
  • Actually I have one more question for you, since you've been so helpful, haha. I want a common event to "fire" every hour or so, and I think to do that I need to run a time delay script whenever the map updates. I've been checking out the rematch battle section of the scripts, but again, scripting is not my strong suit, and I don't really know how the map update system works. So ya, do you know how I might run a common event every hour?
     
    153
    Posts
    4
    Years
    • Seen Feb 4, 2020
    You want it to reset every hour if used before or you want it to be activated every
    hour whatever happens elsewhere?

    in the first case you need an event with a selfswitch which makes it doing nothing after first use and have a timer switching this switch to off after an hour
    in the second case you can just use conditional branches with time of day conditions script. example here from an event I made
    Code:
    pbGetTimeNow.wday == 0 &&(pbGetTimeNow.hour >= 12)
    here it says if it's day 0 (I think it's sunday, not sure anymore) and the time is less than 12 then do. You could have for example if it's 12 or 13 or 14 or 15... (or are written || instead of &&)
     
    40
    Posts
    8
    Years
  • I want it to work how phone calls with trainers do. Like, I think every 20 or 30 minutes a random contact in your phone calls you and either ask someone for a rematch or just generates a random message. I want to do something like that. I'm familiar with how pbSetEventTime works and everything, but it just applies for a single event, whereas I want this timer to apply globally, if that makes sense.
     
    153
    Posts
    4
    Years
    • Seen Feb 4, 2020
    Ok sorry then I'm not sure how to do it. I have been looking for how to do a global event for ages and could only partially solve my problems with parallel processes which are only working on one map but together with variables which are global it kinda does the trick. But if you find out how I'm really interested :D
     
    Last edited:
    40
    Posts
    8
    Years
  • I think it might have to be done via scripts...like, essentials does trainer rematches that way as far as I can tell. Unfortunately I am below novice level at scripting...but I'll keep experimenting and see what I can find out.
     
    40
    Posts
    8
    Years
  • Ok, so I think I actually figured it out. Thought I'd share the script since you wanted to know. Basically I adapted this script in PItem_Phone:
    Code:
    #===============================================================================
    # Phone-related counters
    #===============================================================================
    Events.onMapUpdate+=proc {|sender,e|
      if !$PokemonGlobal || !$game_player || !$game_map ||
         !$Trainer || !$Trainer.pokegear
        # do nothing
        next
      elsif !$PokemonGlobal.phoneTime || $PokemonGlobal.phoneTime<=0
        $PokemonGlobal.phoneTime = 20*60*Graphics.frame_rate #20 minutes
        $PokemonGlobal.phoneTime += rand(20*60*Graphics.frame_rate) #+0 to 20 minutes
      end
      $PokemonGlobal.phoneNumbers = [] if !$PokemonGlobal.phoneNumbers
      if !$game_temp.in_menu && !$game_temp.in_battle &&
         !$game_player.move_route_forcing && !$game_temp.message_window_showing &&
         !pbMapInterpreterRunning?
        $PokemonGlobal.phoneTime -= 1
        if $PokemonGlobal.phoneTime%10==0
          for num in $PokemonGlobal.phoneNumbers
            if num[0] && num.length==8 # if visible and a trainer
              if num[4]==0 # needs resetting
                num[3] = 2000+rand(2000) # set time to can-battle
                num[4] = 1
              end
              num[3] -= 1
              if num[3]<=0 && num[4]==1
                num[4] = 2 # set ready-to-battle flag
                pbSetReadyToBattle(num)
              end
            end
          end
        end
        if $PokemonGlobal.phoneTime<=0
          # find all trainer phone numbers
          phonenum = pbRandomPhoneTrainer
          if phonenum
            call = pbPhoneGenerateCall(phonenum)
            pbPhoneCall(call,phonenum)
          end
        end
      end
    }

    To this:
    Code:
    #===============================================================================
    #This script will activate a switch every x amount of time.
    #===============================================================================
    Events.onMapUpdate+=proc {|sender,e|
      if !$PokemonGlobal || !$game_player || !$game_map ||
         !$Trainer || !$Trainer.pokegear
        # do nothing
        next
      elsif !$PokemonGlobal.phoneTradeTime || $PokemonGlobal.phoneTradeTime<=0
        $PokemonGlobal.phoneTradeTime = 50*60*Graphics.frame_rate         #the time interval.
                                                                          #second number (60) represents 1 minute
                                                                          #first number (50) is the number of minutes
                                                                          #this will "fire" every 50 minutes
        
        $PokemonGlobal.phoneTradeTime += rand(20*60*Graphics.frame_rate)  #Optional randomization.  
                                                                          #This adds a random number of 
                                                                          #minutes to the time above 
                                                                          #between 0 and 20.
      end
      $PokemonGlobal.phoneNumbers = [] if !$PokemonGlobal.phoneNumbers
      if !$game_temp.in_menu && !$game_temp.in_battle &&
         !$game_player.move_route_forcing && !$game_temp.message_window_showing &&
         !pbMapInterpreterRunning?
        $PokemonGlobal.phoneTradeTime -= 1
        if $PokemonGlobal.phoneTradeTime<=0
        $game_switches[PHONE_TRADE_TIME_SWITCH] = true #the switch you want to activate, 
                                                       #you can define it in the settings
                                                       #if you like, as I did here.  
                                                       #You should make the event run 
                                                       #once, then turn off the switch 
                                                       #to prevent endless loops
        end
      end
    }
    And put it in a new script section.

    Basically what it does is make it so that every hour, give or take 20 minutes (you can change the time to whatever you want) it turns on a switch. You also have to go into PField_Metadata and add in the
    "attr_accessor :phoneTradeTime" at the bottom of the Global Metadata class, as well as adding in "@phoneTradeTime =0" at the bottom of "def initialize" too. Of course, you don't have to call it ":phoneTradeTime", you can use whatever you want, so long as you change the script accordingly, of course.

    If you use this with Common Events that activate via Condition Switch, you can make all sorts of interesting events that will activate on a regular basis! I don't know if that's exactly what you're looking to do, but hope this helps anyway :D
     
    1
    Posts
    3
    Years
    • Seen Dec 14, 2020
    Thank you for this thread! I had a similar situation and I managed it thanks to you. I added a little bit to your idea. Since these are just random numbers, you need to be careful. So I decided to make an automatic procedure for checking the phone number through the service before that. I can find out for example who calls from 3523029080 and be sure that this phone is not a Scam or spammer. I think this is very convenient, and you will always be sure that the rooms are normal, clean and you will not fall for some bullshit. Your idea is cool!
     
    Last edited:
    Back
    Top