how do i select a random actor (from 1-5) if not all numbers from 1-5 are selectable?
EwokPD
Member, PRO Posts: 35
Hello,
I am trying to write code at 3.48am... which could be the reason i cant work this out so wondered if anyone can offer any pointers
I have up to 5 targets on screen with self attributes of 1-5 - however if say number 3 and 4 were destroyed this would only leave targets 1,2 and 5 available (LIVE)
I have an enemy actor that i want to randomly target one of the LIVE targets - so have been trying to simply generate a random number between 1-5, then compare the result to see if that target is LIVE - and if not loop back and generate a new target but cannot get it to work.
I have game booleon attributes for the 5 targets that i flag to TRUE when its LIVE, and FALSE when its destroyed.
So code goes along these lines
If node in an enemy node - run AI
On running AI
Change ATT - self.target to random(1,5)
if ATT self.target = 1
and ATT Target01 = true
if ATT self.target = 2
and ATT Target02 = true.....etc etc
change attribute shoot to true (enemy will then shoot target is any of the above statements is true)
then i have....
if ATT self.target = 1
and ATT Target01 = false (the target is no longer in game)(i have this for all 5 targets)
Change ATT - self.target to random(1,5) (the idea here is a new number is generated when the original target is not LIVE - but then i need to trigger the above to run again
The idea being the ENEMY actor would loop through all possible target till it found a valid target and do what it needs to do.
Needless to say i cant get this to work
Is this a viable system to work, or is there an easier way to do this - i am not after someone writing the code here - just high end concept ideas would be great
Thanks
I am trying to write code at 3.48am... which could be the reason i cant work this out so wondered if anyone can offer any pointers
I have up to 5 targets on screen with self attributes of 1-5 - however if say number 3 and 4 were destroyed this would only leave targets 1,2 and 5 available (LIVE)
I have an enemy actor that i want to randomly target one of the LIVE targets - so have been trying to simply generate a random number between 1-5, then compare the result to see if that target is LIVE - and if not loop back and generate a new target but cannot get it to work.
I have game booleon attributes for the 5 targets that i flag to TRUE when its LIVE, and FALSE when its destroyed.
So code goes along these lines
If node in an enemy node - run AI
On running AI
Change ATT - self.target to random(1,5)
if ATT self.target = 1
and ATT Target01 = true
if ATT self.target = 2
and ATT Target02 = true.....etc etc
change attribute shoot to true (enemy will then shoot target is any of the above statements is true)
then i have....
if ATT self.target = 1
and ATT Target01 = false (the target is no longer in game)(i have this for all 5 targets)
Change ATT - self.target to random(1,5) (the idea here is a new number is generated when the original target is not LIVE - but then i need to trigger the above to run again
The idea being the ENEMY actor would loop through all possible target till it found a valid target and do what it needs to do.
Needless to say i cant get this to work
Is this a viable system to work, or is there an easier way to do this - i am not after someone writing the code here - just high end concept ideas would be great
Thanks