klakins 10 Posted May 21, 2020 First I want to say that I'm very new to scripting. The missions I have made in the past have been very light on scripting. I'm making a mission that will randomly generate a mission for you. All the scripts work when playing the mission in MP, hosting the mission on my own machine. The scripts also work fine on a dedicated server when I execVM them in the on activation field of a editor placed trigger, such as Radio Alpha. The problem I'm running into is, I would like to release this mission to the public, so I'm trying to put anti griefing measures in place, by only giving the first player slot the ability to generate the mission. I accomplished this by using the following code. Init.sqf if(player == p1) then {settings addAction ["Enemies: Low", "low.sqf",[],1,false,true,"","_this distance _target < 5"]; settings addAction ["Enemies: Medium", "medium.sqf",[],1,false,true,"","_this distance _target < 5"]; settings addAction ["Enemies: High", "high.sqf",[],1,false,true,"","_this distance _target < 5"]; settings addAction ["Enemies: Extreme", "extreme.sqf",[],1,false,true,"","_this distance _target < 5"]; settings addAction ["Generate Mission", "gennorm.sqf",[],1,false,true,"","_this distance _target < 5"]; settings addAction ["Generate Mission Big Cities Only", "genbco.sqf",[],1,false,true,"","_this distance _target < 5"]; }; For example selecting Generate Mission would run. gennorm.sqf removeAllActions insert; removeAllActions settings; insert addAction ["Insertion 1", "I1.sqf",[],1,false,true,"","_this distance _target < 5"]; insert addAction ["Insertion 2", "I2.sqf",[],1,false,true,"","_this distance _target < 5"]; insert addAction ["Insertion 3", "I3.sqf",[],1,false,true,"","_this distance _target < 5"]; insert addAction ["Insertion 4", "I4.sqf",[],1,false,true,"","_this distance _target < 5"]; typ = "Type: Normal Generation"; if(isServer) then { { if (alive _x && side _x == EAST) then { deleteVehicle _x; }; } forEach allUnits; sleep 2; { if (alive _x && side _x == EAST) then { deleteVehicle _x; }; } forEach allUnits; execVM "start.sqf"; }; sleep 14; if(player == p1) then { settings addAction ["Enemies: Low", "low.sqf",[],1,false,true,"","_this distance _target < 5"]; settings addAction ["Enemies: Medium", "medium.sqf",[],1,false,true,"","_this distance _target < 5"]; settings addAction ["Enemies: High", "high.sqf",[],1,false,true,"","_this distance _target < 5"]; settings addAction ["Enemies: Extreme", "extreme.sqf",[],1,false,true,"","_this distance _target < 5"]; settings addAction ["Generate Mission", "gennorm.sqf",[],1,false,true,"","_this distance _target < 5"]; settings addAction ["Generate Mission Big Cities Only", "genbco.sqf",[],1,false,true,"","_this distance _target < 5"]; }; Which would then run start.sqf if(isServer) then {_mkr = ["m1","m2","m3","m4","m5","m6","m7","m8","m9","m11","m12","m13","m14","m15","m16","m17","m18","m19","m20","m21","m22","m23","m24","m25","m26","m27","m28","m29","m30","m31","m32","m33","m34","m35","m36"] call BIS_fnc_selectRandom; _obj = markerpos _mkr; "A" setMarkerPos _obj; o1 setPos markerpos _mkr; s1 setPos (getPos o1 vectorAdd [0,600,0]); s2 setPos (getPos o1 vectorAdd [600,0,0]); s3 setPos (getPos o1 vectorAdd [-600,0,0]); s4 setPos (getPos o1 vectorAdd [0,-600,0]); "I1" setMarkerPos s1; "I2" setMarkerPos s2; "I3" setMarkerPos s3; "I4" setMarkerPos s4; comp setPos (getPos o1); end setPos (getPos o1); g1 = [getPos o1, east, ["CUP_O_INS_Officer", "CUP_O_INS_Soldier_AR", "CUP_O_INS_Soldier_AK74", "CUP_O_INS_Soldier"],[],[],[],[],[],180] call BIS_fnc_spawnGroup; sleep 2; null = [leader g1,"A","random","min:",mn,"max:",mx,"noai"] execVM "ups.sqf"; }; [player, "task1", ["Clear the area of all enemies", "Clear The Area", "Marker: Area"], (markerPos "A"), true] call BIS_fnc_taskCreate; I also tried removing the if(player == p1) then from the addActions and got the same results. The variables that these scripts define update on the persons machine that ran these scripts, but not the other machines, and obviously not the server, because the mission isn't generated. I know this, because I have a radio trigger set up to display the variables I'm using for testing. Again I want to reiterate that the scripts run fine when I have an editor placed trigger, with on activation being execVM "gennorm.sqf", and they also run fine when I host a local server. I'm obviously missing something that is causing these scripts to only be run on the client that execs them. I would appreciate any help on this. Share this post Link to post Share on other sites
pierremgi 4890 Posted May 21, 2020 What is settings ? as mandatory object to pass an addaction on it? And what is insert? and comp? and end? player is not defined on dedicated but the init.sqf runs also at each joining player, so your addAction should be visible if settings is an edited object. Now, when you trigger it, the code is local to the player. If you try to run something for server only (like your start.sqf) that can't work as is. You need to remoteExec the code on server. If your not familiar with that, I suggest you to read some interesting pages: https://community.bistudio.com/wiki/Multiplayer_Scripting https://community.bistudio.com/wiki/remoteExec https://community.bistudio.com/wiki/Initialization_Order https://community.bistudio.com/wiki/Code_Optimisation Try also better naming in your variables. comp and end, for example, should be not objects (as they seem to be). Share this post Link to post Share on other sites
opusfmspol 282 Posted May 21, 2020 It likely works when you use the radio triggers because the triggers exist on all machines, and when you broadcast radio Alpha the server and clients all ExecVM the gennorm.sqf. But from addAction (local to client) the server does not run anything due to the locality which @pierremgi points out. Your "if (isServer)" scopes get bypassed entirely, the scripts are only running on clients. Share this post Link to post Share on other sites
klakins 10 Posted May 21, 2020 Thanks for the tips. I will be reading those links, and cleaning up the code. I now have this in my init.sqf if(player == p1) then { settings addAction ["Enemies: Low", ["low.sqf"] remoteExec ["execVM"],[],1,false,true,"","_this distance _target < 5"]; settings addAction ["Enemies: Medium", ["medium.sqf"] remoteExec ["execVM"],[],1,false,true,"","_this distance _target < 5"]; settings addAction ["Enemies: High", ["high.sqf"] remoteExec ["execVM"],[],1,false,true,"","_this distance _target < 5"]; settings addAction ["Enemies: Extreme", ["extreme.sqf"] remoteExec ["execVM"],[],1,false,true,"","_this distance _target < 5"]; settings addAction ["Generate Mission", ["gennorm.sqf"] remoteExec ["execVM"],[],1,false,true,"","_this distance _target < 5"]; settings addAction ["Generate Mission Big Cities Only", ["genbco.sqf"] remoteExec ["execVM"],[],1,false,true,"","_this distance _target < 5"]; }; The script now works on a dedicated server, but now as soon as p1 loads into the game missions get spam generated all over the map. What did I do wrong? And to answer your questions settings and insert are both editor placed object. I understand your point about the names, and will be changing them after I get this figured out. comp and end are both triggers. Share this post Link to post Share on other sites
klakins 10 Posted May 21, 2020 Alright, I got it working using this workaround if(player == p1) then { settings addAction ["Enemies: Low", "l.sqf",[],1,false,true,"","_this distance _target < 5"]; settings addAction ["Enemies: Medium", "m.sqf",[],1,false,true,"","_this distance _target < 5"]; settings addAction ["Enemies: High", "h.sqf",[],1,false,true,"","_this distance _target < 5"]; settings addAction ["Enemies: Extreme", "e.sqf",[],1,false,true,"","_this distance _target < 5"]; settings addAction ["Generate Mission", "g.sqf",[],1,false,true,"","_this distance _target < 5"]; settings addAction ["Generate Mission Big Cities Only", "gb.sqf",[],1,false,true,"","_this distance _target < 5"]; }; Then for example in g.sqf ["gennorm.sqf"] remoteExec ["execVM"]; I'm assuming this isn't the most efficient way to do this, so any further help would be appreciated. Share this post Link to post Share on other sites
opusfmspol 282 Posted May 23, 2020 On 5/21/2020 at 4:33 PM, klakins said: I'm assuming this isn't the most efficient way to do this, so any further help would be appreciated. Maybe try this: (not tested, so might need some adjusting - I note there are undefined references, so perhaps there are more to these than was posted) // initPlayerLocal.sqf: Spoiler if (Local p1) then { settings addAction ["Enemies: Low", "low.sqf",[],1,false,true,"","_this distance _target < 5"]; settings addAction ["Enemies: Medium", "medium.sqf",[],1,false,true,"","_this distance _target < 5"]; settings addAction ["Enemies: High", "high.sqf",[],1,false,true,"","_this distance _target < 5"]; settings addAction ["Enemies: Extreme", "extreme.sqf",[],1,false,true,"","_this distance _target < 5"]; settings addAction ["Generate Mission", "gennorm.sqf",[],1,false,true,"","_this distance _target < 5"]; settings addAction ["Generate Mission Big Cities Only", "genbco.sqf",[],1,false,true,"","_this distance _target < 5"]; }; // gennorm.sqf et Al. (run only by Client p1) Spoiler removeAllActions insert; removeAllActions settings; insert addAction ["Insertion 1", "I1.sqf",[],1,false,true,"","_this distance _target < 5"]; insert addAction ["Insertion 2", "I2.sqf",[],1,false,true,"","_this distance _target < 5"]; insert addAction ["Insertion 3", "I3.sqf",[],1,false,true,"","_this distance _target < 5"]; insert addAction ["Insertion 4", "I4.sqf",[],1,false,true,"","_this distance _target < 5"]; typ = "Type: Normal Generation"; "start.sqf" RemoteExec ["execVM",2]; sleep 14; settings addAction ["Enemies: Low", "low.sqf",[],1,false,true,"","_this distance _target < 5"]; settings addAction ["Enemies: Medium", "medium.sqf",[],1,false,true,"","_this distance _target < 5"]; settings addAction ["Enemies: High", "high.sqf",[],1,false,true,"","_this distance _target < 5"]; settings addAction ["Enemies: Extreme", "extreme.sqf",[],1,false,true,"","_this distance _target < 5"]; settings addAction ["Generate Mission", "gennorm.sqf",[],1,false,true,"","_this distance _target < 5"]; settings addAction ["Generate Mission Big Cities Only", "genbco.sqf",[],1,false,true,"","_this distance _target < 5"]; // start.sqf (run only by server, whether hosted or dedicated): Spoiler {if (alive _x && side _x == EAST) then {deleteVehicle _x;};} forEach allUnits; sleep 2; {if (alive _x && side _x == EAST) then {deleteVehicle _x;};} forEach allUnits; // ?? "m10" is missing? _mkr = ["m1","m2","m3","m4","m5","m6","m7","m8","m9", "m11","m12","m13","m14","m15","m16","m17","m18","m19","m20", "m21","m22","m23","m24","m25","m26","m27","m28","m29","m30", "m31","m32","m33","m34","m35","m36" ] call BIS_fnc_selectRandom; _obj = markerpos _mkr; "A" setMarkerPos _obj; o1 setPos markerpos _mkr; s1 setPos ((getPos o1) vectorAdd [0,600,0]); s2 setPos ((getPos o1) vectorAdd [600,0,0]); s3 setPos ((getPos o1) vectorAdd [-600,0,0]); s4 setPos ((getPos o1) vectorAdd [0,-600,0]); "I1" setMarkerPos s1; "I2" setMarkerPos s2; "I3" setMarkerPos s3; "I4" setMarkerPos s4; comp setPos (getPos o1); end setPos (getPos o1); g1 = [getPos o1, east, ["CUP_O_INS_Officer", "CUP_O_INS_Soldier_AR", "CUP_O_INS_Soldier_AK74", "CUP_O_INS_Soldier"],[],[],[],[],[],180] call BIS_fnc_spawnGroup; null = [leader g1,"A","random","min:",mn,"max:",mx,"noai"] execVM "ups.sqf"; [West,"task1",["Clear the area of all enemies","Clear The Area","Marker: Area"],(markerPos "A"),true] remoteExecCall ["BIS_fnc_taskCreate",([0,-2] select isDedicated)]; 1 Share this post Link to post Share on other sites
klakins 10 Posted May 25, 2020 On 5/23/2020 at 2:03 PM, opusfmspol said: Maybe try this: (not tested, so might need some adjusting - I note there are undefined references, so perhaps there are more to these than was posted) // initPlayerLocal.sqf: Hide contents if (Local p1) then { settings addAction ["Enemies: Low", "low.sqf",[],1,false,true,"","_this distance _target < 5"]; settings addAction ["Enemies: Medium", "medium.sqf",[],1,false,true,"","_this distance _target < 5"]; settings addAction ["Enemies: High", "high.sqf",[],1,false,true,"","_this distance _target < 5"]; settings addAction ["Enemies: Extreme", "extreme.sqf",[],1,false,true,"","_this distance _target < 5"]; settings addAction ["Generate Mission", "gennorm.sqf",[],1,false,true,"","_this distance _target < 5"]; settings addAction ["Generate Mission Big Cities Only", "genbco.sqf",[],1,false,true,"","_this distance _target < 5"]; }; // gennorm.sqf et Al. (run only by Client p1) Hide contents removeAllActions insert; removeAllActions settings; insert addAction ["Insertion 1", "I1.sqf",[],1,false,true,"","_this distance _target < 5"]; insert addAction ["Insertion 2", "I2.sqf",[],1,false,true,"","_this distance _target < 5"]; insert addAction ["Insertion 3", "I3.sqf",[],1,false,true,"","_this distance _target < 5"]; insert addAction ["Insertion 4", "I4.sqf",[],1,false,true,"","_this distance _target < 5"]; typ = "Type: Normal Generation"; "start.sqf" RemoteExec ["execVM",2]; sleep 14; settings addAction ["Enemies: Low", "low.sqf",[],1,false,true,"","_this distance _target < 5"]; settings addAction ["Enemies: Medium", "medium.sqf",[],1,false,true,"","_this distance _target < 5"]; settings addAction ["Enemies: High", "high.sqf",[],1,false,true,"","_this distance _target < 5"]; settings addAction ["Enemies: Extreme", "extreme.sqf",[],1,false,true,"","_this distance _target < 5"]; settings addAction ["Generate Mission", "gennorm.sqf",[],1,false,true,"","_this distance _target < 5"]; settings addAction ["Generate Mission Big Cities Only", "genbco.sqf",[],1,false,true,"","_this distance _target < 5"]; // start.sqf (run only by server, whether hosted or dedicated): Hide contents {if (alive _x && side _x == EAST) then {deleteVehicle _x;};} forEach allUnits; sleep 2; {if (alive _x && side _x == EAST) then {deleteVehicle _x;};} forEach allUnits; // ?? "m10" is missing? _mkr = ["m1","m2","m3","m4","m5","m6","m7","m8","m9", "m11","m12","m13","m14","m15","m16","m17","m18","m19","m20", "m21","m22","m23","m24","m25","m26","m27","m28","m29","m30", "m31","m32","m33","m34","m35","m36" ] call BIS_fnc_selectRandom; _obj = markerpos _mkr; "A" setMarkerPos _obj; o1 setPos markerpos _mkr; s1 setPos ((getPos o1) vectorAdd [0,600,0]); s2 setPos ((getPos o1) vectorAdd [600,0,0]); s3 setPos ((getPos o1) vectorAdd [-600,0,0]); s4 setPos ((getPos o1) vectorAdd [0,-600,0]); "I1" setMarkerPos s1; "I2" setMarkerPos s2; "I3" setMarkerPos s3; "I4" setMarkerPos s4; comp setPos (getPos o1); end setPos (getPos o1); g1 = [getPos o1, east, ["CUP_O_INS_Officer", "CUP_O_INS_Soldier_AR", "CUP_O_INS_Soldier_AK74", "CUP_O_INS_Soldier"],[],[],[],[],[],180] call BIS_fnc_spawnGroup; null = [leader g1,"A","random","min:",mn,"max:",mx,"noai"] execVM "ups.sqf"; [West,"task1",["Clear the area of all enemies","Clear The Area","Marker: Area"],(markerPos "A"),true] remoteExecCall ["BIS_fnc_taskCreate",([0,-2] select isDedicated)]; That looks like a great way to do that. Thank you. Also, thanks for noticing the missing marker. One change that I will need to make to what you provided is, put the addActions for insert in another script, and remote exec those for all clients, because all players need to be able to see those. Thanks again. Share this post Link to post Share on other sites
opusfmspol 282 Posted May 25, 2020 Moving to a separate script would be proper since remoteExec the addactions doesn't return the handles for storing and removing them later. Share this post Link to post Share on other sites