Mini Objective Script
#1
Mini Objective Script - R1
Dubealex

Jul 18 2005

This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.


code and instructions fixed

This script will allow the player to press a button (the * on the numpad by default) to display a small window at the bottom of the screen displaying the present goal, the goal stats and an hint (optional). This window is a pop-up, and the player can continue playing while its open - The player can press the Goal button again to hide it.

The developer of the game have some basic tool to mainpulate the goal he set in the game, those tool will be listed below the following script, in the instruction manual.

First of all, this script requieres Cybersam's Keyboard Input Script V4, that you can take right here.

STEP 1: Insert the Keyboard Input Script:
Copy the following script just above MAIN and call it KB Input
Code:
#======================================
# â–  Keyboard Script
#---------------------------------------------------------------------------
#  By: Cybersam
#   Date: 25/05/05
#   Version 4
#======================================

module Kboard
#--------------------------------------------------------------------------
$RMouse_BUTTON_L = 0x01        # left mouse button
$RMouse_BUTTON_R = 0x02        # right mouse button
$RMouse_BUTTON_M = 0x04        # middle mouse button
$RMouse_BUTTON_4 = 0x05        # 4th mouse button
$RMouse_BUTTON_5 = 0x06        # 5th mouse button
#--------------------------------------------------------------------------
$R_Key_BACK      = 0x08        # BACKSPACE key
$R_Key_TAB       = 0x09        # TAB key
$R_Key_RETURN    = 0x0D        # ENTER key
$R_Key_SHIFT     = 0x10        # SHIFT key
$R_Key_CTLR      = 0x11        # CTLR key
$R_Key_ALT       = 0x12        # ALT key
$R_Key_PAUSE     = 0x13        # PAUSE key
$R_Key_CAPITAL   = 0x14        # CAPS LOCK key
$R_Key_ESCAPE    = 0x1B        # ESC key
$R_Key_SPACE     = 0x20        # SPACEBAR
$R_Key_PRIOR     = 0x21        # PAGE UP key
$R_Key_NEXT      = 0x22        # PAGE DOWN key
$R_Key_END       = 0x23        # END key
$R_Key_HOME      = 0x24        # HOME key
$R_Key_LEFT      = 0x25        # LEFT ARROW key
$R_Key_UP        = 0x26        # UP ARROW key
$R_Key_RIGHT     = 0x27        # RIGHT ARROW key
$R_Key_DOWN      = 0x28        # DOWN ARROW key
$R_Key_SELECT    = 0x29        # SELECT key
$R_Key_PRINT     = 0x2A        # PRINT key
$R_Key_SNAPSHOT  = 0x2C        # PRINT SCREEN key
$R_Key_INSERT    = 0x2D        # INS key
$R_Key_DELETE    = 0x2E        # DEL key
#--------------------------------------------------------------------------
$R_Key_0         = 0x30        # 0 key
$R_Key_1         = 0x31        # 1 key
$R_Key_2         = 0x32        # 2 key
$R_Key_3         = 0x33        # 3 key
$R_Key_4         = 0x34        # 4 key
$R_Key_5         = 0x35        # 5 key
$R_Key_6         = 0x36        # 6 key
$R_Key_7         = 0x37        # 7 key
$R_Key_8         = 0x38        # 8 key
$R_Key_9         = 0x39        # 9 key
#--------------------------------------------------------------------------
$R_Key_A         = 0x41        # A key
$R_Key_B         = 0x42        # B key
$R_Key_C         = 0x43        # C key
$R_Key_D         = 0x44        # D key
$R_Key_E         = 0x45        # E key
$R_Key_F         = 0x46        # F key
$R_Key_G         = 0x47        # G key
$R_Key_H         = 0x48        # H key
$R_Key_I         = 0x49        # I key
$R_Key_J         = 0x4A        # J key
$R_Key_K         = 0x4B        # K key
$R_Key_L         = 0x4C        # L key
$R_Key_M         = 0x4D        # M key
$R_Key_N         = 0x4E        # N key
$R_Key_O         = 0x4F        # O key
$R_Key_P         = 0x50        # P key
$R_Key_Q         = 0x51        # Q key
$R_Key_R         = 0x52        # R key
$R_Key_S         = 0x53        # S key
$R_Key_T         = 0x54        # T key
$R_Key_U         = 0x55        # U key
$R_Key_V         = 0x56        # V key
$R_Key_W         = 0x57        # W key
$R_Key_X         = 0x58        # X key
$R_Key_Y         = 0x59        # Y key
$R_Key_Z         = 0x5A        # Z key
#--------------------------------------------------------------------------
$R_Key_LWIN      = 0x5B        # Left Windows key (Microsoft Natural keyboard)
$R_Key_RWIN      = 0x5C        # Right Windows key (Natural keyboard)
$R_Key_APPS      = 0x5D        # Applications key (Natural keyboard)
#--------------------------------------------------------------------------
$R_Key_NUMPAD0   = 0x60        # Numeric keypad 0 key
$R_Key_NUMPAD1   = 0x61        # Numeric keypad 1 key
$R_Key_NUMPAD2   = 0x62        # Numeric keypad 2 key
$R_Key_NUMPAD3   = 0x63        # Numeric keypad 3 key
$R_Key_NUMPAD4   = 0x64        # Numeric keypad 4 key
$R_Key_NUMPAD5   = 0x65        # Numeric keypad 5 key
$R_Key_NUMPAD6   = 0x66        # Numeric keypad 6 key
$R_Key_NUMPAD7   = 0x67        # Numeric keypad 7 key
$R_Key_NUMPAD8   = 0x68        # Numeric keypad 8 key
$R_Key_NUMPAD9  = 0x69        # Numeric keypad 9 key
$R_Key_MULTIPLY  = 0x6A        # Multiply key (*)
$R_Key_ADD       = 0x6B        # Add key (+)
$R_Key_SEPARATOR = 0x6C        # Separator key
$R_Key_SUBTRACT  = 0x6D        # Subtract key (-)
$R_Key_DECIMAL   = 0x6E        # Decimal key
$R_Key_DIVIDE    = 0x6F        # Divide key (/)
#--------------------------------------------------------------------------
$R_Key_F1        = 0x70        # F1 key
$R_Key_F2        = 0x71        # F2 key
$R_Key_F3        = 0x72        # F3 key
$R_Key_F4        = 0x73        # F4 key
$R_Key_F5        = 0x74        # F5 key
$R_Key_F6        = 0x75        # F6 key
$R_Key_F7        = 0x76        # F7 key
$R_Key_F8        = 0x77        # F8 key
$R_Key_F9        = 0x78        # F9 key
$R_Key_F10       = 0x79        # F10 key
$R_Key_F11       = 0x7A        # F11 key
$R_Key_F12       = 0x7B        # F12 key
#--------------------------------------------------------------------------
$R_Key_NUMLOCK   = 0x90        # NUM LOCK key
$R_Key_SCROLL    = 0x91        # SCROLL LOCK key
#--------------------------------------------------------------------------
$R_Key_LSHIFT    = 0xA0        # Left SHIFT key
$R_Key_RSHIFT    = 0xA1        # Right SHIFT key
$R_Key_LCONTROL  = 0xA2        # Left CONTROL key
$R_Key_RCONTROL  = 0xA3        # Right CONTROL key
$R_Key_L_ALT    = 0xA4        # Left ALT key
$R_Key_R_ALT    = 0xA5        # Right ALT key
#--------------------------------------------------------------------------
$R_Key_SEP      = 0xBC        # , key
$R_Key_DASH      = 0xBD        # - key
$R_Key_DOTT      = 0xBE        # . key
#--------------------------------------------------------------------------
GetKeyState = Win32API.new("user32","GetAsyncKeyState",['i'],'i')
GetKeyboardState = Win32API.new("user32","GetKeyState",['i'],'i')
GetSetKeyState = Win32API.new("user32","SetKeyboardState",['i'],'i')
#--------------------------------------------------------------------------
module_function
#--------------------------------------------------------------------------
def keyb(rkey)
   if GetKeyState.call(rkey) != 0
     return 1
   end
   return 0
