Threat-based targeting

dodger451

Villager
Member
Joined
Oct 28, 2015
Messages
5
Reaction score
0
Primarily Uses
i just played a bit with rpgmaker and ruby first time

and made this script to make enemies attack party members based on received damage.

Intro: This is a script to improve the AI of Enemies for RPG Maker VX Ace. During a battle, the script lets enemies choose targets based on the accumulated "threat" they feel for each opponent (multiplied by his tgr). This script will maintain a threat table for each enemy, threat rises when an party member hurts an enemy or when he heals another member.

https://github.com/dodger451/rpgmaker/blob/master/Thread_Sytem.rb

i hope you like it!
 
Last edited by a moderator:

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,254
Reaction score
1,254
First Language
Spanish
Primarily Uses
RMVXA
I was just looking for something similar to this!

can this be adapted so that a skill used by an ally would sky-rocket that enemy's target priority?

as in, I want the player to attract an enemy's attention on purpose, in addition to the players causing enemies to target them based on their threat.

for example:

actor A targets enemy A... enemy A responds by threat to actor A.

actor B uses Aggro on enemy A... if Aggro > actual threat, enemy targets actor B.

(I suck at Ruby, but I know the basics behind programming)
 

dodger451

Villager
Member
Joined
Oct 28, 2015
Messages
5
Reaction score
0
Primarily Uses
IIRC there was an attribute TGR that you work with to archive something like that (e.g have a skill increase an actors tgr for a few rounds).

That would be the easiest solution to let actor get the aggro via a skill, but that would make all enemies attack him more often.

TGR and the damage-based threat are being combined when calculating who is going to be attacked.

Alternatively you will need to hook a script that calls $game_threat.add_threat(enemy_defender, actor_attacker, additional_threat)

when you want increase the threat, with enemy_defender = enemy A and actor_attacker = actor B and additional_threat being the threat you want to add

(1 point equals threat generated 1 hp damage being dealt).
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,254
Reaction score
1,254
First Language
Spanish
Primarily Uses
RMVXA
I had a skill increasing an actor's TGR manually already, but I wanted the battler's attention to be directed towards the actor, not the actor making itself more targettable.
the point was to get to force the enemy's action towards the actor from the very beginning, but I had to settle with increasing the actor's exposure when it became too messy to handle it with skills and events.
if this works, then I might be able to adapt it to cause negative aggro, and use a sort of "peace" skill.
 
from the little testing I could do, it works just as it is... I used that manual aggro in combat, and the enemy kept switching back to the character that was dealing him 2k+ damage.
 
Last edited by a moderator:

Rinobi

Veteran
Veteran
Joined
Mar 24, 2014
Messages
579
Reaction score
219
First Language
English
Primarily Uses
RMVXA


