OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: Lean Bear on 28 Jun 2005, 11:46:08
-
I know that there is onSingleMapClick, so surely there must be a way to find if you've clicked your left-mouse button, right?
As that is the default primary fire - could checking that if you've fired relate to whether that button has been pressed? Or is there a much easier way? (eg onClick :)) :P
-
you could use a EH,
unitname addeventhandler ["Fired",{hint format ["%1 has pushed the button",name unitname]}]
although if your OFP is set up like mine left Ctrl also fires :-(
-
dont know why you would want to check if a mouse click had occured
I dont see anything useful that could come from it that would be reliable
a) you are probably assuming that everyone has the same key setup
b) There are no other instances of a mouse click being used, eg dialogues
what is it that you are aiming to achieve, maybe there is another way around your problem
-
I agree..
Most of the time fired eventhandler would be fine (The BAS Radio doesnt acctualy fire anything, but when you click it plays that radio sound, so it doesn't have to create a bullet to trigger it)
What'r you trying to achive? :P
- Ben
-
I think the event handler will work fine. (btw It doesn't matter if not everyone has the same keyboard set-up. Its just really to detect when the "fire" button is pressed)
But what I'm trying to do is:
I have this sequence of animations, right. And at certain points, the anim will change if the primary fire button is pressed. (animationPhase should do the trick for timing it).
The way I see it, is if you have one anim playing, and say, halfway through the anim you press "fire" (at 0.5 in the anim phase), then another anim will play (using switchMove in a script) - and this could continue for ever :)
-
ok from what i understand
firing a weapon will run a series of animations
if you then fire while the animations are running, then it will cause another anim to run.
this can be done with a booleans, arrays and some form of timing counter
dunno whether this is ai and player or just player, so will try and make an ai compatible version for ya
excuse the long variable names, they are for clarity
Init.sqs
tx_Unit_in_Anim = []
tx_stopPlay = false
tx_firedevents = 0
fired event script
_unit = _this select 0
if(_unit in tx_Unit_in_Anim)then{goto "INTERRUPT_ANIM"}else{tx_Unit_in_Anim = tx_Unit_in_Anim + [_unit]}
tx_start_time = time
_unit playmove "AAA"
if(tx_stopPlay)then{exit}
_unit playmove "BBB"
if(tx_stopPlay)then{exit}
_unit playmove "CCC"
if(tx_stopPlay)then{exit}
tx_Unit_in_Anim = tx_Unit_in_Anim - [_unit]
exit
#INTERRUPT_ANIM
tx_firedevents = tx_firedevents +1
if(tx_firedevents > 1)then{exit}
tx_stopPlay = true
#LOOP
if ((time - tx_start_time) <= 5)then{_unit switchmove "XXX"}else{unit switchmove "YYY"}
~1
tx_firedevents = tx_firedevents -1
if(tx_firedevents > 0)then{goto "LOOP"}else{tx_Unit_in_Anim = tx_Unit_in_Anim - [_unit];tx_stopPlay = false;exit}
ok the basics
first fired event
1) places the unit in a global array
2) creates a global variable which saves the mission time that the initial fired event occurred at
3) If no other fired events occur, then :
..........all the anims are played through
.......... the unit is removed from the array
.......... and the system is reset
4) If another fired event occurs during these anims, this second fired eveny then:
.......... Issues a boolean "tx_stopPlay" which stops the playmoves in the first fired event script
.......... Increases a fired event counter by 1 (used if a 3rd or more fired events occur during the switchmove anims)
5) If a third or more fired event DOES NOT occur, then:
.......... it plays the switchmoves once
.......... decreases the counter back to 0
.......... exits the loop
.......... and removes the unit from the array
6) If a third or more fired events occured while the second fired event script is running then:
.......... It loops its switchmoves until the counter reaches 0
7) Any additional fired events that occur while the second event is running, will simply increase the counter then exit
The reason for the array (ai compatability) for ai local to the players client
If this is only run on a player, then use a boolean instead
hope that helps
NB>>> you may have to place pauses after each playmove or switchmove, not sure if the script waits for the move to be played before reading the next line or if it runs through all the lines and places the moves in a queue
-
OK, thanks for that great script.
I completely understand where you're going with this, and after replacing all the playMove's with switchMove's (playMoves don't work so great with these particular animations) and adding delays for the anims to play - I couldn't find any errors or anything :)
The only problem was that I don't think the second part of the script actually runs.
After looking over it several times, and adding/adjusting vrious lines - I couldn't see anywhere anything that actually checks if the mouse is clicked (the weapon fired) :P
I can see the variables related to it - but I don't actually see any code that checks for it. Am I missing something obvious here, or what?
btw This reply took so long because I went for a different method which is much simpler, but requires way more scripts - and after a while you begin to notice a little lag - so I came back to this to see if we could get it working.
-
the "fired event script" is the script that runs of a fired event handler.
for the purposes of this explanation, have named the above script "firedevent.sqs"
eg if you attach a fired eventhandler to a unit, everytime he fires a weapon, the designated event,( in the below example, this is a script.) will occur
to add a fired event
create an array with all the units you want your system to work on
eg
tx_Units = [W1,W2,W3,W4,W5]
and then attach the fired event handler to them
{_x addEventHandler ["fired", {_this exec "firedevent.sqs"}]} foreach tx_units
this is normally declared in the init.sqs.
If you have a lot of units, then you can place a trigger over all the units and instead of using "foreach arrayname" you can use foreach list triggername
-
Whoopsy :P
I can't believe I missed that :P You even wrote "fired event script" and everything :P
OK, the script is working fine. I was wondering if there was a way to repeat it again. For example, after the "Interrupt_Anim" section, would it be possible to repeat what happened in the first section (when the unit fires, checking if the unit is in the array etc.) for the second section.
To put it more clearly:
Fired Event 1 -> Anim 1 -> Interrupt Anim 1 -> Fired Event 2 -> Anim 2 -> Interrupt Anim 2...and so on...?
Again, thanks for you help so far.
edit
I should probably mention that I already tried using another variable to count how many times the script has been called - but it wouldn't work like that. To use that method, the whole script would have to be re-written.