iPhone App Directory
RPG Maker VX
 
Gallery Members Search Calendar Help


Welcome Guest ( Log In | Register )

Collapse

>Announcement

The 2nd Quarter Contest has arrived! Go check it out in the Community Announcements now!

> Note for Tutorial Threads

New threads (tutorials) here will go into a moderation queue. You will not see your thread appear when you create it. A moderator will decide if it will be approved or denied.

 
Reply to this topicStart new topic
> [-Scripting-] Scripts in Events FAQ, Just some quick pointers, and tips
Rating 3 V
IceDragon
post May 1 2011, 05:29 PM
Post #1


I demand cookies.
Group Icon


Type: Coder
Alignment: Neutral Good




-Scripting in Events FAQ-
by IceDragon

-Introduction-

So, out of boredom I decided to do this, I'll try to answer all script related questions regarding eventing.
<.< Now don't blame me if you don't understand something.
http://www.rpgmakervx.net/index.php?showforum=39 # << Start reading the stuff here if your a scripter/coder (even if your not)
I'm not gonna explain the basics of ruby, I'm just gonna assume you have some knowledge of ruby by now.
Now if your just starting RMVX, my advice, return self, learn the editor first.
Some of the things here can be done without scripting.


-The FAQ-
So I'll answer some of the most common questions.
Spoiler:

Event Control Commands # - Its best to look at this first before continuing


Event Script Command # - This is the event script command



-BASICS-
Just a few things I need to address before continuing.
Data Types (only some though)
Spoiler:

Strings, Integers, Floats, Booleans ; (Data Types)
CODE
# // -String-
"This is a string"
"2"

# // -Integer-
2
-2

# // -Float-
2.00
-3.41

# // -Boolean-
true
false



Special and Mathematical Operation symbols
Spoiler:

CODE
# // -Basic-

+ Addition
- Subtraction
* Multiplication
/ Division

# // -Comparison-

!  Not (when place infront of a boolean expression)
<  Less Than
>  Greater Than
== Equal to?
<= Less than or Equal to?
>= Greater than or Equal to?
!= Not Equal to?

# // And more stuff...

#  Ruby Comment Line
|| Or (symbol)
&& And(symbol)




Spoiler:

QUES How do I store value n(integer) in variable x(variable_id)?
ANS
CODE
$game_variables[variable_id] = integer

# // Examples
$game_variables[2] = 4
$game_variables[12] = -18


QUES How do I change the value of a switch?
ANS
CODE
$game_switches[switch_id] = boolean

# // Examples
$game_switches[100] = true
$game_switches[9] = false





-ACTOR-
*clears throat* Okay so everything here pretains to the Game_Actor class so anything done on the $game_actors[id] can be done on the $game_party.members[index]
Assuming the actor exists.

Spoiler:

QUES How do I get n party member?
ANS
CODE
$game_party.members[member_index]
# // NOTE member_index starts at 0 so if the party has 4 members, its 0, 1, 2, 3 as there indecies.
# // Examples
$game_party.members[0]
$game_party.members[1]
$game_party.members[7]


QUES How do I get n Actor?
ANS
CODE
$game_actors[actor_id]
# // NOTE actor 0 is non existent, >.> unless a script put it there.

# // Examples
$game_actors[2]
$game_actors[18]


QUES How do I get a, b, c from Actor n?
ANS
CODE
# // HP
$game_actors[actor_id].hp
$game_actors[actor_id].maxhp
# // MP
$game_actors[actor_id].mp
$game_actors[actor_id].maxmp
# // ATK
$game_actors[actor_id].atk
# // DEF
$game_actors[actor_id].def
# // SPI
$game_actors[actor_id].spi
# // AGI
$game_actors[actor_id].agi

# // LEVEL
$game_actors[actor_id].level
# // ID
$game_actors[actor_id].id




-EVENT/PLAYER-
A common error is this
$game_events
DON'T DO EEEEEEET!

Its :
$game_map.events


Spoiler:

QUES How do I get n Event?
ANS
CODE
$game_map.events[event_id]

# // Examples
$game_map.events[2]
$game_map.events[5]


QUES How do I get the current Event?
ANS
CODE
$game_map.events[@event_id]
# // NOTE @event_id is a public_instance variable in the Game_Intepreter class

# // Example
$game_map.events[@event_id]


QUES How do I get the Player?
ANS
CODE
$game_player


QUES How do I move event/player to x, y?
ANS
CODE
$game_player.moveto(x, y)
$game_map.events[event_id].moveto(x, y)
// NOTE This will simply plop the character to xy, they won't "move" to x, y


QUES How do I get an event's/player's x, y?
ANS
CODE
$game_player.x
$game_player.y
$game_map.events[event_id].x
$game_map.events[event_id].y


QUES How do I get events at x, y?
ANS
CODE
$game_map.events_xy(x, y)
# // Note this returns an Array, if you have no idea what that is, go read a programming tut.


QUES How do I find if event/player is at x, y?
ANS
CODE
#// 2 Ways
#// 1
($game_player.x == x and $game_player.y == y)
($game_map.events[event_id].x == x and $game_map.events[event_id].y == y)
#// 2
$game_player.pos?(x, y)
$game_map.events[event_id].pos?(x, y)