Load: Multiple Skill Types v1.00 by Kread-EX
Read: Multiple Skill Types Notetags
"Slime LV 11 finds thread-based target"
"Slime LV 11 feels threaten by Natalie (tgr=1.0, threat=0): 1.0"
"Slime LV 11 feels threaten by Eric (tgr=1.0, threat=0): 1.0"
"choose Natalie(1.0)"
"Slime LV 11 finds thread-based target"
"Slime LV 11 feels threaten by Natalie (tgr=1.0, threat=0): 1.0"
"Slime LV 11 feels threaten by Eric (tgr=1.0, threat=0): 1.0"
"choose Natalie(1.0)"
"Natalie causes 808 damage on Slime LV 11, Slime LV 11 feels more threatened (+809)"
"Slime LV 11 finds thread-based target"
"Slime LV 11 feels threaten by Natalie (tgr=1.0, threat=809): 809.0"
"Slime LV 11 feels threaten by Eric (tgr=1.0, threat=0): 1.0"
" choose Natalie(809.0)"
"Natalie causes 189 damage on Slime LV 11, Slime LV 11 feels more threatened (+190)"
"Slime LV 11 finds thread-based target"
"Slime LV 11 feels threaten by Natalie (tgr=1.0, threat=999): 999.0"
"Slime LV 11 feels threaten by Eric (tgr=1.0, threat=0): 1.0"
" choose Natalie(999.0)"
"Slime LV 11 finds thread-based target"
"Slime LV 11 feels threaten by Natalie (tgr=1.0, threat=999): 999.0"
"Slime LV 11 feels threaten by Eric (tgr=1.0, threat=0): 1.0"
" choose Natalie(999.0)"
"Slime LV 11 finds thread-based target"
"Slime LV 11 feels threaten by Natalie (tgr=1.0, threat=999): 999.0"
"Slime LV 11 feels threaten by Eric (tgr=1.0, threat=0): 1.0"
" choose Natalie(999.0)"
"Slime LV 11 finds thread-based target"
"Slime LV 11 feels threaten by Natalie (tgr=1.0, threat=999): 999.0"
"Slime LV 11 feels threaten by Eric (tgr=1.0, threat=0): 1.0"
" choose Natalie(999.0)"
"Slime LV 11 finds thread-based target"
"Slime LV 11 feels threaten by Natalie (tgr=1.0, threat=999): 999.0"
"Slime LV 11 feels threaten by Eric (tgr=1.0, threat=0): 1.0"
" choose Natalie(999.0)"
"Slime LV 11 finds thread-based target"
"Slime LV 11 feels threaten by Natalie (tgr=1.0, threat=999): 999.0"
"Slime LV 11 feels threaten by Eric (tgr=1.0, threat=0): 1.0"
" choose Natalie(999.0)"
"Natalie causes 603 damage on Slime LV 11, Slime LV 11 feels more threatened (+604)"
"Slime LV 11 finds thread-based target"
"Slime LV 11 feels threaten by Natalie (tgr=2.0, threat=1603): 3206.0"
"Slime LV 11 feels threaten by Eric (tgr=1.0, threat=0): 1.0"
"choose Natalie(3206.0)"
"Eric heals -256 hp on Natalie, all his enemies feel more threatened (+257 each)"
" -> Slime LV 11 feels 257 more threatended by  Eric"
"Slime LV 11 finds thread-based target"
"Slime LV 11 feels threaten by Natalie (tgr=2.0, threat=1603): 3206.0"
"Slime LV 11 feels threaten by Eric (tgr=1.0, threat=257): 257.0"
" choose Natalie(3206.0)"
"Slime LV 11 finds thread-based target"
"Slime LV 11 feels threaten by Natalie (tgr=2.0, threat=1603): 3206.0"
"Slime LV 11 feels threaten by Eric (tgr=1.0, threat=257): 257.0"
" choose Natalie(3206.0)"
"Slime LV 11 finds thread-based target"
"Slime LV 11 feels threaten by Natalie (tgr=2.0, threat=1603): 3206.0"
"Slime LV 11 feels threaten by Eric (tgr=1.0, threat=257): 257.0"
" choose Natalie(3206.0)"
"Slime LV 11 finds thread-based target"
"Slime LV 11 feels threaten by Natalie (tgr=2.0, threat=1603): 3206.0"
"Slime LV 11 feels threaten by Eric (tgr=1.0, threat=257): 257.0"
" choose Natalie(3206.0)"
"Natalie causes 346 damage on Slime LV 11, Slime LV 11 feels more threatened (+347)"
"Slime LV 11 finds thread-based target"
"Slime LV 11 feels threaten by Natalie (tgr=4.0, threat=1950): 7800.0"
"Slime LV 11 feels threaten by Eric (tgr=1.0, threat=257): 257.0"
" choose Natalie(7800.0)"
"Slime LV 11 finds thread-based target"
"Slime LV 11 feels threaten by Natalie (tgr=4.0, threat=1950): 7800.0"
"Slime LV 11 feels threaten by Eric (tgr=1.0, threat=257): 257.0"
" choose Natalie(7800.0)"
"Slime LV 11 finds thread-based target"
"Slime LV 11 feels threaten by Natalie (tgr=4.0, threat=1950): 7800.0"
"Slime LV 11 feels threaten by Eric (tgr=1.0, threat=257): 257.0"
" choose Natalie(7800.0)"
"Slime LV 11 finds thread-based target"
"Slime LV 11 feels threaten by Natalie (tgr=4.0, threat=1950): 7800.0"
"Slime LV 11 feels threaten by Eric (tgr=1.0, threat=257): 257.0"
" choose Natalie(7800.0)"
"Slime LV 11 finds thread-based target"
"Slime LV 11 feels threaten by Natalie (tgr=4.0, threat=1950): 7800.0"
"Slime LV 11 feels threaten by Eric (tgr=1.0, threat=257): 257.0"
" choose Natalie(7800.0)"
"Slime LV 11 finds thread-based target"
"Slime LV 11 feels threaten by Natalie (tgr=4.0, threat=1950): 7800.0"
"Slime LV 11 feels threaten by Eric (tgr=1.0, threat=257): 257.0"
" choose Natalie(7800.0)"
"Slime LV 11 finds thread-based target"
"Slime LV 11 feels threaten by Natalie (tgr=1.0, threat=1950): 1950.0"
"Slime LV 11 feels threaten by Eric (tgr=1.0, threat=257): 257.0"
" choose Eric(257.0)"
"Slime LV 11 finds thread-based target"
"Slime LV 11 feels threaten by Natalie (tgr=1.0, threat=1950): 1950.0"
"Slime LV 11 feels threaten by Eric (tgr=1.0, threat=257): 257.0"
" choose Natalie(1950.0)"
"Natalie causes 216 damage on Slime LV 11, Slime LV 11 feels more threatened (+217)"


