Home   Help Search Login Register  

Author Topic: sqf troubles (ai finding cover)  (Read 986 times)

0 Members and 1 Guest are viewing this topic.

Offline Triggerhappy

  • Contributing Member
  • **
  • Llama, it's what's for dinner.
sqf troubles (ai finding cover)
« on: 15 Jul 2005, 01:27:55 »
I thought i was doing really good....

heres the deal:
i have made 3 functions that are supposed to work together to find any form of cover for ai (attached below with the test mission)

but it seems that the "probes" are stopping before getting anywhere

i have a script that gives a hint format of the output and another giving the players pos

i apologize that the functions aren't commented but i still need to finish them

if you need me to explain anything i'll be glad to.

thanks

EDIT:
the concept behind this is that the soldier will be displaced by the "cover" when setpos'd on it, therefore there must be something there
« Last Edit: 15 Jul 2005, 22:36:21 by Triggerhappy »

Offline Fragorl

  • Coding Team
  • Former Staff
  • ****
Re:sqf troubles
« Reply #1 on: 15 Jul 2005, 05:24:53 »
Just a quick question; i'll probably be slapping my forehead when i find out, but where do you call the initial script from? - not the init squis but the call_cover squis. Could this be the problem?

Offline Triggerhappy

  • Contributing Member
  • **
  • Llama, it's what's for dinner.
Re:sqf troubles
« Reply #2 on: 15 Jul 2005, 05:36:24 »
no i call it via radio. (i thought i said that...) nope, guess i didn't. whoops, sry

the initial script is called by radio

*slaps forehead ;D

Offline Fragorl

  • Coding Team
  • Former Staff
  • ****
Re:sqf troubles (ai finding cover)
« Reply #3 on: 16 Jul 2005, 05:06:54 »
;)

So, reading through them in detail, I see the functions as doing the following:

1.) take a unit, eg the player
2.) camcreate a dummy soldier 2 metres away from the player in specified directions (0, 45, 90, 135 etc degrees), AND 1 metre up into the air.
3.) Loop, checking each time that the x and y coordinates of the camcreated soldier are exactly equal to the x and y of the initial position (where the dummy was created).
4.) In the body of the loop, you call a function which moves the dummy 0.1 metres further away from the player, in the initial direction.

Immediately, you can see the loop will be broken as the position of the camcrated soldier is no longer the same as its starting position. You would need to update _pos, from gatherdata.sqf, as well. I see what you are trying to do though. You are moving the test soldier to a position, and testing to see whether or not he could actually be moved there; if he couldn't then you assume that there is some form of cover blocking him.

I would do away with move_probe altogether, and change some things in gatherdata, like this:

GatherData.sqf
Code: [Select]
private ["_unit","_dir","_pos","_orig_pos","_cover","_probe","_return"];
_unit = _this select 0;
_dir = _this select 1;
_pos = [(getpos _unit select 0) + (2 * sin _dir),(getpos _unit select 1) + (2 * cos _dir),0];
_orig_pos = _pos;
_cover = false;
_probe = "soldierwb" camcreate _pos;
while "((getpos _probe select 0) == (_pos select 0) && (getpos _probe select 1) == (_pos select 1))) ||
   (sqrt((((_pos select 0)  - (_orig_pos select 0))^2) + (((_pos select 1)  - (_orig_pos select 1))^2)) >= 5)" do
{
   _pos = [(_pos select 0) + (.1 * sin _dir),(_pos select 1) + (.1 * cos _dir),0];
   _probe setpos _pos;
};
if (sqrt((((_pos select 0)  - (_orig_pos select 0))^2) + (((_pos select 1)  - (_orig_pos select 1))^2)) < 5) then {_cover = true};
deletevehicle _probe;
_return =[_cover,_pos,_dir];
_return

I've added the condition from move_probe to this function; that is if the probe is more than 5 metres from the original position , scrub the attempt to find cover. Also, _pos is updated in the loop body as well as moving the probe, and then at the end of each loop the pos is checked again (to see if the move was successful).

Unfortunately, I'm fairly certain that the setpos attempt will always be returned as successful regardless of whether there was anything blocking the attempt; that's what happened when i tried doing a similar thing in a function. The actual move takes a certain amount of time (i believe ofp waits until the next game 'tick' to actually move the object, despite setting it's position as described in the setpos instantly). However, you might have more success than i did. Failing that, you will have to resort to a script with a small ~ delay.
« Last Edit: 16 Jul 2005, 05:08:20 by Fragorl »

Offline Triggerhappy

  • Contributing Member
  • **
  • Llama, it's what's for dinner.
Re:sqf troubles (ai finding cover)
« Reply #4 on: 16 Jul 2005, 05:13:27 »
well, the reason i had the move_probe.sqf is that i originally had something similar to yours (minus that second check) and i kept getting errors unit i left it to just one item in the while do command. I'll try yours and see how it works, hopefully it will and then ai scripts can be improved with this function.

otherwise a script may have to do

thanks for your help

Offline Triggerhappy

  • Contributing Member
  • **
  • Llama, it's what's for dinner.
Re:sqf troubles (ai finding cover)
« Reply #5 on: 16 Jul 2005, 05:26:24 »
nope it spits out a gigantic error message at me

Offline Fragorl

  • Coding Team
  • Former Staff
  • ****
Re:sqf troubles (ai finding cover)
« Reply #6 on: 16 Jul 2005, 05:28:20 »
np ;D

the only reason i abandoned the attempt is because i also wanted a function, not a script, that would instantly find some cover. Setting up a script to return values to another script was too much hard work, and the delay didnt suit my purposes

I suggest you have a look for gen barron's coverscript; it's very good and whilst the version i had caused game crashes, apparently there's another, earlier? version that works really well...

Offline Fragorl

  • Coding Team
  • Former Staff
  • ****
Re:sqf troubles (ai finding cover)
« Reply #7 on: 16 Jul 2005, 05:28:58 »
Hmm... error message eh? well let's see...

the correct version should be this:
Code: [Select]
while "((getpos _probe select 0) == (_pos select 0) && (getpos _probe select 1) == (_pos select 1)) &&
   (sqrt((((_pos select 0)  - (_orig_pos select 0))^2) + (((_pos select 1)  - (_orig_pos select 1))^2)) < 5)" do
{
   _pos = [(_pos select 0) + (.1 * sin _dir),(_pos select 1) + (.1 * cos _dir),0];
   _probe setpos _pos;
};

was error missing brackets, and the 'and' should be 'or', plus the sign was around the wrong way
« Last Edit: 16 Jul 2005, 05:54:03 by Fragorl »

Offline Triggerhappy

  • Contributing Member
  • **
  • Llama, it's what's for dinner.
Re:sqf troubles (ai finding cover)
« Reply #8 on: 16 Jul 2005, 05:43:21 »
yeah the message doesn't help though

generic error in expression

but the little |#|  is after the second line of the while do part
which leads me to believe that it won't work as a function