Home   Help Search Login Register  

Author Topic: New AI coverfire script doesnt work ...  (Read 1282 times)

0 Members and 1 Guest are viewing this topic.

Offline paddy

  • Contributing Member
  • **
  • Llama whipping good
New AI coverfire script doesnt work ...
« on: 02 Sep 2005, 15:06:13 »
Early version of coverfire by Paddy

- To execute - To execute coverfire
[unit] exec "coverfire.sqs"

   N.B. remember to preprocess the random int.sqf file in init.sqs

- To execute revealtoall
[unit] exec "revealtoall.sqs"

--// coverfire.sqs is a script that makes units cover other units in the group while
they are moving.
Completely untested due to lack of time (and energy) was built for speeder and requires thorough testing HELP!!  Script must be activated for each group member.

REQUIRED ......
   1) A trigger named 'eastunits' covering whole map and activated by east repeatedly every 2 seconds
   2) A trigger named 'westunits' covering whole map and activated by west repeatedly every 2 seconds
   3) Preprocess randomint.sqf in init.sqs and place 'randomint.sqf' in your missions file
//--

--// revealtoall.sqs is a script that is similar to general barons AI info sharing
script.  Reveals presence of enemy units to whole of group when unit is detected
by ANY member of the group.  Script must be activated for each group member. //--

All feedback greatly appreciated especially code fixing help and scripting tips!!
(im not the most advanced scripter in the world)

Thankyou

