[RESOLVED] Script Request: Threat/Aggro System [XP]

Started by KCMike20, January 04, 2009, 06:33:00 am

Previous topic - Next topic

Fantasist

I tend to do that, sorry ^_^'
*sigh* I'll have to complete this system sooner or later: I planned on using this in my game long ago since I saw it in the RTAB demo. I'll do it, you can be sure of that :up:
Do you like ambient/electronic music? Then you should promote a talented artist! Help out here. (I'm serious. Just listen to his work at least!)


The best of freeware reviews: Gizmo's Freeware Reviews





Jackolas

can i bumb this 1 becouse it was 1 of the more interesting requests

Holyrapid

Im bumpng it too, because this would be nice with BABS... I know it has some sort of threat thing in it allready, but from my knowledge, this would improve it.

Fantasist

I don't know what you said about BABS, but this sure is a great system. I wish I could do it soon.
Can someone help me on this? I don't know how to choose randomly b/w actors with same threat. Like say the threats of the party members are 6, 6, 4, 2. The target should be either the 1st or second actor. How do I get that?
Also, if anyone can do this completely, I'll gladly hand over the responsibility.
Do you like ambient/electronic music? Then you should promote a talented artist! Help out here. (I'm serious. Just listen to his work at least!)


The best of freeware reviews: Gizmo's Freeware Reviews




Starrodkirby86

I'm no scripting wizard, the best I can do is script you a Pikachu, but have you tried something like...

When in the case that there's two, three, or four actors with equal threat amounts, perhaps you can generate a random variable of 1, 2, 3, and 4. Whichever variable it lands on would be the monster would attack...Of course it might turn out to be very unoptimized or so (4! = 24 [If you see no relation to this thing, then ignore this]), but bah.

What's osu!? It's a rhythm game. Thought I should have a signature with a working rank. ;P It's now clickable!
Still Aqua's biggest fan (Or am I?).




winkio

July 06, 2009, 04:06:52 pm #26 Last Edit: July 06, 2009, 04:08:12 pm by winkio
make an array of the targets.  Then choose a random number from the indexes

Example:

possible_targets = []
possible_targets.push(actor1)
possible_targets.push(actor3)
possible_targets.push(actor4)
the_target = possible_targets[rand(possible_targets.size)]

that's pseudocode, but its pretty close to actual code.

And if you want to give this away at some point, I have the time and could do it.

Fantasist

@Star: Doesn't really help, but thanks. (Script me a Pikachu.)

@winkio: Yes, but I need to separate the equal threat actors to choose randomly among them.

*sigh* I don't know if it's the phobia of not completing this for 6 months, but I'm kind of afraid even to start. screw it. I'll try this again from scratch.
Do you like ambient/electronic music? Then you should promote a talented artist! Help out here. (I'm serious. Just listen to his work at least!)


The best of freeware reviews: Gizmo's Freeware Reviews




Starrodkirby86

Quote from: Fantasist on July 06, 2009, 04:11:01 pm
@Star: Doesn't really help, but thanks. (Script me a Pikachu.)

Quote from: Starrodkirby86 on July 05, 2008, 11:03:25 am
Quote from: Fantasist on July 05, 2008, 10:58:30 am
lol! Then script me a pikachu!

Okay...um...
#Pikachu Code
#By Starrodkirby86
#Pika Pika! Insert this above main! You'll be happy!
#Instructions:
#
#Place this ABOVE Main. You'll be happy
begin
  print "Pikachu loves hentai."
end


What's osu!? It's a rhythm game. Thought I should have a signature with a working rank. ;P It's now clickable!
Still Aqua's biggest fan (Or am I?).




winkio

July 06, 2009, 04:19:43 pm #29 Last Edit: July 06, 2009, 04:24:36 pm by winkio
okay, ill write pretty much the whole thing out:

threat = []
alive_actors = []
$game_party.actors.each {|a|
 if (!a.is_dead)
   threat.push(a.get_threat)
   possible_targets.push(a)
 end}
possible_targets = []
(0...threat.size).each {|i|
 if threat[i] == threat.max
   possible_targets.push(alive_actors[i])
 end}
the_target = possible_targets[rand(possible_targets.size)]

Iterate through all the actors, add any that can be targeted to an array, and also add their threats to a different array.  Find the max of the threat array, and push the corresponding actor(s) into a new array.  Take a random element of that array for the target.
 

Blizzard

Use .sort with a block that specifies how the array should be sorted (as in: what the sorting criteria is). Just check out "CP#resort_weapons" in CP Beta.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Fantasist

July 06, 2009, 04:40:51 pm #31 Last Edit: July 06, 2009, 04:44:31 pm by Fantasist
That was the first thing I tried:
targets.sort! {|a, b| b.threat - a.threat}

It still doesn't solve the problem of deciding b/w 2 or more actors of same highest threat.

This is the solution I came up with just now:

  def random_target_actor(hp0 = false)
    # Get maximum threat
    max_threat = 0
    for actor in @actors
      next unless (!hp0 && actor.exist?) || (hp0 && actor.hp0?)
      max_threat = actor.threat if actor.threat > max_threat
    end
    # Collect targets with maximum threats
    targets = []
    for actor in @actors
      next unless (!hp0 && actor.exist?) || (hp0 && actor.hp0?)
      targets.push(actor) if actor.threat == max_threat
    end
    return fts_threat_choose_actor(hp0) if targets.size == 0
    return targets[rand(targets.size)]
  end


1st, I get the max threat. Then I collect actors with max threat. The array size will be 1 or more, but chosing a random element will work in either case.
Do you like ambient/electronic music? Then you should promote a talented artist! Help out here. (I'm serious. Just listen to his work at least!)


The best of freeware reviews: Gizmo's Freeware Reviews




winkio


Blizzard

Or

targets.sort! {|a, b| b.threat - a.threat}
targets = targets.find_all {|a| a.threat == targets[0].threat}
target = targets[rand(targets.size)]


:P
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

winkio

damn you blizz, and your extensive knowledge of coding!

(seriously, who knew about find_all?)

Fantasist

@Blizz: Where do you learn these subtle details?

m(_)m  m(_)m  m(_)m
Do you like ambient/electronic music? Then you should promote a talented artist! Help out here. (I'm serious. Just listen to his work at least!)


The best of freeware reviews: Gizmo's Freeware Reviews




Blizzard

July 06, 2009, 05:02:44 pm #36 Last Edit: July 06, 2009, 05:05:35 pm by Blizzard
Spoiler: ShowHide


@winkio: Careful, not "find_all?" but "find_all". I use "find_all" all the time along with "any?". I prefer "x.any? {|a| !a.condition}" to "x.all? {|a| a.condition}" because "any?" will abort the search if the first one was found while "all?" always has to check all.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

winkio

the ? was because I was asking a question...

Blizzard

Ok, no problem. It's just that I got an error a few times by using find_all? accidentally. xD
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

winkio