Home   Help Search Login Register  

Author Topic: getDir tank turret  (Read 1590 times)

0 Members and 1 Guest are viewing this topic.

Offline macguba

  • Former Staff
  • ****
    • macguba's operation flashpoint page
getDir tank turret
« on: 11 May 2005, 14:04:09 »
Does anybody know how to get the direction of a tank turret?   I'm guessing that for an AI controlled tank I can make it fire and then do something with an EH that will get me there.   But what about a player controlled tank?  

getDir just returns the direction of the hull.   As does getDir on any of the crew.

I'm trying to make a tank smoke screen script.  If anybody knows of one out there already that would save me the trouble .... My one works beautifully but only if you're facing north.

Many thanks
Plenty of reviewed ArmA missions for you to play

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:getDir tank turret
« Reply #1 on: 11 May 2005, 14:56:53 »
afaik you can't..
Not without editing the tank model, or using a gimmick that would require an 'AddOn' (just a small config and few scripts)...
« Last Edit: 11 May 2005, 14:58:08 by HateR_Kint »
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline macguba

  • Former Staff
  • ****
    • macguba's operation flashpoint page
Re:getDir tank turret
« Reply #2 on: 11 May 2005, 15:39:46 »
Thanks m8 .... I thought as much.   I've got a workaround more or less working, but we'll need to see if it's acceptable.

Two related questions.

1)  Any idea how to determine which weapon a tank currently has selected?    I can change it with selectWeapon, but I want to know what it was so I can change it back if needs be.    


2)  I'm using this line of code, adapted from something I found on the forums I think by GB but I've forgotten already.

_tank addEventHandler ["fired",{call format ["bullet=nearestObject [_this select 0,""%1""]",_this select 4]; tankDir=(getDir bullet)}]

It works just fine.  :)  However, you will note that tankDir is a global variable.   If I make it local, _tankDir, I get an error.   Is there any way of extracting this value as a local?   I suspect there is the same issue with bullet.  

If it has to be global, then you need a seperate script for each tank which is very tedious.  Plus its eating up your global variables.      If I can make all this work the way I want then there is a non-trivial risk that two tanks will be using the script at the same time .. I suppose in theory I can detect that and make them queue for it .... *groan*

Thanks again.
Plenty of reviewed ArmA missions for you to play

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:getDir tank turret
« Reply #3 on: 11 May 2005, 17:49:38 »
A few random thoughts (I only have a few minutes so some of it may be of no help at all):

- does getDir (gunner tankname) tell you anything useful about the direction of the gun?

-my experience with EH is that whatever it actions needs to use global variables - in effect it just runs the code as written at the time of the event.

-If you have to have a global variable but you want to get rid of it later setting it = nil destroys it.

- cound you use the format command so that TankDir is TankDir1, TankDir2 etc.  then you could have mutiple instances of the same script running one for each tank

- congratulations on all the blue stars

I will think more on this over dinner.

Offline 456820

  • Contributing Member
  • **
Re:getDir tank turret
« Reply #4 on: 11 May 2005, 17:57:47 »
well the M1A2 addon has a tank dust script so maybe if you un pbo it and take alook at how they did it might help

Offline macguba

  • Former Staff
  • ****
    • macguba's operation flashpoint page
Re:getDir tank turret
« Reply #5 on: 11 May 2005, 17:59:52 »
Quote
does getDir (gunner tankname) tell you anything useful about the direction of the gun?
No

Quote
my experience with EH is that whatever it actions needs to use global variables - in effect it just runs the code as written at the time of the event.
Thanks, that's the kind of tip I needed


Quote
If you have to have a global variable but you want to get rid of it later setting it = nil destroys it.
That's not the problem.    I haven't even started on the calling conditions yet but there is a strong chance of several tanks in the same group calling the script at virtually the same time.   Global variables are going to be messy.   It's not terminal though.

Quote
cound you use the format command so that TankDir is TankDir1, TankDir2 etc.  then you could have mutiple instances of the same script running one for each tank
Probably but I'm a bit vague on that sort of thing.  Any chance of an example?

Quote
congratulations on all the blue stars
Thank you.  :)


@456820 - thanks.  I haven't started looking at dust scripts yet, it's a good idea.
« Last Edit: 11 May 2005, 18:00:51 by macguba »
Plenty of reviewed ArmA missions for you to play

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:getDir tank turret
« Reply #6 on: 11 May 2005, 20:58:38 »
At least in the config you can use local variables in the eventHandlers...
And actually you can do it when calling scripts too, sort of...

I'm not actually sure if this would work, but you can try something like:
Code: [Select]
_tank addEventHandler ["fired",{call format ["bullet=nearestObject [_this select 0,""%1""]",_this select 4];{_tankDir=(getDir bullet)}}]or
Code: [Select]
_tank addEventHandler ["fired",{call format ["bullet=nearestObject [_this select 0,""%1""]",_this select 4];"_tankDir=(getDir bullet)"}]
then in the executed script:
Code: [Select]
_turDir = call (_this select 1)
Or if that doesn't work:
Code: [Select]
_turDirStr = _this select 1
_turDir = call _turDirStr