end
#--------------------------------------------------------------------------
def keyboard(rkey)
  GetKeyState.call(rkey) & 0x01 == 1  #
end
#--------------------------------------------------------------------------
def key(rkey, key = 0)
  GetKeyboardState.call(rkey) & 0x01 == key #
end
end


STEP 2: Insert the Mini Objective Script
Copy the following script just above the KBInput Script and call it Goal

Code:
#=========================================
# Mini Objective Script  - R1
# Script created by Dubealex
#
# June 28, 2005
#=========================================

class Goal #Your objectives

def initialize
  
=begin --------------------------------------------------------------------------------------
  
Here we make a list of every objective the player will have during the game.
This is a MINI objective system, and it's made to be simple and fast.
We need the following parameter per objectives:

> Progress
> Max
> Objective Title
> Hint (optional)

Each goal will ba accesed individually, one at a time, during the game. When the player
start a new objective (i.e: a new puzzle), the parameter of this objective are used in the
window; if he start another one, it will change for that one. In other word, the Mini
Objective System will display only the active quest at hand. This is why I called it
MINI script.

Example: $goal[1]= Set_Goal.new(Max, "Objective Title", "Hint")

i.e: $goal[0] is used to know which Goal is active, it store the ID of the active quest.

If you want to edit how the Goal Window looks like, search the following keyword
and edit the commented line:

