OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: macguba 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
-
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)...
-
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.
-
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.
-
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
-
does getDir (gunner tankname) tell you anything useful about the direction of the gun?
No
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
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.
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?
congratulations on all the blue stars
Thank you. :)
@456820 - thanks. I haven't started looking at dust scripts yet, it's a good idea.
-
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:
_tank addEventHandler ["fired",{call format ["bullet=nearestObject [_this select 0,""%1""]",_this select 4];{_tankDir=(getDir bullet)}}]or
_tank addEventHandler ["fired",{call format ["bullet=nearestObject [_this select 0,""%1""]",_this select 4];"_tankDir=(getDir bullet)"}]
then in the executed script:
_turDir = call (_this select 1)
Or if that doesn't work:
_turDirStr = _this select 1
_turDir = call _turDirStr
Nowhere near guaranteed :P
-
Please bear with the muddled typing, and hopefully not to muddled thinking - just back from a wonderful dinner in Provence.
_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.
-
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:
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...
-
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? ::)
-
Beta version up on the scripts beta board. (http://www.ofpec.com/yabbse/index.php?board=27;action=display;threadid=23622)
Thanks again for all your help. :)
Still a long way to go.
-
Well, you can still (and you should) 'catch' the bullet/shell in the eventHandler:
this addEventHandler ["fired",{_projectile=(nearestObject [_this select 0,_this select4]); [_this select 0,direction _projectile] exec "dir.sqs"}]
so, in the first script:
_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:
_tank = _this select 0
_dir = _this select 1
-
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.
-
Your OBE is in the post.
lol, ok... :P
So yay, I actually managed to help someone... :)