Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Battery Warning?

Hello, I'm requesting a script for a thing that pops up when the computers battery gets low. If it is impossible, I understand.

What:Battery Warning
Why:I know that the computer says it, but for the Pokemon Game.
Details:Like in Pokemon Games, when your GB/A or DS, when your battery is low it says "Your Battery is low. Want to save?" and then yes/no comes up, and yes it says "Saving..." (And it saves), if "No", then it says "You may loose all of your progress if you don't save. Sure?" "Yes"=Dun save. "No"=Save.

Payment:Er..None, sorry. :( Credit in my game though!
 
Meh, nothing is impossible. Keyboard and mouse input was done, why not battery power? And real clock has been made, interaction with a C+ program and Ruby program etc etc...
I believe anything can be done in RGSS.
 

poccil

Sponsor

This function I wrote, called pbBatteryLow?, checks battery power.

Code:
def pbBatteryLow?
 power="\0"*12
 begin
  sps=Win32API.new('kernel32.dll','GetSystemPowerStatus','p','l')
 rescue
  return false
 end
 if sps.call(power)==1
  status=power.unpack("CCCCVV")
  # Battery Flag
  if status[1]!=255 && (status[1]&6)!=0 # Low or Critical
    return true
  end
  # Battery Life Percent
  if status[2]<5 # Less than 5 percent
    return true
  end
  # Battery Life Time
  if status[4]<300 # Less than 5 minutes
    return true
  end
 end
 return false
end

In Pokemon Essentials (my Pokemon functionality suite), the following code can be used.  It uses the pbBatteryLow? function above.

Code:
class PokemonTemp
  attr_accessor :batterywarning
end

Events.onMapUpdate+=proc {|sender,e|
 if !$Trainer || !$PokemonGlobal || !$game_player || !$game_map
 elsif Time.now.sec==0 && !$PokemonTemp.batterywarning && pbBatteryLow? &&
    !$game_player.move_route_forcing &&
    !$game_system.map_interpreter.running? &&
    !$game_temp.message_window_showing
  $PokemonTemp.batterywarning=true
  if Kernel.pbConfirmMessage(_INTL("The game has detected that the battery is low.  Would you like to save the game now?"))
   pbSaveScreen
  elsif Kernel.pbConfirmMessage(_INTL("You may lose your progress if you don't save.  Would you like to save now?"))
   pbSaveScreen
  end
 end
} 
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top