ok.
1st things:-place a game logic anywhere on your map and name it
server .
This will be used later to determine if a script is running on a server ar a client, because game logics are server-side only.
- fill in
[] exec "checkplayersleft.sqs" in any units command line. But only do it for 1 unit. This will start the script "checkplayersleft.sqs"
- Make a trigger, set type to
lose and fill in the condition-line:
activatelosetrigger The lose-trigger will be activated when the variable "activatelosetrigger" is set to "true".
Then some scripting:-Add this to your init.sqs (do it with notepad), just before the "exit" command line.If you got no "init.sqs"-file by now, look down, I explained there how to make a new "blabla.sqs"-file
; First check if machine is server or just a client
? !(local server): goto "thisnoserver"
; If machine is server, set variables to their defaults and broadcast their values to all clients
playersleft = 0;PublicVariable "playersleft"
activatelosetrigger = false;publicVariable "activatelosetrigger"
; Continue init.sqs here if machine is just a client
#thisnoserverIf you made a new init.sqs, and only then, add the following line:
execIn the other case (you already have a init.sqs), there would be this line already and you should place the code just above this line.
-Then make a new textfile in the folder of your mission and rename it "checkplayersleft.sqs" (be sure you enabled view of all file types or you will get a "checkplayersleft.sqs.txt"-file)
Open the file with notepad and fill in:
; If machine is the server, just exit
? (local server): exit
; Give the player time to spawn (be sure that server set variables and player spawned)
~ 20
; If player (the unit he/she has chosen) is still alive after the first 20 seconds, add 1 to playersleft and broadcast new value to all
? (alive player): playersleft = playersleft +1; publicVariable "playersleft"
; Now check every 10 seconds if player is still alive. If not, go to playerdead
#checkloop
~10
? !(alive player): goto "playerdead"
goto "checkloop"
#playerdead
; Player is dead. Substract 1 from playersleft and broadcast the new value to all.
playersleft = playersleft -1; publicVariable "playersleft"
; Check if 0 players left. If so, set variable activatelosetrigger to true and broadcast the new value to all.
? (playersleft == 0): activatelosetrigger = true; publicVariable "activatelosetrigger"
; Then exit the script on this machine
exit
This should do if the game runs on a dedicated server. It will not run correctly if the server is a player. (The player who is server will not be counted at playersleft)
It will not run, if all players die within the first 20 seconds. If this case is important to you, you can add the following to the init.sqs, below the other code just above the #thisnoserver line. It will set the condition for the lose trigger to true if no players have been added to playersleft after 40 seconds (that means if all players died before they could have been added to playersleft):
~40
? (playersleft == 0): activatelosetrigger = trueI hope it works, because I have no dedicated server to test and I am new to scripting as I mentioned. Someone should review this.
(There is one thing I am not sure of by now: Will the script run on every client if activated by any (1) unit? Or does it need to be activated from every playable units init-line? I could imagine this, though it is not likely)
cu slowworm