datsalmon
Eggom ( a fresh bubu out of the lake, still wet from swimming should eventually dry off
Posts: 40
|
Post by datsalmon on Mar 12, 2014 12:39:52 GMT
say i have a bunch of abjects flying around and shootincg eachother. how would i make them pick their target based on stats? for example they have like, attack, defense and speed or something. and i want one of the AI to go for the object with the lowest defense.
|
|
|
Post by orange08 on Mar 12, 2014 17:40:09 GMT
assuming you're using GM, i would use 3 global variables global.lowest_defense_found = 99999 //make this number be higher than any ship's defense variable global.lowest_defense_ship_id = -1 //this will be used to get the id of the ship with the lowest defense global.id_dont_use = id //this will be used to make sure we dont pick our own ship as the target //this goes on a loop through all the obj_ships that currently exist in the room with obj_ship { if id !=global.id_dont_use //if this is not our own ship { if my_defense < global.lowest_defense_found //if this ship's defense variable is smaller than the last one we found { global.lowest_defense_found = my_defense global.lowest_defense_ship_id = id //set the global id variable to this ship, because we have the smallest defense so far } } } my_target = global.lowest_defense_ship_id here the code is in pastebin: pastebin.com/nfDTmKnX
|
|
datsalmon
Eggom ( a fresh bubu out of the lake, still wet from swimming should eventually dry off
Posts: 40
|
Post by datsalmon on Mar 12, 2014 18:00:26 GMT
super thanks, i'll give that a go.
|
|
datsalmon
Eggom ( a fresh bubu out of the lake, still wet from swimming should eventually dry off
Posts: 40
|
Post by datsalmon on Mar 13, 2014 17:03:38 GMT
it works really well, thanks.
|
|