Advertiser Content
Male
Canada
Seen 2 Days Ago
Posted 4 Weeks Ago
17 posts
3.6 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?

Vendily

Female
Seen 1 Hour Ago
Posted 1 Day Ago
959 posts
4.2 Years
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")

Vendily

Female
Seen 1 Hour Ago
Posted 1 Day Ago
959 posts
4.2 Years
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.

Vendily

Female
Seen 1 Hour Ago
Posted 1 Day Ago
959 posts
4.2 Years
I knew I forgot something today.
def pbHasPhoneTrainer?(trtype,trname)
  return pbFindPhoneTrainer(trtype,trname)!=nil
end
That should do the trick!

Male
Canada
Seen 2 Days Ago
Posted 4 Weeks Ago
17 posts
3.6 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?
Male
Seen 2 Days Ago
Posted 5 Days Ago
153 posts
160 Days
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
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 &&)
Male
Canada
Seen 2 Days Ago
Posted 4 Weeks Ago
17 posts
3.6 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.
Male
Seen 2 Days Ago
Posted 5 Days Ago
153 posts
160 Days
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
Male
Canada
Seen 2 Days Ago
Posted 4 Weeks Ago
17 posts
3.6 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:
#===============================================================================
# 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:
#===============================================================================
#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
Advertiser Content