|
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
|