QUES How do I activate an event?
ANS
CODE
$game_map.events[event_id].start
# // NOTE be careful with this, you can actually chain activate events
# // Examples
$game_map.events[1].start
$game_map.events[2].start
$game_map.events[3].start





-CONDITIONS-
Ahh yeah~
I'm not gonna get into cases .

Spoiler:

CODE
if sumthing
  do_stuff
elsif sumthing_else  
  do_other_stuff
else  
  do_else_stuff
end  

# // Note unless is the opposite of if
unless sumthing
  do_stuff
elsif sumthing_else  
  do_other_stuff
else  
  do_else_stuff
end




-MAP-

Spoiler:

QUES How do I get the current maps ID?
ANS
CODE
$game_map.map_id


QUES How do I get the tile_id at x, y?
ANS
CODE
$game_map.data[x, y, z]
# // NOTE The data object for a map is a Table with 3 layers; (0, 1, 2) it starts at 0.
# // This first layer is all your A tiles (except some, like the tall grass for eg)
# // The second layer is where the other overlaying A tiles go
# // The third layer is Tiles B to E

# // Examples
$game_map.data[1, 1, 2]
Returns the B~E tile_id at 1, 1

$game_map.data[1, 1, 0]
Returns the B~E tile_id at 1, 1


>.> If you want to get the tile_id for the tile the player is currently standing on...
Use the knowledge you gained from above...



-ALL TOGETHER NOW-
I'm gonna pull some stunts that weren't mentioned okay.

Spoiler:

CODE
# // Get Player's XY and see if it matches Event 2
px = $game_player.x
py = $game_player.y
if $game_map.events[2].pos?(px, py)
p "Positions Match"
else
p "Positions do not Match"
end

# // A more useful version, assigning the value to switch 5
px = $game_player.x
py = $game_player.y
val= $game_map.events[2].pos?(px, py)
$game_switches[5] = val

# // Getting the first party members level and storing it in variable 10
mem = $game_party.members[0]
$game_variables[10] = mem.level

# // But WHAT IF X doesn't exist?
# // NOTE nil is the... what ya call the, null, valueless, errr value(-less)...
mem = $game_party.members[0]
unless mem == nil
  mem = $game_party.members[0]
  $game_variables[10] = mem.level
end




# // Last Modified 05/02/2011

If you have a question, and it somehow, wasn't covered feel free to post here about it.

~IceDragon

This post has been edited by IceDragon: May 6 2011, 08:35 PM


--------------------
Spoiler:





To be Hexa-fied


Spoiler:
Other/Reminders--
Support your cookie loving dragon!

CODE
[url="http://www.rpgmakervx.net/index.php?showuser=52960"][img]http://i56.tinypic.com/2d1pfmw.png[/img][/url]


http://www.rpgmakervx.net/index.php?showto...amp;#entry48215 HA AUTOTILES
Pine's Birthday is the 2th of July

WORK ON YOUR TIME MEMORY @___@
Go to the top of the page
 
+Quote Post
   
quigonkeichy
post May 2 2011, 12:52 PM
Post #2


I MOVE THE STARS FOR NO ONE.
Group Icon


Type: Writer
Alignment: Lawful Evil




This is pretty cool actually, always wondered what I could put in the 'Script' command that wasn't necessarily to do with the scripts that I had installed already. Cheers for this!


--------------------





My project!



I support:
Spoiler:









Go to the top of the page
 
+Quote Post
   
wltr3565
post May 2 2011, 04:01 PM
Post #3


The best BAKA ever
Group Icon


Type: Undisclosed
Alignment: True Neutral




? I don't see how to get the activating event itself. Fretting something for the activating event itself via script command should be the simplest smile.gif

Good reference for me, thanks smile.gif


--------------------
This place is empty, just like I restarted myself.
Go to the top of the page
 
+Quote Post
   
IceDragon
post May 2 2011, 04:26 PM
Post #4


I demand cookies.
Group Icon


Type: Coder
Alignment: Neutral Good




>.> Didn't expect someone to want that.
Well its like this:
CODE
event.start # // as simple as that

$game_map.events[event_id].start


Added to FAQ.


--------------------
Spoiler:





To be Hexa-fied


Spoiler:
Other/Reminders--
Support your cookie loving dragon!

CODE
[url="http://www.rpgmakervx.net/index.php?showuser=52960"][img]http://i56.tinypic.com/2d1pfmw.png[/img][/url]


http://www.rpgmakervx.net/index.php?showto...amp;#entry48215 HA AUTOTILES
Pine's Birthday is the 2th of July

WORK ON YOUR TIME MEMORY @___@
Go to the top of the page
 
+Quote Post
   
Ravenith
post May 4 2011, 02:43 PM
Post #5


Your friendly neighborhood lunatic.
Group Icon


Type: Designer
Alignment: Neutral Good




Well, it's not a tutorial for beginners of the craft, to be sure. But it's the absolutely most interesting piece of work for both scripting beginners and eventing intermediate users! Way to go!


--------------------
Go to the top of the page
 
+Quote Post
   

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 19th April 2014 - 11:06 AM

RPGMakerVX.net is an Privacy Policy, Legal.