Powered by Invision Power Board

 
    Reply to this topicStart new topicStart Poll

> GM7: Attack Priority Code, SOLVED
Japan
Soiyeruda
Posted: Oct 7 2009, 04:11 PM
Quote Post


Because retarded looking women is fun. :S
[*][*][*][*][*]
[*][*][*]

Group Icon
Group: Members
Posts: 3589
Member No.: 5004
Joined: 6-March 08

Status: (0d) [--]


So yeah, having issues with this code. Maybe one of you can help me out. :S

I'm attempting to create an AI code, which basically picks a target, based on priorities. The priorities are:

1. If the target is killable with given statistics, and highest threat
2. If the target is damageable with given statistics, and highest threat
3. If the target has the highest threat level. (for if no targets are damageable or killable)

With 1. being first priority and 3. being lowest priority.

I've messed with the given code, and so far, I've only been able to get it to work on the target with the earlier id, which I assume is because with you use the with statement, it goes through all objects with the given name, in order by id. Otherwise, the priorities would mostly be based off threat level, and would appear random.

If anyone can reedit the code to make it work for all instances of the same object (which basically means the priorities need to work correctly), I'd greatly appreciate it.

Variables:
global.units_turn - Enemy's id
tar_att - Target's id
threat_number - gives your units a random threat value.
tar_att_num - The Target's threat value.
HP, ATK, DEF - sorta self explanatory (just the stats of each unit)

CODE
if global.units_turn=id and tar_att=-1
{

with(objUnit_Ally) {threat_number=random(1)}
with(objUnit_Ally)
{
//Priority 3: Highest Threat
if threat_number>global.units_turn.tar_att_num
{global.units_turn.tar_att_num=threat_number; global.units_turn.tar_att=id;}
//Priority 2: Damageable and Highest Threat
if (global.units_turn.ATK-DEF)>0 and threat_number>global.units_turn.tar_att_num
{global.units_turn.tar_att_num=threat_number; global.units_turn.tar_att=id;}
//Priority 1: Killable
if (global.units_turn.ATK-DEF)>0 //checks if damage is possible/isn't a negative
{
if HP-(global.units_turn.ATK-DEF)<=0 and threat_number>global.units_turn.tar_att_num
{global.units_turn.tar_att_num=threat_number; global.units_turn.tar_att=id;}
}

}

}


This post has been edited by Soiyeruda on Oct 8 2009, 02:35 AM
PMEmail Poster
Top
United States
Littlink
Posted: Oct 7 2009, 04:57 PM
Quote Post


hip 2b square
[*][*][*][*][*]
[*][*]

Group Icon
Group: Members
Posts: 5146
Member No.: 2010
Joined: 11-April 06

Status: (0d) [--]


you'd need a way to check objects within your range with the correct object_name

off the top of my head maybe like

check closest object
does this object have the right name?
if not then go back to step one with the next closest
if so then gather threat information


--------------------
[████████░░] 80%

user posted image
PMUsers WebsiteMSN
Top
Japan
Soiyeruda
Posted: Oct 7 2009, 05:01 PM
Quote Post


Because retarded looking women is fun. :S
[*][*][*][*][*]
[*][*][*]

Group Icon
Group: Members
Posts: 3589
Member No.: 5004
Joined: 6-March 08

Status: (0d) [--]


QUOTE (Littlink @ Oct 8 2009, 06:57 AM)
you'd need a way to check objects within your range with the correct object_name

off the top of my head maybe like

check closest object
does this object have the right name?
if not then go back to step one with the next closest
if so then gather threat information

It's not really a distance thing.

The code "works". It's just when it gets to the priorities, it screws up, and is heavily based on threat level.

From GMC, I apparently need lists. >.>
PMEmail Poster
Top
United States
Littlink
Posted: Oct 7 2009, 07:25 PM
Quote Post


hip 2b square
[*][*][*][*][*]
[*][*]

Group Icon
Group: Members
Posts: 5146
Member No.: 2010
Joined: 11-April 06

Status: (0d) [--]


QUOTE (Soiyeruda @ Oct 7 2009, 05:01 PM)
It's not really a distance thing.

The code "works". It's just when it gets to the priorities, it screws up, and is heavily based on threat level.

From GMC, I apparently need lists. >.>

ah

then I guess you'd create a variable (threat dohoho) and uh

add one for every threat checked (ie if killable add 1 to threat)

and then if threat is too high

do stuff

bah I'm terrible at this


--------------------
[████████░░] 80%

user posted image
PMUsers WebsiteMSN
Top
Japan
Soiyeruda
Posted: Oct 8 2009, 01:24 AM
Quote Post


Because retarded looking women is fun. :S
[*][*][*][*][*]
[*][*][*]

Group Icon
Group: Members
Posts: 3589
Member No.: 5004
Joined: 6-March 08

Status: (0d) [--]


It's okay. Actually, I sorta figured out that I need to use lists and queues. Too bad I suck with those. . . .lol.

EDIT: After toying around, I eventually got it to work. Required a list, and two queues. :S

This post has been edited by Soiyeruda on Oct 8 2009, 02:34 AM
PMEmail Poster
Top
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

  Topic Options Topic Options Reply to this topicStart new topicStart Poll

 




[ Script Execution time: 0.0426 ]   [ 14 queries used ]   [ GZIP Enabled ]   [ Server Load: 1.41 ]