GOAL_WINDOW

=end #---------------------------------------------------------------------------------------------    

  $goal[0]= 0 #No quest active at game start - DO NOT change this line !
  $goal[1]= Set_Goal.new(1, "Quest Title", "Your Hint - Optional")



#You do not need to edit anything past this line ! ======================

end
end

#------------------------------------------------------------------------------------------------------

class Set_Goal

attr_accessor :progress
attr_accessor :max
attr_accessor :title
attr_accessor :hint  

def initialize(max, title, hint)
   @max=max
   @progress=progress=0
   @title= title
   @hint= hint
end

def completed?
   if @progress>=@max
     return true
   else
     return false
   end  
end

end  
#------------------------------------------------------------------------------------

#GOAL_WINDOW
#DO not edit the non-commented line, unless you know how to script.

class Goal_Window < Window_Base

def initialize
   super(-5, 380, 650, 105) #The position and size of the window (POS.X, POS.Y, WIDTH, HEIGHT)
   self.contents = Bitmap.new(width - 32, height - 32)
   self.windowskin = RPG::Cache.windowskin("001-Blue01") #The WindowSkin Filename
   self.contents.font.name = "Tahoma"  #The font to be used
   self.contents.font.size = 24 #The size of the text
   self.opacity=180 #Opacity of the Goal Window (255=Opaque)
end

def update
   self.contents.clear
  
   id=$goal[0]
   if id >= 1
    
     progress=$goal[id].progress
     max=$goal[id].max
     title=$goal[id].title
     hint=$goal[id].hint
    
     self.contents.font.color = text_color(6) #Color of the TITLE of the goal
     self.contents.draw_text(0, 0, 640, 32, title.to_s)
     self.contents.font.color = text_color(4) #Color of the STATS for that goal
     self.contents.draw_text(0, 22, 640, 32, progress.to_s + " /" + max.to_s)
     if $goal[id].completed? == false
       self.contents.font.color = text_color(8) #Color of the HINT for the goal      
       self.contents.draw_text(0, 44, 640, 32, hint.to_s)
     else
        self.contents.font.color = text_color(3) #Objective COMPLETED color    
        self.contents.draw_text(0, 44, 640, 32, "Objective Completed !")
     end  
   else
     self.contents.font.color = text_color(2) #NO OBJECTIVE color
     self.contents.draw_text(0, 0, 640, 32, "No Objective")  
   end  
end      
end

#------------------------------------------------------------------------------------


STEP 3: Insert the ADD-ON in Scene_Map

(A) Just below class Scene_Map you must paste the following code:

Code:
#ADDON
def show_goal
   @goal_window.visible=true
end  

def hide_goal
   @goal_window.visible=false
end
#END ADDON


(B) Just below def main you must paste the followi

Code:
#ADDON
   @show_goal_window==false
   @goal_window=Goal_Window.new
   @goal_window.visible=false
  #END ADDON

© STILL in def main, just below loop do, you must paste the following code:ng code:

Code:
#ADDON
   if @show_goal_window==true
     @goal_window.update
      if Kboard.keyboard($R_Key_MULTIPLY) #KEY CONDITION
           @show_goal_window=false
           @goal_window.visible=false
      end
    end
  
    #Check for the * button, the Mini Goal button
    if $game_switches[1]==true  #switch ID= Goal System ON/OFF
      if Kboard.keyboard($R_Key_MULTIPLY) #KEY CONDITION
           @show_goal_window=true
           @goal_window.visible=true  
      end
     end
   #END ADDON