Seems to work pretty well. Enemies will most likely attack the actor with the highest threat, but it isn't absolute. Skills that add "TGR" only increase the multiplier for threat, so I'll need a script call which adds a pretty big number... I'd prefer for this number to be based on the parameters of the user of the threat skill; I'm pretty sure I can work that part out on my own.

What are your terms of use?
Also a few user-friendly ideas:

State/Debuff-based threat functionality: Maybe applying a state/debuff multiplies threat by an additional value. So that enemy's feel threatened by negative status infliction and debuffs.
Add Threat Notetags: So that states can temporarily add threat values along side, or instead of, multiplying by TGR.

Edit: What script call would you use to manually add threat to the "target" of a skill? Edit2: Nevermind, got it.
 
Last edited by a moderator:

dodger451

Villager
Member
Joined
Oct 28, 2015
Messages
5
Reaction score
0
Primarily Uses
Terms of use:

It's free for use with both free and commercial RPG Maker games. I don’t demand royalties or special liberties if you choose to use the original content in your commercial games (but a free copy of your game would be nice~). Editing this script is perfectly okay as long as you still provide the proper credit.

Regarding you're ideas, I was already thinking about those, but never found the time. I'll merge pull requests if you feel like contributing :)
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,713
First Language
English
Primarily Uses
RMVXA
I think you might need to rename your topic.  Should this not be Threat-based targeting?  You have Thread-based.  To edit your title, click edit on your first post, select Use Full Editor, and that will give you all the functionality.

I have also asked for this thread to be moved.  Scripts should be posted in the Script section of the forum, not here in Support.
 
Last edited by a moderator:

dodger451

Villager
Member
Joined
Oct 28, 2015
Messages
5
Reaction score
0
Primarily Uses
Thx, your are  completely right! I renamed it.

I just wanted to put this somewhere before i forgot about it again  :p
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,108
Reaction score
13,713
First Language
English
Primarily Uses
RMMV
I've moved this thread to RGSS3 (VX Ace) Scripts. Please be sure to post your threads in the correct forum next time. Thank you.
 

BardAaron

Veteran
Veteran
Joined
Apr 30, 2015
Messages
46
Reaction score
15
First Language
English
Primarily Uses
This is EXACTLY what I was looking for.
 

Rinobi

Veteran
Veteran
Joined
Mar 24, 2014
Messages
579
Reaction score
219
First Language
English
Primarily Uses
RMVXA
Some things I discovered poking around... may be useful.

Removing/Setting Threat:

$threat_tables[b.name][a.name] = value # set value on user and target$game_troop.members.each {|bb| $threat_tables[bb.name][a.name] = value} # set value on user and all enemies$game_party.members.each {|aa| $threat_tables[b.name][aa.name] = value} # set value all party members and targetAdd/Subtracting Threat:

Code:
$game_threat.add_threat(b, a, value) # set value on user and target$game_troop.members.each {|bb| $game_threat.add_threat(bb, a, value)} # set value on user and all enemies$game_party.members.each {|aa| $game_threat.add_threat(b, aa, value)} # set value on all party members and target
 
Last edited by a moderator:

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,254
Reaction score
1,254
First Language
Spanish
Primarily Uses
RMVXA
bug in update_threat_on_heal() when healing outside battle.

