Jump to content
Sign in to follow this  
pwrmx24

Make an addAction for portable light for all MP - Yeah I know...but can't find it

Recommended Posts

Continuing to work on my land portable light that can be switched on/off by all players. Good practice for newbie scripter.

So this worked in my first ever init.sqf:

createMarker ["spot1mkr",6469.65,5311.91,14.7677];

if (isserver) then {spot1 = createVehicle ["Land_PortableLight_double_F",getmarkerpos "spot1mkr",[],0,"none"]};

if (isServer) then {spot1 setDir 090};

spot1 addAction ["Turn Off", {spot1 setHit ["Light_1_hitpoint",1], spot1 setHit ["Light_2_hitpoint",1]}];

spot1 addAction ["Turn On", {spot1 setHit ["Light_1_hitpoint",0], spot1 setHit ["Light_2_hitpoint",0]}];

I thought this would force the clients to add the action when loading the init.sqf. It puts the light down w/out duplicates upon JIP but it doesn't seem to add the addAction.

I have searched all night...I think I understand local and global executed commands now thanks Kill Zone Kid blog:

http://killzonekid.com/arma-scripting-tutorials-basic-multiplayer-coding/

then i thought a duplicative "if" "then" "else" in the init.sqf but that seemed to disable the host addAction. e.g.:

if (isServer) then {addAction ["Turn Off", {spot1 setHit ["Light_1_hitpoint",1], spot1 setHit ["Light_2_hitpoint",1]}]} else {addAction ["Turn Off", {spot1 setHit ["Light_1_hitpoint",1], spot1 setHit ["Light_2_hitpoint",1]}]}

Do I need to:

Create my own function then broadcast that function to all clients then execute them on the client somehow:

fxoff = {addAction ["Turn Off", {spot1 setHit ["Light_1_hitpoint",1], spot1 setHit ["Light_2_hitpoint",1]}]};

if (!isServer) then {"fxoff"};

Or do i need to use the BIS_fnc_MP function somehow.

Great game.....steep learning curve on editing for me.

Share this post


Link to post
Share on other sites

Helps when your syntax is correct:

spot1 addAction ["Turn Off", {spot1 setHit ["Light_1_hitpoint",1]; spot1 setHit ["Light_2_hitpoint",1];}];
spot1 addAction ["Turn On", {spot1 setHit ["Light_1_hitpoint",0]; spot1 setHit ["Light_2_hitpoint",0];}];

Share this post


Link to post
Share on other sites

