OFPEC Forum
Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting Multiplayer => Topic started by: Hawke on 02 Jan 2009, 12:57:23
-
Hey,
Im just learning how to use the publicVariable command and i was woundering if you can make a publicVariable call a script.
global_command = "[flag,Lgate,Rgate,0,3] exec (log\scripted_gate.sqs)"
publicvariable "global_command"
-
global_command addPublicVariableEventHandler {call compile (this select 1)};
-
Remember that publicVariable handlers are only run remotely, not locally, so you need to do a bit more to ensure your code runs globally (both remotely and locally).
To do what you asked for is an entirely generic system to run code:
global_command_handler = { call compile _this };
"global_command" addPublicVariableEventHandler { (_this select 1) call global_command_handler };
global_command = "[flag, Lgate, Rgate, 0, 3] exec ""log\scripted_gate.sqs""";
publicVariable "global_command"; // Run remotely.
global_command call global_command_handler; // Run locally.
However, what you should probably do in this case, assuming you really have to use sqs, is:
open_gate_handler = { _this exec "log\scripted_gate.sqs" };
"open_gate" addPublicVariableEventHandler { (_this select 1) call open_gate_handler };
open_gate = [flag, Lgate, Rgate, 0, 3];
publicVariable "open_gate"; // Run remotely.
open_gate call open_gate_handler; // Run locally.
-
@ spooner
Hey, your idea worked when i tryed hosting a session but when i tryed it on my dedicated server, the server wouldn't move the wall but it would on the clients. so all you would see is a wall moveing backwards and forwards like the server didnt run the script so it kept pushing the wall back where it came from after every 3 seconds.
any idea why ??? ???
-
There are any number of reasons why this wouldn't work as you'd expect. However, without knowing anything about the gate object, about "log\scripted_gate.sqs", or how you are running the code I gave you, I have no idea why exactly it wouldn't be working...
-
Ok,
first off there is a flag on the map named flag that has the open called "open gate", once you have hit the action it open a dialog in which you have to enter a password pops up,
#ACOY
_ok = createDialog "DlgTutorial2"
?!(dialog): exit
#ACOY1
_buffer = ctrlText 202
_action = format ["%1", _buffer]
buttonSetAction [204, _action]
? _action == "password" : goto "Open"
?!(dialog): goto "death"
goto "ACOY1"
#Open
closedialog 0
titletext [format ["Welcome to 3 PARA's armoury , %1",name player],"plain down"]
[] exec "log\doors.sqs"
#death
closedialog 0
titletext [format ["The area you are trying to access is restricted area, %1",name player],"plain down"]
exit
when the password is entered it runs the door.sqs which has the publicvariable you sent me. At the moment its in a .sqs, i even tryed a .sqf
open_gate_handler = { _this exec "log\scripted_gate.sqs" };
"open_gate" addPublicVariableEventHandler { (_this select 1) call open_gate_handler };
open_gate = [flag, Lgate, Rgate, 0, 3];
publicVariable "open_gate";
open_gate call open_gate_handler;
Then the publicvariable should run the scripted_gate.sqs
_obj = _this select 0
_leftgate = _this select 1
_rightgate = _this select 2
_open_or_close = _this select 3
_dist = _this select 4
_gatedir_left = getdir _leftgate
_gatedir_right = getdir _rightgate
_dir = _gatedir_left - 90
_dir2 = _gatedir_right + 90
_sp = 0.01
?(getdammage _obj> 0.5 OR GETdammage _leftgate > 0.5 OR Getdammage _rightgate > 0.5) : hint "Mechanism is damaged"; exit
;reverse the direction when to gate closes
?_open_or_close == 0:_dir = _dir - 180
?_open_or_close == 0: _dir2 = _dir2 - 180
_pos = getpos _leftgate
_pos2 = getpos _rightgate
_leftgate setpos _pos
_rightgate setpos _pos2
_x = (_pos select 0) - ((getpos _leftgate) select 0)
_y = (_pos select 1) - ((getpos _leftgate) select 1)
_z = (_pos select 2) - ((getpos _leftgate) select 2)
_x2 = (_pos2 select 0) - ((getpos _rightgate) select 0)
_y2 = (_pos2 select 1) - ((getpos _rightgate) select 1)
_z2 = (_pos2 select 2) - ((getpos _rightgate) select 2)
_pos = getpos _leftgate
_pos2 = getpos _rightgate
_leftgate setpos [(_pos select 0)+2*_x,(_pos select 1)+2*_y,(_pos select 2)+2*_z]
_rightgate setpos [(_pos2 select 0)+2*_x2,(_pos2 select 1)+2*_y2,(_pos2 select 2)+2*_z2]
_md = _dist / (1 - _sp)
#1oop
_pos = getpos _leftgate
_pos2 = getpos _rightgate
_leftgate setpos [(_pos select 0)+_x+((sin _dir)*_sp),(_pos select 1)+_y+((cos _dir)*_sp),(_pos select 2)+_z]
_rightgate setpos [(_pos2 select 0)+_x2+((sin _dir2)*_sp),(_pos2 select 1)+_y2+((cos _dir2)*_sp),(_pos2 select 2)+_z2]
~_sp
_md = _md - _sp
?(_md >= 0): goto "1oop"
exit
so don't know where it's going wrong. :dunno:
-
Sorry for bumbing, but is any one going to help me????
-
I gave you these bits of code in two parts for a reason:
open_gate_handler = { _this exec "log\scripted_gate.sqs" };
"open_gate" addPublicVariableEventHandler { (_this select 1) call open_gate_handler };
open_gate = [flag, Lgate, Rgate, 0, 3];
publicVariable "open_gate"; // Run remotely.
open_gate call open_gate_handler; // Run locally.
The first part adds the handler and must be done on all machines at the start of the mission (e.g. from init.sqs or init.sqf). It sets up an event handler which allows everyone to see the effect. The second part actually invokes the handler on all machines. I think the problem is that if you run all that only when you open the gate via an action, the handlers have not been created on all machines already, so the animation (scripted_gate.sqs) will only occur on the gate-opener's machine.
-
It works now, cheers. But you never said any thing about adding the EH in the init on the first post :P
-
OR....
_this setvehicleinit format["%1 exec 'log\scripted_gate.sqs'", _this];
processinitcommands
;)