cerberusjin 10 Posted September 14, 2014 I set up a sectrol control. Named the sector "sctr_A". everything works fine except the server side script. Problem: At the start of the game the ticket won't change it's value even if i put any number. After capturing the sector, the script should increment team score but it's not working. Can someone please explain to me why my script is not working? And if not too much, help me solve the problem/correct the script. init.sqf gameOver = false; if (isServer) then { [west,0] call BIS_fnc_respawnTickets; [east,0] call BIS_fnc_respawnTickets; _handle = [] spawn { while {!gameOver} do { if ((sctr_A getVariable "owner") == west) then { west addScoreSide 1; } else { if ((sctr_A getVariable "owner") == east) then { east addScoreSide 1; }; }; sleep 1; }; }; }; Share this post Link to post Share on other sites
jshock 513 Posted September 14, 2014 Try it without the if (isServer) check or start the script like this: if (!isServer) exitWith{}; gameOver = false; [west,0] call BIS_fnc_respawnTickets; [east,0] call BIS_fnc_respawnTickets; _handle = [] spawn { while {!gameOver} do { if ((sctr_A getVariable "owner") == west) then { west addScoreSide 1; } else { if ((sctr_A getVariable "owner") == east) then { east addScoreSide 1; }; }; sleep 1; }; }; Share this post Link to post Share on other sites
cerberusjin 10 Posted September 15, 2014 @JShock still doesnt work. complete script inside init.sqf waitUntil {(!isNull player && time > 0)}; //==============LOADOUT //-----WEST [west, "WEST1"] call BIS_fnc_addRespawnInventory; [west, "WEST2"] call BIS_fnc_addRespawnInventory; [west, "WEST3"] call BIS_fnc_addRespawnInventory; [west, "WEST4"] call BIS_fnc_addRespawnInventory; [west, "WEST5"] call BIS_fnc_addRespawnInventory; [west, "WEST6"] call BIS_fnc_addRespawnInventory; //-----EAST [east, "EAST1"] call BIS_fnc_addRespawnInventory; [east, "EAST2"] call BIS_fnc_addRespawnInventory; [east, "EAST3"] call BIS_fnc_addRespawnInventory; [east, "EAST4"] call BIS_fnc_addRespawnInventory; [east, "EAST5"] call BIS_fnc_addRespawnInventory; [east, "EAST6"] call BIS_fnc_addRespawnInventory; //==============Declaration of Variables //[east, west] PointsNeeded = 100; Pointsperkill = 20; gameOver = false; if (!isDedicated) then { //west addScoreSide ((scoreSide west)*-1); //east addScoreSide ((scoreSide east)*-1); while {!gameOver} do { //=======Score Display SCORE_01_Load = {((_this select 0) displayCtrl 1001) ctrlSetText format ["%1", scoreSide west]}; 1 cutRsc ["score_test","PLAIN"]; SCORE_02_Load = {((_this select 0) displayCtrl 1002) ctrlSetText format ["%1", scoreSide east]}; 2 cutRsc ["score_test2","PLAIN"]; sleep 0.125; //Has one of the teams reached score limit if ((scoreSide west) >= PointsNeeded) then { gameOver = true; publicVariable "gameOver"; //Send end mission to clients - based on if they won or lost [["SideLost",false,5],"BIS_fnc_endMission", east, false] call BIS_fnc_MP; [["SideWon",true,true],"BIS_fnc_endMission", west, false] call BIS_fnc_MP; }; if ((scoreSide east) >= PointsNeeded) then { gameOver = true; publicVariable "gameOver"; //Send end mission to clients - based on if they won or lost [["SideLost",false,5],"BIS_fnc_endMission", west, false] call BIS_fnc_MP; [["SideWon",true,true],"BIS_fnc_endMission", east, false] call BIS_fnc_MP; }; }; //=====disable respawn for "_i" from 0 to 1e+1000 do { waitUntil {!isNull (findDisplay 49)}; ((findDisplay 49) displayCtrl 1010) ctrlEnable false; }; }; if (!isServer) exitWith{}; [west,1] call BIS_fnc_respawnTickets; [east,1] call BIS_fnc_respawnTickets; _handle = [] spawn { while {!gameOver} do { if ((sctr_A getVariable "owner") == west) then { west addScoreSide 1; } else { if ((sctr_A getVariable "owner") == east) then { east addScoreSide 1; }; }; sleep 1; }; }; Share this post Link to post Share on other sites
iceman77 19 Posted September 15, 2014 (edited) Player variable will never exist on the server. The server will be hung there waiting for a condition that will never be true. Try moving the null check at the top, to after the dedicated check. I'm a bit rusty in any case, and i hope that helps. //==============LOADOUT //-----WEST [west, "WEST1"] call BIS_fnc_addRespawnInventory; [west, "WEST2"] call BIS_fnc_addRespawnInventory; [west, "WEST3"] call BIS_fnc_addRespawnInventory; [west, "WEST4"] call BIS_fnc_addRespawnInventory; [west, "WEST5"] call BIS_fnc_addRespawnInventory; [west, "WEST6"] call BIS_fnc_addRespawnInventory; //-----EAST [east, "EAST1"] call BIS_fnc_addRespawnInventory; [east, "EAST2"] call BIS_fnc_addRespawnInventory; [east, "EAST3"] call BIS_fnc_addRespawnInventory; [east, "EAST4"] call BIS_fnc_addRespawnInventory; [east, "EAST5"] call BIS_fnc_addRespawnInventory; [east, "EAST6"] call BIS_fnc_addRespawnInventory; //==============Declaration of Variables //[east, west] PointsNeeded = 100; Pointsperkill = 20; gameOver = false; //Server gonna hop over this condition and go straight to your server code at the bottom.. instead of getting hung up on the waitUntil that was at the top if (!isDedicated) then { waitUntil {(!isNull player && time > 0)}; //west addScoreSide ((scoreSide west)*-1); //east addScoreSide ((scoreSide east)*-1); while {!gameOver} do { //=======Score Display SCORE_01_Load = {((_this select 0) displayCtrl 1001) ctrlSetText format ["%1", scoreSide west]}; 1 cutRsc ["score_test","PLAIN"]; SCORE_02_Load = {((_this select 0) displayCtrl 1002) ctrlSetText format ["%1", scoreSide east]}; 2 cutRsc ["score_test2","PLAIN"]; sleep 0.125; //Has one of the teams reached score limit if ((scoreSide west) >= PointsNeeded) then { gameOver = true; publicVariable "gameOver"; //Send end mission to clients - based on if they won or lost [["SideLost",false,5],"BIS_fnc_endMission", east, false] call BIS_fnc_MP; [["SideWon",true,true],"BIS_fnc_endMission", west, false] call BIS_fnc_MP; }; if ((scoreSide east) >= PointsNeeded) then { gameOver = true; publicVariable "gameOver"; //Send end mission to clients - based on if they won or lost [["SideLost",false,5],"BIS_fnc_endMission", west, false] call BIS_fnc_MP; [["SideWon",true,true],"BIS_fnc_endMission", east, false] call BIS_fnc_MP; }; }; //=====disable respawn for "_i" from 0 to 1e+1000 do { waitUntil {!isNull (findDisplay 49)}; ((findDisplay 49) displayCtrl 1010) ctrlEnable false; }; }; if (!isServer) exitWith{}; [west,1] call BIS_fnc_respawnTickets; [east,1] call BIS_fnc_respawnTickets; _handle = [] spawn { while {!gameOver} do { if ((sctr_A getVariable "owner") == west) then { west addScoreSide 1; } else { if ((sctr_A getVariable "owner") == east) then { east addScoreSide 1; }; }; sleep 1; }; }; Edited September 15, 2014 by Iceman77 Share this post Link to post Share on other sites
jshock 513 Posted September 15, 2014 (edited) I completely missed this was in the init.sqf, not that that changes much of anything (well may have changed my answer :p), but Iceman's suggestion is your best bet. Makes more sense with the entirety of the code though ;). Edited September 15, 2014 by JShock Share this post Link to post Share on other sites
cerberusjin 10 Posted September 15, 2014 @Iceman77 still doesn't work. Share this post Link to post Share on other sites
jshock 513 Posted September 15, 2014 Try using the Steam startup parameter: -showScriptErrors Then run the mission and see what it throws, may be syntax... Share this post Link to post Share on other sites
Naiss 28 Posted September 15, 2014 maybe try to install Microsoft framework, i had this isue befor but when i installed that it all worked fine (not sure) Share this post Link to post Share on other sites
jshock 513 Posted September 15, 2014 Another question as well...are you taking your mission and testing it on a dedicated machine, not your own computer (through editor preview), because if not then all the code under the isDedicated check won't run because dedicated is false. Share this post Link to post Share on other sites
Larrow 2823 Posted September 15, 2014 Huge Test Mission Share this post Link to post Share on other sites
jshock 513 Posted September 15, 2014 #Larrow to the rescue :681: Share this post Link to post Share on other sites
cerberusjin 10 Posted September 17, 2014 @Larrow Thanks again for the big help! As of now, I'm trying to understand the whole script. if it is fine with you, can you explain to me what i'm doing wrong? why my functions are not working correctly(including the script in my other thread)? basic of using spawn? when to use spawn or call? Sorry if i have so many questions. Share this post Link to post Share on other sites
Larrow 2823 Posted September 18, 2014 There was nothing particularly wrong with your code (other than the pointed out !isNull player) it was more just a question of flow. Your original code minus the isNull //==============LOADOUT //-----WEST [west, "WEST1"] call BIS_fnc_addRespawnInventory; [west, "WEST2"] call BIS_fnc_addRespawnInventory; [west, "WEST3"] call BIS_fnc_addRespawnInventory; [west, "WEST4"] call BIS_fnc_addRespawnInventory; [west, "WEST5"] call BIS_fnc_addRespawnInventory; [west, "WEST6"] call BIS_fnc_addRespawnInventory; //-----EAST [east, "EAST1"] call BIS_fnc_addRespawnInventory; [east, "EAST2"] call BIS_fnc_addRespawnInventory; [east, "EAST3"] call BIS_fnc_addRespawnInventory; [east, "EAST4"] call BIS_fnc_addRespawnInventory; [east, "EAST5"] call BIS_fnc_addRespawnInventory; [east, "EAST6"] call BIS_fnc_addRespawnInventory; //==============Declaration of Variables //[east, west] PointsNeeded = 100; Pointsperkill = 20; gameOver = false; if (!isDedicated) then { //west addScoreSide ((scoreSide west)*-1); //east addScoreSide ((scoreSide east)*-1); while {!gameOver} do { //=======Score Display SCORE_01_Load = {((_this select 0) displayCtrl 1001) ctrlSetText format ["%1", scoreSide west]}; 1 cutRsc ["score_test","PLAIN"]; SCORE_02_Load = {((_this select 0) displayCtrl 1002) ctrlSetText format ["%1", scoreSide east]}; 2 cutRsc ["score_test2","PLAIN"]; sleep 0.125; //Has one of the teams reached score limit if ((scoreSide west) >= PointsNeeded) then { gameOver = true; publicVariable "gameOver"; //Send end mission to clients - based on if they won or lost [["SideLost",false,5],"BIS_fnc_endMission", east, false] call BIS_fnc_MP; [["SideWon",true,true],"BIS_fnc_endMission", west, false] call BIS_fnc_MP; }; if ((scoreSide east) >= PointsNeeded) then { gameOver = true; publicVariable "gameOver"; //Send end mission to clients - based on if they won or lost [["SideLost",false,5],"BIS_fnc_endMission", west, false] call BIS_fnc_MP; [["SideWon",true,true],"BIS_fnc_endMission", east, false] call BIS_fnc_MP; }; }; //=====disable respawn for "_i" from 0 to 1e+1000 do { waitUntil {!isNull (findDisplay 49)}; ((findDisplay 49) displayCtrl 1010) ctrlEnable false; }; }; if (!isServer) exitWith{}; [west,1] call BIS_fnc_respawnTickets; [east,1] call BIS_fnc_respawnTickets; _handle = [] spawn { while {!gameOver} do { if ((sctr_A getVariable "owner") == west) then { west addScoreSide 1; } else { if ((sctr_A getVariable "owner") == east) then { east addScoreSide 1; }; }; sleep 1; }; }; So lets read through this So to start every machine running this adds the loadouts, nothing really bad about this every machine repeats these commands but that just means they get overwritten, would be better placed server side though then they just get added once. We setup the global Variables if (!isDedicated) - So if we are anything other than a dedicated server (we will have a player), Then we enter a loop !gameOver, we then have 2 functions for the UI loading, again not really bad but they really only need to be defined once rather than being stuck in this while loop, and we cutrsc to display the UI's EVERY loop, again better off removed from the loop so they are only displayed once and use some CtrlSetText to update the scores. Then we have a large section that is checking the scores and deciding if anyone has won, remember we are still inside a loop that EVERY client is running. This is really not needed and we would be alot better of moving this section to where onlt the server determines the scores and if someone has won. Then after this while loop there is code to turn off the Respawn option in the menu, this code is never going to run as eveyone is stuck in the loop until gameOver, by which time turning off the respawn menu is not needed. Ok so if we were a dedicated server we would have skipped the last lot of code and found if (!isServer) exitwith - kind of redundant as anything that is not a dedicated server is stuck in the while loop above. So anything from here on out is DEDICATED server only, if your running a Hosted server you will be stuck in the while loop. We add A ticket to each side. and we start a loop that adds a score to who ever owns the sector every second. Spawning a thread here is not bad, just unneeded as there is nothing else afterwards, we could of just made a loop. _______________ My code from the test mission - minus the //temp bits as they were there just as a fix, as currently in the stable build scores do not reset properly between missions. This is basically all your code (other than where i changed how to work out who won/lost). It has just been reordered to make a little more workable. //==============Declaration of Global Variables PointsNeeded = 10; Pointsperkill = 20; gameOver = false; scoresUpdated = false; //Pause till briefing has finished sleep 1; //================== //=== SERVER === //================== if (isServer) then { //==============LOADOUT { //-----WEST [west, format["WEST%1",_x] ] call BIS_fnc_addRespawnInventory; //-----EAST [east, format["EAST%1",_x] ] call BIS_fnc_addRespawnInventory; }forEach [1,2,3,4,5,6]; //===============SCORING _monitorSectorScoring = [] spawn { while {!gameOver} do { //every 10 seconds add 1 to the score of the owning side waitUntil { sctr_A getVariable "owner" != sideUnknown}; (sctr_A getVariable "owner") addScoreSide 1; //Scores have changed - make client display new scores publicVariable "scores"; //If we are a hosted server display scores //a PVEH does not fire on the machine were the PV was called if (!isDedicated) then { [] call fnc_updateScores; }; sleep 10; }; }; //===============GAMEOVER _gameThread = [] spawn { while {!gameOver} do { _sides = [east, west]; _points = [scoreSide east, scoreSide west]; //Has one of the teams reached the score limit if ( { _x >= PointsNeeded }count _points > 0 ) then { //Game is over stop all other threads gameOver = true; publicVariable "gameOver"; //Same as saying _won = _sides select ( _points find ( (_points select 0) max (_points select 1) ) ); //If _sides - the winner, then we can only be left with the loser _lost = (_sides - [_won]) select 0; //Send end mission to clients - based on if they won or lost [["SideLost",false,5],"BIS_fnc_endMission", _lost, false] call BIS_fnc_MP; [["SideWon",true,true],"BIS_fnc_endMission", _won, false] call BIS_fnc_MP; }; }; }; }; //=================== //=== CLIENTS === //=================== if (!isDedicated) then { //Adds 1 respawn per player [player ,1] call BIS_fnc_respawnTickets; [player ,1] call BIS_fnc_respawnTickets; //functions called from UI onLoad for storing references to the displays SCORE_01_Load = { scoreDisplayWest = (_this select 0); }; SCORE_02_Load = { scoreDisplayEast = (_this select 0); }; //function to update score displays fnc_updateScores = { (scoreDisplayWest displayCtrl 1001) ctrlSetText format ["%1", scoreSide west]; (scoreDisplayEast displayCtrl 1002) ctrlSetText format ["%1", scoreSide east]; }; //init score displays 1 cutRsc ["score_test","PLAIN"]; 2 cutRsc ["score_test2","PLAIN"]; [] call fnc_updateScores; //update scores - activated by server when scores change "scores" addPublicVariableEventHandler { [] call fnc_updateScores; }; //=====disable ESC menu respawn option while {!gameOver} do { waitUntil {!isNull (findDisplay 49)}; ((findDisplay 49) displayCtrl 1010) ctrlEnable false; }; }; So we define some global variables. If we are a server (Hosted or Dedicated). We add the respawn inventories - as they are side based inventories adding them from the server will make them available to everyone who joins. We then start a separate thread to monitor the sector that adds a point every 10 seconds. We then start another thread that monitors if someone has won yet and if so tells all clients to end mission dependant on if they won/lost As all loops above were spawned every one reaches the client section. If !isDedicated, so anyone who is a client and has a player. Adds one to the number of tickets available for themselves. Sets up two functions for the UI. Creates a function to update the UI's scores. cutRsc to display the UI's and calls the function to update the displays. Adds a PVEH that the sever will activate when the scores change - that calls the function to refreh the displays Then enters a loop that turns off the respawn menu option and will continue to loop here until gameover ____________________________ When you spawn something you are basically saying here is some code go of and run this while i continue with whats below. If you call something then operation stops there it will go off and do what ever in the call then when that has finished come back and resume where it left off. Well you can most probably see now why i just posted a test mission and didnt want to write out this essay :) As you can hopefully see there is not much difference between my code and yours, its just how it is started using spawn to stop anyone getting caught it loops so each machine gets to run what they are ment to be. Share this post Link to post Share on other sites
cerberusjin 10 Posted September 20, 2014 Thank you so much for dedicating so much time writing that essay to explain that to me. I guess my problem is figuring out which line of code should come first, coz I think that's where I messed up. BTW, I just finished(not really a finished game mode) what I'm trying to do and submitted it at makearmanotwar. Thanks again for the big help. Share this post Link to post Share on other sites
cerberusjin 10 Posted September 23, 2014 Hi! I'm back again. I'm trying to make it work for dedicated server. Just a quick question: All I need is to add (isDedicated) then it's gonna work if run in dedicated server? if ((isServer) or (isDedicated)) then { ... } I can't test it right now because I'm having problem setting up dedicated server(TADST). Share this post Link to post Share on other sites
Larrow 2823 Posted September 23, 2014 All I need is to add (isDedicated) then it's gonna work if run in dedicated server?Mmm all depends where. As explained in the essay you need to work through your logic and work out what needs to be run where and how to get each machine to run what it is meant to be running.isServer and isDedicated are kind of the same thing, as in if it is dedicated then it is also a server, the only difference being is that a server can have a player (is a hosted server) Share this post Link to post Share on other sites
cerberusjin 10 Posted September 23, 2014 Sorry if I didn't made it clear. What I mean is if i'll just add isDedicated at the server part just like the script below. //==============Declaration of Global Variables PointsNeeded = 4000; Pointsperkill = 20; gameOver = false; scoresUpdated = false; //scores are bugged till next release - they dont reset scores = [0, 0]; //Pause till briefing has finished sleep 1; //================== //=== SERVER === //================== if ((isServer) or (isDedicated)) then { //==============LOADOUT { //-----WEST [west, format["WEST%1",_x] ] call BIS_fnc_addRespawnInventory; //-----EAST [east, format["EAST%1",_x] ] call BIS_fnc_addRespawnInventory; }forEach [1,2,3,4,5,6]; .......... Share this post Link to post Share on other sites