Arrays
Moderator: Moderators
Arrays
im making a custom ai script for one of my soldiers. i want him to only shoot at things that have a #bazookatarget of 1. so in mohradiant, i give a guy a key of #bazookatarget and value of 1. now all of these guys will have different targetnames, blah blah. the only way they are alike is their #bazookatarget is 1. im guessing i need arrays to define everything with #bazookatarget 1. in my script, how exactly would i get my soldier to recognize these enemies as targets? how do i set up the arrays for teh targets?
Hmm that all is very hard
The only way to 'get' an entity in the script is via its targetname, so the only way to make arrays is by using targetnames. Assuming you have two kinds of enemies in your map, one type targetnamed 'village_german', the other 'bocage_german'
, you could make the array like this:
Now you have a level.bazookatargets array 8)
The only way to 'get' an entity in the script is via its targetname, so the only way to make arrays is by using targetnames. Assuming you have two kinds of enemies in your map, one type targetnamed 'village_german', the other 'bocage_german'
Code: Select all
local.j = 0
for(local.i = 1; local.i <= $village_german.size; local.i++)
{
local.german = $village_german[local.i]
if(local.german.bazookatarget)
{
local.j++
level.bazookatargets[local.j] = local.german
}
}
for(local.i = 1; local.i <= $bocage_german.size; local.i++)
{
local.german = $bocage_german[local.i]
if(local.german.bazookatarget)
{
local.j++
level.bazookatargets[local.j] = local.german
}
}
hmm just a thought...
can you give the targets a 'wild letter'? for example, say you have 3 tanks, panzer1, panzer2, and panzer3. could you refer to either one of them in the script by typing panzer*
that would be really great. then i could use their individual names for specific scripted sequences im making.
can you give the targets a 'wild letter'? for example, say you have 3 tanks, panzer1, panzer2, and panzer3. could you refer to either one of them in the script by typing panzer*
i just had an idea! i dont know if this works though just thought it up...
lets say you got 3 tanks. all named "panzer". now the bazookaman knows to shoot them because their name is "panzer". now to use each one in individual scripted sequences, lets say i gave the first panzer, #bazookatarget 1, next #bazokatarget 2, and so on. now could i use a switch to identify which a specific one in the group? it would go something like this...
Note: never used switches before so plz inform me if i mess up format.
switch (panzer.bazookatarget)
1:
iprintln "Panzer 1"
2:
iprintln "2"
3:
iprintln "3"
would that work??? right now i think that would be the BEST way out of all the ways i posted up above.
lets say you got 3 tanks. all named "panzer". now the bazookaman knows to shoot them because their name is "panzer". now to use each one in individual scripted sequences, lets say i gave the first panzer, #bazookatarget 1, next #bazokatarget 2, and so on. now could i use a switch to identify which a specific one in the group? it would go something like this...
Note: never used switches before so plz inform me if i mess up format.
switch (panzer.bazookatarget)
1:
iprintln "Panzer 1"
2:
iprintln "2"
3:
iprintln "3"
would that work??? right now i think that would be the BEST way out of all the ways i posted up above.
Yeah something like that, although the syntaxis should be a little different.

Code: Select all
switch($panzer[1].bazookatarget)
{
case 1:
// my sweet code here
break
case 2:
// even more code here
break
default:
// last code here
}
Yeah [1] means the first panzer of the array, i.e. the first panzer spawned. This is not necessarily the panzer with #bazookatarget 1. You can't run the switch statement on all panzers at once, since they all have a different #bazookatarget value 
Case 1 equals #bazookatarget 1. I could also have written it as:
Default just means 'else', i.e. if the value of bazookatarget is not one of the above.
Case 1 equals #bazookatarget 1. I could also have written it as:
Code: Select all
switch($panzer[1].bazookatarget)
{
case 2:
// code for panzer 2 here
break
case 1:
// code for panzer 1 here
break
default:
// code for panzer 3 here
}
? ok i got the switch cases, now for the [1] thing... they are already placed in the map.. so wouldnt they all be called? and, if i used this switch in my script, i could call ANY panzer by the different cases?
and ANOHTer question, so that i understand cases. if my #bazookatarget was "bob", would i type code like this?
eh? eh?
[/code]
and ANOHTer question, so that i understand cases. if my #bazookatarget was "bob", would i type code like this?
Code: Select all
switch ($panzer[1].bazookatarget)
{
case bob:
iprintln "Bob target"
case default:
iprintln "error could not find."
}
end[/code]
how do i refer to the panzer?
lets say i got 3 panzers. only one has a #bazookatarget. (and its 1)
now look at the code...
ok, i identified the pazner with a bazookatarget, but how do i refer to that one in the cases? do i just type self? i want that one panzer to do something specific. how do i make only that one panzer do it? plz comment the code alot i dont know much of what ur saying wiht these arrays.
lets say i got 3 panzers. only one has a #bazookatarget. (and its 1)
now look at the code...
Code: Select all
switch ($panzer.bazookatarget)
case 1:
self drive here
break
default:
println "None"Here this might help
This little piece of code loops for as many times as there are $panzers ($panzer.size) and assigns the $panzers to level.panzer_1, level.panzer_2 and level.panzer_3.
Code: Select all
for(local.i = 1; local.i <= $panzer.size; local.i++)
{
local.panzer = $panzer[local.i]
switch(local.panzer.bazookatarget)
{
case 1:
level.panzer_1 = local.panzer
break
case 2:
level.panzer_2 = local.panzer
break
case 3:
level.panzer_3 = local.panzer
}
}