R.E. (http://www.ofpec.com/yabbse/index.php?board=10;action=display;threadid=25124)
   - Original request for script


P.S. Please reply for more info if I have not been very clear here, things sound good in my head but others rarely understand my .... genius.

So far I have found a problem with the createunit command ..

The script tries to create a lasertarget object for the AI to shoot at but when the script runs it brings up an error message, can't remember it eaxtly but it was something about expecting an array and finding an object, run the script and see yourself.

FYI an example mission will follow shortly, I dont have the req. computer to make one at the moment

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:New AI coverfire script doesnt work ...
« Reply #1 on: 02 Sep 2005, 17:33:50 »
I will comment as I look through.  Coverfire.sqs -
First problem:

Code: [Select]
if (side _unit == west) then {_enemy = east} else {_enemy = west}
Surpising though it may seem _enemy will be undefined after this statement.  Local variable that are define within a {} only exists there and not later.  To achieve what you want you should try:

Code: [Select]
_enemy = west
if (side _unit == west) then {_enemy = east}

That way _enemy is defined before the If statement and so will contunie to exist after it.

EDIT:  Oops - just saw your definitions at the top.

Next point:

Code: [Select]
#initpos;
_pos = getpos _group select _i;
_initpos = _initpos+[_pos];
_i =_i+1;
_p =_p+1;
? _p < _groupcount : goto "initpos";

Will cause you to miss the last element of _group

Replace with:
Code: [Select]
#initpos
_pos = getpos _group select _i
_initpos = _initpos+[_pos]
_i =_i+1
? _i < _groupcount : goto "initpos"

Bye the way you don't need a ; at the end of each line in a script.

Ditto:
Code: [Select]
_i = 0;
_p = 1;
#secondpos
_pos = getpos _group select _i;
_c = _secondpos+[_pos];
_i =_i+1;
_p =_p+1;
? _p < _groupcount : goto "initpos";

Should be:

Code: [Select]
_i = 0
#secondpos
_pos = getpos _group select _i
_c = _secondpos+[_pos]
_i =_i+1
? _i < _groupcount : goto "secondpos"

Note also that I have changed the destination lable in the goto statement to send it to the correct place.

This part of the code is trying to establish if units are moving.  Why not use the command speed?

Next:

Get rid of the _p here as well:
Code: [Select]
_i = 0;
_p = 1;
#checkmove
if ((_initpos select _i) distance (_secondpos select _i) > _sensitivity) then {_identified = _identified + [_group select _i]};
_i =_i+1;
_p =_p+1;
? _p < _groupcount : goto "checkmove";

There is a deeper problem with this though.  The distance command will only work between two objects not between two locations.


You do realise that there will always be a value for _i where _unit will == _group select _i in the following line?
Code: [Select]
? _unit distance (_group select _i) <= _d : goto "checkenemy";
Code: [Select]
_i =_i+1;
_p =_p+1;
? _p < _groupcount : goto "checkdistloop2";
_d =_d+1;
goto "checkdistloop1";
There you go with _p again.

So this bit of code is stepping _d from 1 upwards until you find a member of _group that is closer to the _unit than _d.  As I mentioned above the test will find that _unit is very close to _unit.  Why not just calculate all the distances in one go and then select the smallest?


I am skipping quickly over stuff now.  Next obvious problem is:

Code: [Select]
if (_unit knowsAbout _enemylist select _i ) then {_enemylistknown = _enemylistknown + [_enemylist select _i]};
(_unit knowsAbout _enemylist select _i ) is a number not a boolean at the very least you should have


Code: [Select]
if ((_unit knowsAbout _enemylist select _i ) > 0.105) then {_enemylistknown = _enemylistknown + [_enemylist select _i]};


More to come...

Err... actually there isn't.  I think you have a lot to be going on with just restructuring it to fix these things.  Then I suggest you have a look through the comref
http://www.ofpec.com/editors/comref.php
There is a lot of stuff in there that will give you ideas about what to do, like using speed for example.  Also it will explain fully the use of knowsAbout etc.

I also suggest you investigate the forEach instruction.

Keep at it.  It is a neat idea, and your code is tidy, just not accurate.  I guess you have programmed elsewhere but are newish to this?
« Last Edit: 03 Sep 2005, 04:59:51 by THobson »

Offline paddy

  • Contributing Member
  • **
  • Llama whipping good
Re:New AI coverfire script doesnt work ...
« Reply #2 on: 04 Sep 2005, 18:47:09 »
Thanks THobson, took account of all the suggestions and have altered the script accordingly.

I think now this stripped down version of the script works.  However I tried using the 'fire' command to get the unit to fire more (lay down a wall of lead) but the unit fires straight up in the air!!!!!

I have at last :o made an example mission with all my scripts in it pre-loaded etc.

Hope this helps, i'm really at a loss here....
« Last Edit: 04 Sep 2005, 18:51:23 by paddy »

Offline 456820

  • Contributing Member
  • **
Re:New AI coverfire script doesnt work ...
« Reply #3 on: 04 Sep 2005, 18:51:23 »
i use dowatch or dotarget along with the fire command seems to work fine

Offline paddy

  • Contributing Member
  • **
  • Llama whipping good
Re:New AI coverfire script doesnt work ...
« Reply #4 on: 04 Sep 2005, 18:53:29 »
Example mission, forgot to attach >>

I've tried using the dowatch command as well, dofire is used to get the unit to fire initially but doesn't give very satisfactory results for continued firing.

Offline Blanco

  • Former Staff
  • ****
Re:New AI coverfire script doesnt work ...
« Reply #5 on: 04 Sep 2005, 20:36:45 »
Hi, I haven't tried the script but I would like to comment this :

Quote
if (side _unit == west) then {_enemy = east} else {_enemy = west}

I've never used the Enemy command before but it seems to return all enemy sides...

 
Search or search or search before you ask.

Offline paddy

  • Contributing Member
  • **
  • Llama whipping good
Re:New AI coverfire script doesnt work ...
« Reply #6 on: 04 Sep 2005, 22:28:47 »
Thanks for the hint but the enemy command would only overcomplicate things.  My system will suffice for my purpose (as part of the NImod 'www.nimod.net') so for the sake of simplicity and playability i want to keep the script to a minimum.  When I say playability, this script will run for EVERY unit in the nimod missions and hence a smaller script will be less taxing on the computer.

However if you could suggest a line of script simpler than mine that did the same thing i would appreciate it.