Identifying if unknown character is death inflicted

Status
Not open for further replies.

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
I have a way of identifying if any actor in the battle party is equipped with a certain accessory using this script call in a conditional:


$game_party.battle_members.any? {|actor| actor.armors.include?($data_armors[n]) }


with n being the accessory id.


This check does not return which actor is equipped with it.  For most uses that does not matter as it is used to inflict various things on enemies.  However, for one particular item I need to know if the equipped actor is death inflicted so that I can do something.


Is there a way, e.g. another script call, which can do that?


Thank you.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
Are you doing everything in a script call or do you want to set a variable to the member id so you can then use event commands to do the rest?  


.any? just gives you a true/false value.  .select gives you the list of objects that meet the condition.  If you put that into a temporary variable, you can then use .empty? to see if anyone was actually found, and if they were, use [0] to access the first member found (which might be the only member if you only have one of them, so only one person can have it equipped)


So something like this:

Code:
Script: m = $game_party.battle_members.select {|actor| actor.armors.include?($data_armors[n]) }
        $game_variables[x] = m.empty? ? 0 : m[0].id
After that, variable x will contain the id of any actor wearing the accessory, or 0 if nobody is.
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
@Shaz I think I'm being a bit dense this morning, but I can't see how to use that variable in a conditional . 


There is only one of these items, so if it is equipped there will only be one member with it.  So I need to ask if the member identified by that variable is death inflicted.  And I cannot see how to do that with the commands in the conditional branch.  They all seem to require me to pick a specific actor.  Then when it comes to doing a forced action, it needs to be applied to that actor, and again, forced action requires a specific actor.


(What this accessory is doing is reviving the actor, if knocked out in battle.)
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
Yeah, I didn't know what you were going to be doing with it, and all the commands I could think of that manipulate actors allow a variable (I was thinking of the ones in the lower right corner of tab 1).


You could do it without a script by creating a series of conditional branches to see if the variable is 1, then use actor 1; if the variable is 2, use actor 2, etc.  If you have too many actors or prefer to use scripts, then you'll need to work out the script commands for all the event commands you would have run after identifying the actor.  If you list all the commands and the parameters you'd use, and the id of any database lookups (death is 1, but what is the action to be forced?) then we can help you with the rest.
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
@Shaz Some help would be appreciated, because it was to avoid doing loads of conditionals that I started looking for a script call.


The actual structure is quite simple


Is the actor death inflicted? (state 1)


If yes, use force action of skill id 214 on that actor.


If no, do nothing.


Thanks.


EDIT


For clarification, this is being run at the beginning of each turn using Yanfly's Base Troop Events script so that I don't have to put it into each individual troop.
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
So it would be something like this:

Code:
m = $game_party.battle_members.select {|actor| actor.armors.include?($data_armors[n]) }
if !m.empty? 
  actor = m[0]
  if actor.state?(1)
    actor.force_action(214, actor.index)
    BattleManager.force_action(actor)
    Fiber.yield while BattleManager.action_forced?
  end
end
I'm just not sure about the force_action command, and whether Fiber.yield will do anything in a script call.  If you try it and it doesn't work, we could try getting the Interpreter to run the command (though again it's still going to be in a script call, so I don't know ...)

Code:
m = $game_party.battle_members.select {|actor| actor.armors.include?($data_armors[n]) }
if !m.empty? 
  actor = m[0]
  if actor.state?(1)
    @params = [1, actor.id, 214, actor.index]
    command_339
  end
end
 
Last edited by a moderator:
  • Like
Reactions: Kes

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
@Shaz Sadly I know nothing about fiber yield - I thought fiber was what is in your breakfast cereal.


But with the first suggestion he stays dead and with the second I got this error message.


error message.png
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
sorry - change that to empty? with a ? at the end


I'll edit my post too
 
Last edited by a moderator:

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
@Shaz It runs now without an error message but the actor stays dead.  I've run a double check on the item by creating the whole thing with conditionals for the actor who's currently equipped with it, and it works fine, so it's not the item causing the problem.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
Who is supposed to be doing the action, and who is the target?


The way it's set up, the dead actor is doing the force action on himself.  Maybe that's not happening because he's dead and can't do anything.


If that's what the problem is, try replacing this:

Code:
@params = [1, actor.id, 214, actor.index]


with this:

Code:
@params = [1, $game_party.alive_members[0], 214, actor.index]
 
Last edited by a moderator:

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
So if the command "Remove state 1" were added in before the forced action, would that make it work?
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
It might.  You want the actor to do the force action on himself?


I can't check what the remove state command is - Ace won't load for me right now.  I suspect it's just actor.remove_state(1) but if that doesn't work, go into your Game_Interpreter script and search for change state and just see how it's called there.
 
  • Like
Reactions: Kes

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
This works to perfection!  Thank you.


The reason I was trying to get the dead actor to do the forced action is that I have no way (short of doing another whole run of conditionals) of knowing who else is in the party who could be given that action.  I can see now that my approach was, shall we say, a little problematic.


Once more, thank you for your time and expertise.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
Which way did you go?


This line:

Code:
@params = [1, $game_party.alive_members[0], 214, actor.index]


