Looking for some script logic correction.

kerbonklin

Hiatus King
Veteran
Joined
Jan 6, 2013
Messages
1,726
Reaction score
275
First Language
English
Primarily Uses
RMMV
So the following is supposed to, when an enemy chooses a random target for their skills, check the TGR first (like the default engine), and then if there's no mutations (tgr_rand not making the choice to Return member), the enemy will be checked for 4 possible states, each check checking each alive member for a specific actor id, and then Return that member to target for its skill. if none of the 4 checks apply, then it just does alive_members[0] at the very end. (like the default engine)

Each of my actors have a standard 100% TGR rate, no other changes. Right now i'm checking the aggro affect with 2 actors VS 2 enemies, but it's not working properly and they're still targeting whoever. The state work is completely fine, but there must be something wrong with this code logic that i'm not grasping. Oh and this is an overwrite by the way.

Code:
  #--------------------------------------------------------------------------  # * Random Selection of Target with Aggro State Check  #--------------------------------------------------------------------------  def random_target            tgr_rand = rand * tgr_sum    alive_members.each do |member|      tgr_rand -= member.tgr      return member if tgr_rand < 0      end    if tgr_rand == 0       #Probably might be cause of this, idunno how the calculations work      if not self.actor?    #Check if enemy        if self.state?(116) #Check if enemy has aggro state          alive_members.each do |member|            if member.id == $game_actors[1]     #Or maybe these aren't working like I expected              return member            end          end        elsif self.state?(117)          alive_members.each do |member|            if member.id == $game_actors[2]              return member            end          end        elsif self.state?(118)          alive_members.each do |member|            if member.id == $game_actors[3]              return member            end          end        elsif self.state?(119)          alive_members.each do |member|            if member.id == $game_actors[4]              return member            end          end        end      end    end    alive_members[0]  end
 
Last edited by a moderator:

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,513
Reaction score
3,203
First Language
Binary
Primarily Uses
RMMZ
not tried it, but logically, this should work...

  #--------------------------------------------------------------------------  # * Random Selection of Target with Aggro State Check  #--------------------------------------------------------------------------  def random_target            tgr_rand = rand * tgr_sum    battle_members.each do |member|      next unless member      next unless member.alive?      tgr_rand -= member.tgr      return member if tgr_rand < 0.0    end    if tgr_rand == 0.0      #Probably might be cause of this, idunno how the calculations work      if self.is_a?(Game_Enemy) #Check if enemy        # Check if enemy has aggro state        return battle_members[0] if state?(116) && battle_members[0].alive?        return battle_members[1] if state?(117) && battle_members[1].alive?        return battle_members[2] if state?(118) && battle_members[2].alive?        return battle_members[3] if state?(119) && battle_members[3].alive?      end    end    return battle_members[0]  end edit :

Basically you are wanting it so that if enemy has state [x] then it will attack actor [x] if they are alive?>

What if they arent alive? just attack anyone ?
 
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
member.id is an id - a number.


$game_actors[x] is a Game_Actor.


You just want to compare member.id to the id of the actor, not to the actor itself.


Dekita, that's not the same logic (not to say the initial logic was correct).


I get the impression that for each state, he only wants it to target a particular actor. What you have is for each state, he gets battler 1, battler 2, etc, regardless of what the actor id is.


Maybe a bit more detail on WHAT you're trying to accomplish (why the different checks for the states, and why target specific actors - who may or may not be in the battle lineup at all - for each of those states?) will be helpful too, because you may just be going about it the wrong way.


But what I said above is the #1 thing to try - you're comparing a number with an object, and they're never going to be equal.
 
Last edited by a moderator:

kerbonklin

Hiatus King
Veteran
Joined
Jan 6, 2013
Messages
1,726
Reaction score
275
First Language
English
Primarily Uses
RMMV
@Dekita, nevermind it didn't work

@Shaz, I see what you mean, so my checks were most likely wrong then and it needs correcting. You were correct in your impression. What I am trying to accomplish is for the enemy to target specific actors based on a state they have. When (for example) Ralph attacks an enemy, Ralph inflicts State 116 onto it. Then when the enemy attacks through random_target, that enemy will target Ralph because it has that state. However the initial TRG check will take priority, which is why it comes first, THEN the state check, and then if there are no states to work with then it will target anyone randomly like normal.

I have my states set to replace the other aggro states through other means, so an enemy will never have two of the states.

Think of this as a non-universal form of TGR.
 
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
Gotcha. I think, then, that your biggest issue is that you're comparing a number with a Game_Actor, and they'll never be equal.

Instead of putting == $game_actors[id], just use the actor id itself (I said that in the first couple of lines of my post, but your reply focussed on the other part of what I said, so I just want to make sure you did get that bit).

So the fixes, and a bit of reduction, can be done like this:

# tgr stuff hereif tgr_rand == 0 and !self.actor? return $game_actors[1] if self.state?(116) && alive_members.include?($game_actors[1]) return $game_actors[2] if self.state?(117) && alive_members.include?($game_actors[2]) return $game_actors[3] if self.state?(118) && alive_members.include?($game_actors[3]) return $game_actors[4] if self.state?(119) && alive_members.include?($game_actors[4])endalive_members[0]It can be reduced even further by using an array for the states, and looping through the array by index.In fact, if you put that method into Game_Troop instead of adjusting Game_Unit, you wouldn't even need the self.actor check, because the modified version would only be run for enemies.
 