Well, there are a few problems here. The main ones being that the spot1 variable only exists on the server and setHit is an argument local command. The first problem can be fixed by using publicVariable on spot1 to broadcast it to everyone. Then we use a waitUntil and isNil to hold clients until they receive that variable. However, since we are using a waitUntil, we have to move the code to a different scheduled thread than what the init.sqf runs in (you shouldn't stop the init.sqf). Finally, we add the addActions but this time using BIS_fnc_MP and its CfgRemoteExecCommands functionality to run the setHits in the code blocks.

All in all, it will look like this. I haven't tested it, though...

[color="#FF8040"][color="#006400"][i]// server only code[/i][/color]
[color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#191970"][b]isServer[/b][/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]then[/b][/color] [color="#8B3E2F"][b]{[/b][/color]
[color="#006400"][i]// why are you using this marker?[/i][/color]
[color="#191970"][b]createMarker[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#7A7A7A"]"spot1mkr"[/color][color="#8B3E2F"][b],[/b][/color][color="#FF0000"]6469.65[/color][color="#8B3E2F"][b],[/b][/color][color="#FF0000"]5311.91[/color][color="#8B3E2F"][b],[/b][/color][color="#FF0000"]14.7677[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color]
spot1 [color="#8B3E2F"][b]=[/b][/color] [color="#191970"][b]createVehicle[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#7A7A7A"]"Land_PortableLight_double_F"[/color][color="#8B3E2F"][b],[/b][/color][color="#191970"][b]getMarkerPos[/b][/color] [color="#7A7A7A"]"spot1mkr"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b][[/b][/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b],[/b][/color][color="#FF0000"]0[/color][color="#8B3E2F"][b],[/b][/color][color="#7A7A7A"]"none"[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color]
spot1 [color="#191970"][b]setDir[/b][/color] [color="#FF0000"]90[/color][color="#8B3E2F"][b];[/b][/color]
[color="#006400"][i]// send variable to clients[/i][/color]
[color="#191970"][b]publicVariable[/b][/color] [color="#7A7A7A"]"spot1"[/color][color="#8B3E2F"][b];[/b][/color]
[color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#006400"][i]// global code in new thread[/i][/color]
[color="#8B3E2F"][b][[/b][/color][color="#8B3E2F"][b]][/b][/color] [color="#191970"][b]spawn[/b][/color] [color="#8B3E2F"][b]{[/b][/color]
[color="#006400"][i]// wait for variable to exist[/i][/color]
[color="#191970"][b]waitUntil[/b][/color] [color="#8B3E2F"][b]{[/b][/color] [color="#8B3E2F"][b]![/b][/color][color="#191970"][b]isNil[/b][/color] [color="#8B3E2F"][b]{[/b][/color]spot1[color="#8B3E2F"][b]}[/b][/color] [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#006400"][i]// add actions[/i][/color]
[color="#1874CD"]_off[/color] [color="#8B3E2F"][b]=[/b][/color] spot1 [color="#191970"][b]addAction[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#7A7A7A"]"Turn Off"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color]
	[color="#006400"][i]// setHit on light owner via BIS_fnc_MP[/i][/color]
	[color="#1874CD"]_h1[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#8B3E2F"][b][[/b][/color]spot1[color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b][[/b][/color][color="#7A7A7A"]"Light_1_hitpoint"[/color][color="#8B3E2F"][b],[/b][/color][color="#FF0000"]1[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b],[/b][/color][color="#7A7A7A"]"setHit"[/color][color="#8B3E2F"][b],[/b][/color]spot1[color="#8B3E2F"][b],[/b][/color][color="#000000"]false[/color][color="#8B3E2F"][b],[/b][/color][color="#000000"]false[/color][color="#8B3E2F"][b]][/b][/color] [color="#191970"][b]call[/b][/color] BIS_fnc_MP[color="#8B3E2F"][b];[/b][/color]
	[color="#1874CD"]_h2[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#8B3E2F"][b][[/b][/color]spot1[color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b][[/b][/color][color="#7A7A7A"]"Light_2_hitpoint"[/color][color="#8B3E2F"][b],[/b][/color][color="#FF0000"]1[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b],[/b][/color][color="#7A7A7A"]"setHit"[/color][color="#8B3E2F"][b],[/b][/color]spot1[color="#8B3E2F"][b],[/b][/color][color="#000000"]false[/color][color="#8B3E2F"][b],[/b][/color][color="#000000"]false[/color][color="#8B3E2F"][b]][/b][/color] [color="#191970"][b]call[/b][/color] BIS_fnc_MP[color="#8B3E2F"][b];[/b][/color]
[color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#1874CD"]_on[/color] [color="#8B3E2F"][b]=[/b][/color] spot1 [color="#191970"][b]addAction[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#7A7A7A"]"Turn On"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color]
	[color="#1874CD"]_h1[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#8B3E2F"][b][[/b][/color]spot1[color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b][[/b][/color][color="#7A7A7A"]"Light_1_hitpoint"[/color][color="#8B3E2F"][b],[/b][/color][color="#FF0000"]0[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b],[/b][/color][color="#7A7A7A"]"setHit"[/color][color="#8B3E2F"][b],[/b][/color]spot1[color="#8B3E2F"][b],[/b][/color][color="#000000"]false[/color][color="#8B3E2F"][b],[/b][/color][color="#000000"]false[/color][color="#8B3E2F"][b]][/b][/color] [color="#191970"][b]call[/b][/color] BIS_fnc_MP[color="#8B3E2F"][b];[/b][/color]
	[color="#1874CD"]_h2[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#8B3E2F"][b][[/b][/color]spot1[color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b][[/b][/color][color="#7A7A7A"]"Light_2_hitpoint"[/color][color="#8B3E2F"][b],[/b][/color][color="#FF0000"]0[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b],[/b][/color][color="#7A7A7A"]"setHit"[/color][color="#8B3E2F"][b],[/b][/color]spot1[color="#8B3E2F"][b],[/b][/color][color="#000000"]false[/color][color="#8B3E2F"][b],[/b][/color][color="#000000"]false[/color][color="#8B3E2F"][b]][/b][/color] [color="#191970"][b]call[/b][/color] BIS_fnc_MP[color="#8B3E2F"][b];[/b][/color]
[color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color][/color]

Made with KK's SQF to BBCode Converter

Welcome to multiplayer scripting... its complicated.

Share this post


Link to post
Share on other sites
Well, there are a few problems here. The main ones being that the spot1 variable only exists on the server and setHit is an argument local command.

I was actually thinking the same on the "spot" variable, but didn't think of the locality of setHit, good catch.

Share this post


Link to post
Share on other sites
Well, there are a few problems here. The main ones being that the spot1 variable only exists on the server and setHit is an argument local command. The first problem can be fixed by using publicVariable on spot1 to broadcast it to everyone. Then we use a waitUntil and isNil to hold clients until they receive that variable. However, since we are using a waitUntil, we have to move the code to a different scheduled thread than what the init.sqf runs in (you shouldn't stop the init.sqf). Finally, we add the addActions but this time using BIS_fnc_MP and its CfgRemoteExecCommands functionality to run the setHits in the code blocks.

All in all, it will look like this. I haven't tested it, though...

[color="#FF8040"][color="#006400"][i]// server only code[/i][/color]
[color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#191970"][b]isServer[/b][/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]then[/b][/color] [color="#8B3E2F"][b]{[/b][/color]
[color="#006400"][i]// why are you using this marker?[/i][/color]
[color="#191970"][b]createMarker[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#7A7A7A"]"spot1mkr"[/color][color="#8B3E2F"][b],[/b][/color][color="#FF0000"]6469.65[/color][color="#8B3E2F"][b],[/b][/color][color="#FF0000"]5311.91[/color][color="#8B3E2F"][b],[/b][/color][color="#FF0000"]14.7677[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color]
spot1 [color="#8B3E2F"][b]=[/b][/color] [color="#191970"][b]createVehicle[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#7A7A7A"]"Land_PortableLight_double_F"[/color][color="#8B3E2F"][b],[/b][/color][color="#191970"][b]getMarkerPos[/b][/color] [color="#7A7A7A"]"spot1mkr"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b][[/b][/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b],[/b][/color][color="#FF0000"]0[/color][color="#8B3E2F"][b],[/b][/color][color="#7A7A7A"]"none"[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color]
spot1 [color="#191970"][b]setDir[/b][/color] [color="#FF0000"]90[/color][color="#8B3E2F"][b];[/b][/color]
[color="#006400"][i]// send variable to clients[/i][/color]
[color="#191970"][b]publicVariable[/b][/color] [color="#7A7A7A"]"spot1"[/color][color="#8B3E2F"][b];[/b][/color]
[color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#006400"][i]// global code in new thread[/i][/color]
[color="#8B3E2F"][b][[/b][/color][color="#8B3E2F"][b]][/b][/color] [color="#191970"][b]spawn[/b][/color] [color="#8B3E2F"][b]{[/b][/color]
[color="#006400"][i]// wait for variable to exist[/i][/color]
[color="#191970"][b]waitUntil[/b][/color] [color="#8B3E2F"][b]{[/b][/color] [color="#8B3E2F"][b]![/b][/color][color="#191970"][b]isNil[/b][/color] [color="#8B3E2F"][b]{[/b][/color]spot1[color="#8B3E2F"][b]}[/b][/color] [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#006400"][i]// add actions[/i][/color]
[color="#1874CD"]_off[/color] [color="#8B3E2F"][b]=[/b][/color] spot1 [color="#191970"][b]addAction[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#7A7A7A"]"Turn Off"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color]
	[color="#006400"][i]// setHit on light owner via BIS_fnc_MP[/i][/color]
	[color="#1874CD"]_h1[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#8B3E2F"][b][[/b][/color]spot1[color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b][[/b][/color][color="#7A7A7A"]"Light_1_hitpoint"[/color][color="#8B3E2F"][b],[/b][/color][color="#FF0000"]1[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b],[/b][/color][color="#7A7A7A"]"setHit"[/color][color="#8B3E2F"][b],[/b][/color]spot1[color="#8B3E2F"][b],[/b][/color][color="#000000"]false[/color][color="#8B3E2F"][b],[/b][/color][color="#000000"]false[/color][color="#8B3E2F"][b]][/b][/color] [color="#191970"][b]call[/b][/color] BIS_fnc_MP[color="#8B3E2F"][b];[/b][/color]
	[color="#1874CD"]_h2[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#8B3E2F"][b][[/b][/color]spot1[color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b][[/b][/color][color="#7A7A7A"]"Light_2_hitpoint"[/color][color="#8B3E2F"][b],[/b][/color][color="#FF0000"]1[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b],[/b][/color][color="#7A7A7A"]"setHit"[/color][color="#8B3E2F"][b],[/b][/color]spot1[color="#8B3E2F"][b],[/b][/color][color="#000000"]false[/color][color="#8B3E2F"][b],[/b][/color][color="#000000"]false[/color][color="#8B3E2F"][b]][/b][/color] [color="#191970"][b]call[/b][/color] BIS_fnc_MP[color="#8B3E2F"][b];[/b][/color]
[color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#1874CD"]_on[/color] [color="#8B3E2F"][b]=[/b][/color] spot1 [color="#191970"][b]addAction[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#7A7A7A"]"Turn On"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color]
	[color="#1874CD"]_h1[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#8B3E2F"][b][[/b][/color]spot1[color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b][[/b][/color][color="#7A7A7A"]"Light_1_hitpoint"[/color][color="#8B3E2F"][b],[/b][/color][color="#FF0000"]0[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b],[/b][/color][color="#7A7A7A"]"setHit"[/color][color="#8B3E2F"][b],[/b][/color]spot1[color="#8B3E2F"][b],[/b][/color][color="#000000"]false[/color][color="#8B3E2F"][b],[/b][/color][color="#000000"]false[/color][color="#8B3E2F"][b]][/b][/color] [color="#191970"][b]call[/b][/color] BIS_fnc_MP[color="#8B3E2F"][b];[/b][/color]
	[color="#1874CD"]_h2[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#8B3E2F"][b][[/b][/color]spot1[color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b][[/b][/color][color="#7A7A7A"]"Light_2_hitpoint"[/color][color="#8B3E2F"][b],[/b][/color][color="#FF0000"]0[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b],[/b][/color][color="#7A7A7A"]"setHit"[/color][color="#8B3E2F"][b],[/b][/color]spot1[color="#8B3E2F"][b],[/b][/color][color="#000000"]false[/color][color="#8B3E2F"][b],[/b][/color][color="#000000"]false[/color][color="#8B3E2F"][b]][/b][/color] [color="#191970"][b]call[/b][/color] BIS_fnc_MP[color="#8B3E2F"][b];[/b][/color]
[color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color][/color]

Made with KK's SQF to BBCode Converter

Welcome to multiplayer scripting... its complicated.

Wow. Complicated you got that right. Thanks for answering. So every time I want to add an action to a vehicle I'll have to do all that? wow.

I was using the createMarker command because at first I created the light in the editor w/ a trigger...not in a .sqf file. So when i put the code in the init.sqf I thought i would need a marker. but I see that I could probably just put the position in the createVehicle command. But it's nice to be able to move items using markers anyway I guess.

OK. So a few ?s so I can start to learn to fish on my own:

1) When I ran my init.sqf and had a player join they saw the light and it was facing the correct direction. but it just didn't have the addaction. that's the only problem i had with the script. Is the publicVariable really needed since it was somehow in the other client?

2) "global code in new thread" After reading about the spawn command I think you are using the [] spawn to execute what comes next....which first is to wait until the JIP client has the spot1 object then execute all the code inside the {}..which is a lot. I read the link about sched and non-sched or w/out sched but only understand partially. I'm guessing we just want to make sure the client has the object before we run the other commands locally. But confirm all this goes in my init.sqf file?

3) I read about the BIS_fnc_MP. Where I get lost is what is the purpose of "_off", "_on" and the "_h1" and "_h2"? Are they just helpers for the coder to see what the lines are about?

Here is how i understand the syntax you've written:

params: I think this means we are passing two items to the setHit command... spot1 and ["Light_1_hitpoint",1] so when BIS_fnc_MP runs it gets this: spot1 setHit ["Light_1_hitpoint",1]

functionName: setHit

target: spot1 I think I understand this.

isPersistent: false shouldn't this be true since we want to according to wiki: "(will be called now and for every JIP client)"

isCall: false I have a lot more to understand about the above two items.

Thanks.

BTW: I just tested the script. I have two machines here and it works great.

Edited by Pwrmx24

Share this post


Link to post
Share on other sites

I'll try to answer your questions the best I can.

I asked about using the marker because you could put the cords right into the createVehicle command, like you said. It just seemed redundant... but you could be using the marker elsewhere... that's why I left it. As for spawning this with a trigger... can you not just place this in the editor? I swear I have seen it. Also, moving the marker will not move the light... they are not tied together, in case you thought that.

1. The reason you didn't have the addAction working in your original attempt was because the spot1 variable didn't exist anywhere else but the server. The if-isServer statement makes sure its only spawned once, but also make it so the only place the variable is defined is on the server. Variables like this are different from the name you give an object in the editor. If you had placed the object there and named it spot1, then you wouldn't have that problem. The use of publicVariable here broadcasts the variable to all of the clients (& JIP). This ensures that spot1 references the light everywhere, consistently.

2. I used the spawn command here to open a new "thread". This allows the init.sqf to continue running past the code block while the waitUntil has the script held. execVM works much the same way but with script files, not code. The waitUntil command is really for people who are in the server when the mission starts. The publicVariable is synced to a JIP clients before the init.sqf is ran - so we don't have to worry about it there. However, when the mission starts, clients in the game already will skip the if-isServer part and go straight to the the "global code" section. Since we can't tell exactly when the server will have spot1 defined and broadcasted, we have to waitUntil it is ready. This code is designed for the init.sqf so make sure you run it there.

3. I use local variables (underscored words) there simply as a place to store the returned data from those commands. A return is what a command or function sends back after its runs. Not all commands have that. If you look at the wiki page for a command, it will tell you what it returns. AddAction returns the action index number. According to the wiki, BIS_fnc_MP returns an array, or "data packet". I don't know exactly what that is, but it might be the return from the command or function you are using. Without the "_off", "_on", "_h1", and "_h2", that returned data will just be floating there unassigned to a variable. Depending on the code, or scope you are running a code in, that might cause problems. Its always a good idea to assign returned data like that to a variable, just to be safe.

params: You are correct.

functionName: you are correct.

target: I'm using the object spot1 here as a place to send the code. BIS_fnc_MP accepts a bunch of different values here. Using an object means it runs the code where that object is local - who owns it - the server in this case.

isPersistent: No, false is correct. We don't need to send the info to JIP players. setHit is an argument:local/effect:global command. That means the code has to be ran on the machine where the object is local. However, the effects are global and send to the clients by the engine.

isCall: This just means whether we should use spawn or call when running the functionName. We aren't using a function here but a CfgRemoteExecCommand so this probably doesn't apply. However, if you notice the light taking a little while to change when the action is hit, change it to true. False means its spawned... The code is added to the engine's code scheduler and ran when possible. Calling it means it will be bumped to the front and ran immediately.

I hope this answers your questions... good luck.

Edited by Fight9

Share this post


Link to post
Share on other sites
So every time I want to add an action to a vehicle I'll have to do all that?

No. Fight9 just gave you an example of how you could solve your issue. But for using addAction in multiplayer, all you basically need is

[{player addAction ["Action Name", {/* what should be done */}];}, "BIS_fnc_call", true, true, true] call BIS_fnc_MP;

If you want to addAction to another object than the player, the object must be addressable on the respective client.

Is the publicVariable really needed since it was somehow in the other client?

Yes. Usually publicVariable is only needed for variables, not objects. If an object should be created only on one machine, use createVehicleLocal. Otherwise with createVehicle, the created object will allways be global. But in this case, the publicVariable is needed so the created object (spot1) can be addressed in the addAction command. Adapting the code above, it could be like this:

[{spot1 addAction ["Turn on", {/* what should be done */}];}, "BIS_fnc_call", true, true, true] call BIS_fnc_MP;

Share this post


Link to post
Share on other sites
[{player addAction ["Action Name", {/* what should be done */}];}, "BIS_fnc_call", true, true, true] call BIS_fnc_MP;

You are better off passing addAction directly through BIS_fnc_MP.

[[player,["Action Name", {/* what should be done */}]],"addAction",true,true,false] call BIS_fnc_MP;

There is no reason for that extra function' date=' BIS_fnc_call. That would only come in handy if you were using a command not supported in the CfgRemoteExecCommands.

@Pwrmx24

This all comes down on how you are adding the action. The above code would be used if you need the action for everyone but calling the code from one machine. Running code from the init.sqf or the init field of an object in-editor would not require this - since that is ran for everyone.

Multiplayer scripting all comes down to knowing where your code is running and how the commands used are ran. If you have a global command, you can run it locally without adding anything. But if you have local command (like addAction) that you need to run globally, then you need to do some extra work like running it through BIS_fnc_MP.

Share this post


Link to post
Share on other sites
You are better off passing addAction directly through BIS_fnc_MP.

[[player,["Action Name", {/* what should be done */}]],"addAction",true,true,false] call BIS_fnc_MP;

There is no reason for that extra function, BIS_fnc_call. That would only come in handy if you were using a command not supported in the CfgRemoteExecCommands.

Nitpicky, but correct. ;) I didn't think about that, thanks for pointing it out. But the "isPersistent" was intentional as the question implies this to be executed for JIP players as well.

Edited by Heeeere's Johnny!

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×