Home   Help Search Login Register  

Author Topic: Run once  (Read 506 times)

0 Members and 1 Guest are viewing this topic.

max_killer_payne

  • Guest
Run once
« on: 24 Aug 2003, 17:14:21 »
How can I make an add action script run once, It will add to the action menu when you get within 3 metres of the policeman. But the policeman is scheduled to get killed in a minute. So what do I put in my script to make sure once its run once, it doesent run again. Heres my script:

Code: [Select]
_unit = _this select 0
_player = _this select 1
?runonce: goto "whenadd"
actionnumber = 0

#whenadd
?(_player distance _unit < 3): goto "action"
~0.3
goto "action"

#action
runonce=true
action = _player Addaction ["Report your problem","thingy.sqs"]
;here I am IDing the action, to a name which is action, so when you use the action in the game OFP will recognise you just used 'action'
~0.3
goto "start"

#start
?report: goto "whathappens"
?(_player distance _unit) < 3: goto "start"
_player RemoveAction (action)
actionnumber = (actionnumber + 1)
goto "action"

#whathappens
titletext["Excuse me officer, can you help?","plain",2]
~5
titletext["Well, I'll try sir.","plain",2]
~5
titletext["Good, I'm in way too deep","plain",2]
;or whateva u want to happen here
goto "nomore"

#nomore
nameofurscript=false
_player removeaction action
actionnumber = (actionnumber + 1)
exit

Offline Killswitch

  • Members
  • *
  • Peace, cheese and ArmA
Re:Run once
« Reply #1 on: 25 Aug 2003, 15:53:21 »
In your init.sqs (or in the init field of some unit or even in a trigger somewhere. Depends on how you have the mission set up, of course)

Code: [Select]
runonce=false;
report=false;


Then, the script above could look like this:
Code: [Select]
_unit = _this select 0
_player = _this select 1
?runonce: exit
actionnumber = 0

;
; Wait until player gets within 3 m of the unit.
;
#getcloser
?(_player distance _unit < 3): goto "action"
~1
goto "getcloser"

;
; Then, add the "Report your problem" action
;
#action
action = _player addAction ["Report your problem","thingy.sqs"]

;
; Wait until player uses the action or moves away from the officer.
; It is assumed that thingy.sqs sets the variable report to true when run

#start
?report: goto "whathappens"
; Dont waste too much CPU on busy waiting...
~1
?(_player distance _unit) < 3: goto "start"


;
; Player walked away. Go back and wait for him to close again.
;
_player removeAction (action)
actionnumber = (actionnumber + 1)
goto "getcloser"

#whathappens
titletext["Excuse me officer, can you help?","plain",2]
~5
titletext["Well, I'll try sir.","plain",2]
~5
titletext["Good, I'm in way too deep","plain",2]
;or whateva u want to happen here

; Player has delivered his report. This is a one-time event.
runonce=true


#nomore
nameofurscript=false
_player removeAction action
actionnumber = (actionnumber + 1)
exit

Note
  • I don't know what you need the "actionnumber" or the "nameofurscript" for...
  • Strictly, you don't need the runonce variable if the script above is started only once and you don't use runonce anywhere else.

max_killer_payne

  • Guest
Re:Run once
« Reply #2 on: 25 Aug 2003, 16:00:41 »
Thanks Killswitch. I appreciate it.  ;D

Komuna

  • Guest
Re:Run once
« Reply #3 on: 26 Aug 2003, 10:45:23 »
Very simple my friends... Just remove the action and forget any additional variables. Besides, though the script will skip the code with the 'runonce' variable, the action would still be available. Then:

Unit removeaction _index

(As you told, the action only appears when you aproach the policeman, which means that you're actually adding such action to the policeman.)

PoliceMan removeAction 0

Hey! But don't fully trust me ;D !!! Check the 'removeAction' command first.... And remember that addAction retunrs an array with the following format:

[Whom was added, Who activated it, action index]
« Last Edit: 26 Aug 2003, 12:01:28 by Komuna »