Nowhere near guaranteed :P
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:getDir tank turret
« Reply #7 on: 11 May 2005, 21:18:43 »
Please bear with the muddled typing, and hopefully not to muddled thinking - just back from a wonderful dinner in Provence.

Quote
_tank addEventHandler ["fired",{call format ["bullet=nearestObject [_this select 0,""%1""]",_this select 4]; tankDir=(getDir bullet)}]
All this does is once the tank fires its gun is to set the values of two global variables.  I presume you have a script running somewhere that uses them.  One posibility is to have the EH run the script directly, something like (and this is where the provencal wine starts to get in the way);

_tank addEventHandler ["fired",{[_this select 0,_this select 4] exec "thisisthescripttorunwhenatankfiresitsgun.sqs"}]


in the script have

_bullet =nearestObject [_this select 0,_this select 1]
_tankDir=(getDir _bullet)




Or some such.



Also

_tank addEventHandler ["fired",{_this exec "thisisthescripttorunwhenatankfiresitsgun.sqs"}]

 might also be worth playing around with.

In the script:
_this select 0 : who fired ;
_this select 1 : with what weapon ;
_this select 2 : with what muzzle (your M16, or M203 ?)
_this select 3 : mode ? (either single, or burst, or auto)
_this select 4 : the type of ammo used.


I am sorry I can't test anything I am away from my games machine at the moment.
« Last Edit: 11 May 2005, 21:28:10 by THobson »

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:getDir tank turret
« Reply #8 on: 12 May 2005, 17:57:13 »
The problem of using nearestObject within an sqs is that once some lag is introduced the script may very well 'miss' the bullet/shell...
This was a major problem when we started devving MCAR...

Anyway, tested this and it works:
Code: [Select]
this addEventHandler ["fired",{direction (nearestObject [_this select 0,_this select 4]) exec "script.sqs" }]
In the script you get the dir with:
_dirTurret = _this

No need to use such a complex way like in the example given in the first post...
« Last Edit: 12 May 2005, 17:58:11 by HateR_Kint »
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline macguba

  • Former Staff
  • ****
    • macguba's operation flashpoint page
Re:getDir tank turret
« Reply #9 on: 12 May 2005, 19:46:28 »
OK we're making progress.    Thank you all.

Current situation:-

addAction "fire smoke"

The action calls the first script, which has (in summary):-

_tank=_this select 0
_tank addEventHandler ["fired",{_this exec "smoke2.sqs"}]
_tank fire machine gun
_tank removeEH
exit

And then in the second script.

_tank = _this select 0
_ammo = _this select 4
_dir = direction (nearestObject [_tank, _ammo])

Bingo.

HateR_Kint, your last solution worked perfectly, but I need to be able to grab the tank in the second script so a little adaption was needed.    Once I'd restarted OFP to get rid of an unjustified error message it all seemed so simple.   Anybody else had a line of code both work perfectly and also produce an error message?    ::)



Plenty of reviewed ArmA missions for you to play

Offline macguba

  • Former Staff
  • ****
    • macguba's operation flashpoint page
Re:getDir tank turret
« Reply #10 on: 12 May 2005, 23:32:33 »
Beta version up on the scripts beta board.

Thanks again for all your help.  :)

Still a long way to go.
Plenty of reviewed ArmA missions for you to play

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:getDir tank turret
« Reply #11 on: 13 May 2005, 10:03:54 »
Well, you can still (and you should) 'catch' the bullet/shell in the eventHandler:
Code: [Select]
this addEventHandler ["fired",{_projectile=(nearestObject [_this select 0,_this select4]); [_this select 0,direction _projectile] exec "dir.sqs"}]
so, in the first script:
Code: [Select]
_tank=_this select 0
_tank addEventHandler ["fired",{_projectile=(nearestObject [_this select 0,_this select4]); [_this select 0,direction _projectile] exec "smoke2.sqs"}]
_tank fire machine gun
_tank removeEH
exit

and in the smoke2:
Code: [Select]
_tank = _this select 0
_dir = _this select 1
« Last Edit: 13 May 2005, 10:04:16 by HateR_Kint »
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline macguba

  • Former Staff
  • ****
    • macguba's operation flashpoint page
Re:getDir tank turret
« Reply #12 on: 13 May 2005, 10:08:57 »
Brilliant!   Your OBE is in the post.

That's exactly what I wanted to do but I couldn't figure out how to catch it in the EH (which is obviously much better) and then pass both _dir and _tank to the second script.

Plenty of reviewed ArmA missions for you to play

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:getDir tank turret
« Reply #13 on: 13 May 2005, 12:40:41 »
Quote
Your OBE is in the post.
lol, ok... :P

So yay, I actually managed to help someone... :)
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.