would have made the first living member (who would have been a member of the battle party, and not the member who had the accessory equipped) do the forced action.
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
@ShazNot being a scripter I didn't understand what that meant.  So I took the idea of removing state 1 and inserted it at what I hoped was the right place.  It must have been, because it now works.  The script call now looks like this:

Code:
m = $game_party.battle_members.select {|actor| actor.armors.include?($data_armors[100]) 
}
if !m.empty? 
  actor = m[0]
  if actor.state?(1)
    actor.remove_state(1)
    @params = [1, actor.id, 214, actor.index]
    command_339
  end
end
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
Yes.  I'll break it down for you ...


m = $game_party.battle_members.select {|actor| actor.armors.include?($data_armors[100])
}


Selects all battle members who have armor id 100 equipped, and puts them into an array called 'm'

Code:
if !m.empty? 
  actor = m[0]
Checks to see if 'm' is not empty - if it's empty, everything from the test to the corresponding 'end' (ie - the rest of the script call) will be skipped.  If 'm' is not empty, it puts the first element, which is a Game_Actor object, into a variable called 'actor'

Code:
  if actor.state?(1)
    actor.remove_state(1)
Checks to see if the retrieved actor has state 1.  If it doesn't, everything else is skipped.  If it does have the state, the state is removed (your addition)

Code:
    @params = [1, actor.id, 214, actor.index]
    command_339
Sets up the parameters for the 'force action' command.  The parameters are 1 (an actor is forcing the action rather than an enemy), actor.id (the id of the actor previously retrieved - this is the previously dead actor who has armor #100 equipped), 214 (the action to be forced), actor.index (the battle party index of the actor previously retrieved).


The script is written in a way that there could be several actors, or no actors, who have that armor item equipped.  If it was possible for several to have it equipped at the same time, we could change the script a little to fill m with only those actors who had the armor equipped AND had state 1.  That would allow you to remove the actor.state? test which would reduce the script by a couple of lines.  You could still do that if you were feeling adventurous ;)
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
I don't think I could put the words me/I, script and adventurous in the the same sentence.  I knew what the component parts of the script call meant, it was the alternative suggestion that I didn't understand i.e.

Code:
@params = [1, $game_party.alive_members[0], 214, actor.index]
I had no idea what the [0] was referring to, whereas I'm very familiar with the remove_state command, as I use it in the damage formula.  So I went for the command I understood.


I'm glad we're having this discussion, though, because although this particular piece of equipment will be unique, I might want to use this mechanism again with different states and forced actions.


If there were more than one actor with the item equipped, how would the script call look?  Let us assume that it is not relating to state 1 - because having multiple resurrections would be a trifle OP - but, say, state 87 and the forced action is, say, skill 190.  So there would be no need to worry about having a dead actor being given the Forced Action, it could be any member of the battle party.  Oh - except that there might be a dead actor in the party if things are going wrong, so if the action were given to that actor it would fail.
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
$game_party.alive_members returns an array.  [0] simply grabs the first of those.  In this case, there is no need to test that the array is not empty, as if $game_party.alive_members were empty, everyone would be dead, and you would have gotten a gameover before this point.


I'm not sure I'm grasping your hypothetical situation correctly, so let me know if you need any changes.  If we are looking for possibly multiple actors who have accessory 100 equipped and are inflicted with state 87, and we want them to use skill 190 on themselves and remove the state (so they don't keep doing it each turn), this is how I would begin (I will include comments this time) :

Code:
# grab into an array all battlers who have the accessory and are inflicted with state 87
# we should probably also only include alive members, as a dead member wouldn't be able to execute an action
members = $game_party.battle_members.select{|actor| actor.armors.include?($data_armors[100]) && actor.state?(87) && actor.alive?}

# loop through each (if none were found, the loop won't run, otherwise it will run once for each person found)
members.each do |actor|

  # remove the state if we want to wait until it's added again
  actor.remove_state(87)
  
  # set up the force action - the parameters are:
  # [who is forcing (0=enemy;1=actor), user id/index, skill id, target index]
  @params = [1, actor.id, 190, actor.index]
  
  # and call the Interpreter command to force the action
  command_339
end
This should work, as command_339 is being called on each iteration, and will delay until the action is complete, and then it will move to the next one.  So they won't all execute the actions at the same time, but in turn.


So I would test with that, and if there were errors or it didn't seem to work properly, I'd start tweaking and experimenting.


If you wanted a different actor to execute the action, there are a few ways to do it, but you'd have to decide whether it could still be the person who is the target, filter to exclude dead battlers, and cater for the possibility that the target is the only living battle member (so if you want it to be anyone but the target, you could end up with nobody and that would be an issue).  In this case, you could exclude the actor.alive? test from the array creation in the first command.


I hope that's not all too confusing for you :)
 
Last edited by a moderator:

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
@Shaz Okay, I think I've got this now.  Been doing some gentle experimenting and I am hopeful that I shall be able to do interesting things with this.


Once more, a huge thank you for your time and trouble.


Closing as this is now solved.
 
Last edited by a moderator:
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c

Forum statistics

Threads
105,857
Messages
1,017,018
Members
137,563
Latest member
MinyakaAeon
Top