Last edited by a moderator:

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,513
Reaction score
3,203
First Language
Binary
Primarily Uses
RMMZ
could have been due to checking if tgr_rate was < 0 as realistically, this shouldnt matter considering you are checking if a state is inflicted, which is what should determine the target.

Try this...

  #-----------------------------------------------------------------------------  #  #-----------------------------------------------------------------------------  def random_target            tgr_rand = rand * tgr_sum    alive_members.each do |member|      tgr_rand -= member.tgr      return member if tgr_rand < 0.0    end    if self.is_a?(Game_Enemy)      alive_members.each do |member|        return member if member == $game_actors[1] && state?(116)        return member if member == $game_actors[2] && state?(117)        return member if member == $game_actors[3] && state?(118)        return member if member == $game_actors[4] && state?(119)      end    end    return alive_members[0]  endEdit:

Shaz got there first ^_^
 
Last edited by a moderator:

Solistra

Veteran
Veteran
Joined
Aug 15, 2012
Messages
593
Reaction score
247
Primarily Uses
So the fixes, and a bit of reduction, can be done like this:

Code:
# tgr stuff hereif tgr_rand == 0 and !self.actor?  return $game_actors[1] if self.state?(116) && alive_members.include?($game_actors[1])  return $game_actors[2] if self.state?(117) && alive_members.include?($game_actors[2])  return $game_actors[3] if self.state?(118) && alive_members.include?($game_actors[3])  return $game_actors[4] if self.state?(119) && alive_members.include?($game_actors[4])endalive_members[0]
Code:
if tgr_rand.zero? && !self.actor?  (1..4).each do |i|    return $game_actors[i] if self.state?(115 + i) && alive_members.include?($game_actors[i])  endendalive_members.first
Just did this for fun. It should work perfectly, though it's untested (I don't have my Windows VM up at the moment). Basically just serves as an example of a ridiculous amount of reduction, because... it's educational?
 

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,513
Reaction score
3,203
First Language
Binary
Primarily Uses
RMMZ
if tgr_rand.zero? && !self.actor? (1..4).each do |i| return $game_actors if self.state?(115 + i) && alive_members.include?($game_actors) endendalive_members.first

I never knew about the .zero? method. I assume it only returns true if value is absolute 0 rather than a float - like 0.01 ?

also, why do you both use self.state?(ID) when state?(ID) does the exact same?

is there a particular reason for using the self. ?
 

Solistra

Veteran
Veteran
Joined
Aug 15, 2012
Messages
593
Reaction score
247
Primarily Uses
also, why do you both use self.state?(ID) when state?(ID) does the exact same?


is there a particular reason for using the self. ?
I just butchered what Shaz wrote, since I don't have Ace open at the moment and didn't feel like going to the trouble of booting up a virtual machine to test a few lines of code. I very rarely work with much of anything related to RGSS3 itself these days, and I never enjoyed working with much of anything related to the battle system to begin with.


In short, no, there isn't a particular reason beyond my own personal laziness.
 

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,513
Reaction score
3,203
First Language
Binary
Primarily Uses
RMMZ
lol yea I get that... its much faster to copy, paste and mod than open a program and start from scratch...

could also reduce it a little more...

Code:
if tgr_rand.zero? && enemy?  (1..4).each {|i| a=$game_actors[i]; return a if state?(115+i) && alive_members.include?(a) }endalive_members.first
 

kerbonklin

Hiatus King
Veteran
Joined
Jan 6, 2013
Messages
1,726
Reaction score
275
First Language
English
Primarily Uses
RMMV
Okay so i've tried each suggestion but to no avail. They still persist to not stay targeting the proper actor.

However I realized that when I took out the beginning TRG check, there were apparently errors with using things like "state?" and "actor?" that caused crashes. So something in the TRG part must be coming true / working, otherwise it would have crashed a long time ago.

For example this comes up when using Shaz's attempt. (without the beginning TGR check) (when used under Game_Unit)



Also if I use Dekita's attempt, and remove the TGR part AND the alive_members[0] part, then even with the states they don't perform their attack. (Even though they have the states)  Which means those checks are not working.
 
Last edited by a moderator:

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,513
Reaction score
3,203
First Language
Binary
Primarily Uses
RMMZ
lol for some reason I assumed your code was within the Game_Battler class :/

Having it within Game_Troop drastically increases complexity due to the fact that nothing you are checking for exists within that class..

for example, no enemies or actors, which means no states to check, which means it wont work even if it didnt throw an error.

Edit:

well thats not really true, it does hold an array of either enemies or actors, depending on which instance of Game_Unit is being checked (Game_Troop or Game_Party)
 
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
Oh - you're doing checks based on self being a battler, but self is actually a game unit. So a game unit doesn't have the actor? or the state? method.


I was working on the assumption that you were putting the code into the correct class and that you knew what methods were available (and I assumed, because I haven't done much in this area, that self referred to user). By the time you get into the random_target, you only know what team is the enemy and what team are friends - you don't know who is taking the action anymore.


I would pull the logic out and maybe look at Game_Action's decide_random_target method instead. The subject variable would contain the actor/enemy executing the action. Put in another check there before the else, saying if !subject.actor? && [116,117,118,119].any? {|state| subject.state?(state) } then call your method (which will need to include the TGR checks), and then fall through to the default else.
 

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

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
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'??

Forum statistics

Threads
105,862
Messages
1,017,047
Members
137,569
Latest member
Shtelsky
Top