I just patched it with a simple check, but you might want to check it from the top.

Code:
def update_threat_on_heal(result, actor_healer, actor_healed)  return if $game_party.in_battle # <----------- this  alive_count = actor_healed.opponents_unit.alive_members.size;  return self unless alive_count>0  additional_threat = ((1 + (-result.hp_damage)).to_f/alive_count.to_f).to_i  dbg actor_healer.name + " heals " + result.hp_damage.to_s + " hp on " + actor_healed.name+", all his enemies feel more threatened (+"+additional_threat.to_s+" each)"  actor_healed.opponents_unit.alive_members.each do |enemy|    dbg " -> " + enemy.name + " feels " + additional_threat.to_s + " more threatended by " + actor_healer.name    add_threat(enemy, actor_healer, additional_threat)  end  return selfend
 
Last edited by a moderator:

dodger451

Villager
Member
Joined
Oct 28, 2015
Messages
5
Reaction score
0
Primarily Uses
Fixed.

Thanks for reporting, gstv87

bug in update_threat_on_heal() when healing outside battle.

I just patched it with a simple check, but you might want to check it from the top.

Code:
def update_threat_on_heal(result, actor_healer, actor_healed)  return if $game_party.in_battle # <----------- this  alive_count = actor_healed.opponents_unit.alive_members.size;  return self unless alive_count>0  additional_threat = ((1 + (-result.hp_damage)).to_f/alive_count.to_f).to_i  dbg actor_healer.name + " heals " + result.hp_damage.to_s + " hp on " + actor_healed.name+", all his enemies feel more threatened (+"+additional_threat.to_s+" each)"  actor_healed.opponents_unit.alive_members.each do |enemy|    dbg " -> " + enemy.name + " feels " + additional_threat.to_s + " more threatended by " + actor_healer.name    add_threat(enemy, actor_healer, additional_threat)  end  return selfend
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,254
Reaction score
1,254
First Language
Spanish
Primarily Uses
RMVXA
help me out a bit here, I have a bit of a tangle going on..

if I add this to the damage value formula:

$game_threat.add_threat(b, a, a.atk+1831)the threat is updated correctly, and the skill connects dealing atk+1831 damage.

however, adding the same line in a script call through a common event from that same skill (damage formula disabled), throws an error.

I want the skill to do 0 damage, AND update the threat.

but it doesn't work when I use a script event.

I just fixed it momentarily through the damage formula by using

$game_threat.add_threat(b, a, a.atk+1831) > 0 ? 0 : 0but it should be better done with an event, so that I can call it from another skill if need be.
 
Last edited by a moderator:

Rinobi

Veteran
Veteran
Joined
Mar 24, 2014
Messages
579
Reaction score
219
First Language
English
Primarily Uses
RMVXA
Why not just use:

$game_threat.add_threat(b, a, a.atk + 1831) ; 0Just add the script call before any damage formula followed by a semicolon, you can replace '0' with any damage formula you want. It's already pretty straight forward to use this within any number of skills.
 
Last edited by a moderator:

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,254
Reaction score
1,254
First Language
Spanish
Primarily Uses
RMVXA
but that would be like saying "damage whatever amount this function returns".... I don't want that, I want it to be "do no damage, and also call up this function"

it should be a separate script on it's own, not plugged into the damage formula.

one way I can think about it was doing through a common event, so I can use another skill that instead of affecting one target would affect many targets, but cause the same end result... so it would be two separate skills, two validations, and one final effect: increase aggro of every target by the same amount.

I was thinking about replacing some functions in Game_Battler or Game_Action, with the checks and corrections I need, but I'll hold that as a last resort.

EDIT: I just realized I answered myself....

it should be a separate script on it's own, not plugged into the damage formula.
adding the same line in a script call through a common event from that same skill (damage formula disabled), throws an error.
of course it's going to throw an error, if A and B are part of the damage function, which I'm not passing down to the common event. D'OH!
 
Last edited by a moderator:

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

Latest Threads

Latest Profile Posts

Day 9 of giveaways! 8 prizes today :D
He mad, but he cute :kaopride:

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.

Forum statistics

Threads
106,037
Messages
1,018,464
Members
137,821
Latest member
Capterson
Top