- Remember to change the switch ID in between the brackets by the switch you wanna use to activate/de-activate the goal system !

(D) STILL in def main, below Graphics.freeze, you must add the following code:

Code:
#ADDON
   @goal_window.dispose
  #END ADDON

STEP 4: Insert the ADD-ON in Scene_Title

(A) In command_new_game, just below def command_new_game, you must paste the following code:

Code:
#ADDON
   $goal=[]
   Goal.new           #Load each objective (quest) for the entire game.
   #END ADDON

STEP 5: Insert the ADD-ON in Scene_Load

(A) find the line $game_player = Marshal.load(file) ... You must paste the code shown below AFTER the last Marshal.load(file) line. By default, $game_player is the last one:

Code:
#ADDON
   $goal                     =Marshal.load(file)
  #END ADDON

STEP 6: Insert the ADD-ON in Scene_Save

(A) find the line Marshal.dump($game_player, file) ... You must paste the code shown below AFTER the last Marshal.dump line. By default, $game_player is the last one:

Code:
#ADDON
   Marshal.dump($goal, file)
  #END ADDON

Instruction Manual


(1) Goal Attribute Index


$goal[id].max
$goal[id].progress
$goal[id].title
$goal[id].hint
$goal[id].completed



(2) How to activate a specific goal:

To activate a certain goal, you can simple use the following Call Script:

Code:
$goal[0]=NEW ID

sample: $goal[0]=1

$goal[0] defines which goal is activated. If you want to set no goal as active, you can simple set $goal[0] equal to 0, and the window will show the text "NO OBJECTIVE".

(3) How to maipulate a specific goal:

The way the Goal system works is that the variable $goal[ID] contains all the data you need to access the stats of a certain goal. You can simply replace ID by the ID of the goal you created. You can access those value within Call Script Event.

The way I made the system work is simple: I will describe it with an example goal.

Let's say you have 23 Treasures Chest to get before a gate can open; this is known as the objective "Treasure Chest". The Goal system have the following basic values:

- A unique ID
- A total number of "steps" in the goal
- The progress in those "steps" made by the player
- A title for the goal
- A hint for that goal (optional)

So, in the page that make the treasure chest open, you would add the following Call Script:


Code:
$goal[ID].progress+=1

$goal[ID].progres refer to the progress the player made on that objective. It will always stay in memory, even you activate another goal meanwhile.

You can use $goal[1].progress-=1 to decrease the progress. Or use two equal signs (==) to set the progress to a pre-defined value.

(3) Some tool you have:

You can use the following command to check if a certain goal is completed or not. Each time you run that command, it will send back the value FALSE if it is not completed, and TRUE if it is. (it's a boolean value)


Code:
$goal[id].completed?


So, you can use this in a conditional branch, using the last page (4th).

For other things, you can experiment with the script, and do whatever changes you feel like. This script was made by me for my game, and it's customized for it, and I won't really add-in more features than that -- I wanted it to be simple.

Thanks, and c ya !
}


Possibly Related Threads…
Thread Author Replies Views Last Post
  Change character script jaigai 0 3,187 11-19-2006, 01:00 PM
Last Post: jaigai
  Just a modification of Abyssos' facs script lumina... 0 2,958 11-01-2006, 01:00 PM
Last Post: lumina...
  Credit Script 1.1 acoole 0 2,838 10-24-2006, 01:00 PM
Last Post: acoole
  Script Dev Kit Nick 0 3,227 10-15-2006, 01:00 PM
Last Post: Nick
  Opening Image script sasuke89 0 2,360 07-24-2006, 01:00 PM
Last Post: sasuke89
  Change Color of The diferent Status Script MASTERLOKI 0 2,630 07-18-2006, 01:00 PM
Last Post: MASTERLOKI
  Event Name and ID Search Script Hadriel 0 2,415 06-21-2006, 01:00 PM
Last Post: Hadriel
  Currency Script Split 0 2,653 05-18-2006, 01:00 PM
Last Post: Split
  Book Script and Utility Bruth 0 2,603 05-07-2006, 01:00 PM
Last Post: Bruth
  Individuality Script DrakoShade 0 2,568 03-12-2006, 01:00 PM
Last Post: DrakoShade



Users browsing this thread: 1 Guest(s)