HOW DO YOU CALL THE ENEMIES TROOP NUMBER WHILE SCRIPTING IN VX?

Posts

Pages: 1
I'm attempting to make a script and I need to use the troop number as a variable. Any ideas on how to do this?

I've tried:
$game_troop.troop_id
and
$game_enemy.index

but neither of those seem to work.
Try following:
$game_troop.members[X]
I'm not 100% sure what you're trying to do though.

Edit: This allows you to do something to troop number X. If that's not what you wanted, can you explain more throughout what you want to do?
I'm trying to get a variable 'troopidnumber' to equal what the troops number is in the index. So when battle starts if troop 1 is slime x 2, I want my variable 'troopidnumber' to equal 1.
I figured it out!

$game_player.make_encounter_troop_id

nevermind, that only works if a map only has one troop on it :-/
so this is the point i've gotten to. this is the formula that gets the number i need.

def make_encounter_troop_id
encounter_list = $game_map.encounter_list.clone
for area in $data_areas.values
encounter_list += area.encounter_list if in_area?(area)
end
if encounter_list.empty?
make_encounter_count
return 0
end
return encounter_list(rand(encounter_list.size))
end


when i call game_player.make_encounter_troop_id though, it re-runs this formula instead of giving me its value. any idea on how i can get the value from the first time it was run without running the formula a second time?
KingArthur
( ̄▽ ̄)ノ De-facto operator of the unofficial RMN IRC channel.
1217
You can encapsulate the code that calculates the encounter_list value inside an if statement with a condition that would only be applicable on first run (ie: if some_certain_variable == some_certain_value).
I'm not sure I understand what you mean (I'm like brand new to ruby, as in just started messing with it 2 days ago, ha).
KingArthur
( ̄▽ ̄)ノ De-facto operator of the unofficial RMN IRC channel.
1217
Basically, make it so the "formula" is only executed when a certain condition that'd only be applicable when the "formula" hasn't run yet is true.

Something like this:
def foo
if (bar == null)
bar = 2
end
return bar # I want to return 2 here.
end
I tried that, but it wasn't what I needed. I've been watching scripting tutorials and finally figured it out. I had to set @troop_id as attr_accessor in game troop. The script I made will be available soon! Thanks for the help though!
Here's the code from command "Call Battle".
def command_301

return true if $game_temp.in_battle
if @params[0] == 0 # Direct designation
troop_id = @params[1]
else # Designation with variables
troop_id = $game_variables[@params[1]]
end
if $data_troops[troop_id] != nil
$game_troop.setup(troop_id)
$game_troop.can_escape = @params[2]
$game_troop.can_lose = @params[3]
$game_temp.battle_proc = Proc.new { |n| @branch[@indent] = n }
$game_temp.next_scene = "battle"
end
@index += 1
return false
end

Basically, it's $game_troop.setup(troop_id), $game_temp.battle_proc = Proc.new { |n| @branch = n } and $game_temp.next_scene = "battle" what you need. If something occurs, define can_escape and can_lose too like in the reference.

Salut,
Orochii Zouveleki
Pages: 1