Home   Help Search Login Register  

Author Topic: Last question, I promise. :)  (Read 1216 times)

0 Members and 1 Guest are viewing this topic.

polvy

  • Guest
Last question, I promise. :)
« on: 22 Nov 2003, 23:30:15 »

OK,

WHAT IS GOING ON:
My mission has most of the "playable" units in seperate groups and mixed with AI in each of those seperate groups. Also, the mission is best played with any "playable" units left on, in case there are not enough people to fill all the "playable" the slots.

WHAT I NEED TO KNOW:
How do I set an end trigger that only triggers when all the HUMAN players are dead?

:)

~Polvy

slowworm

  • Guest
Re:Last question, I promise. :)
« Reply #1 on: 23 Nov 2003, 15:30:58 »
First a script that runs server side only that sets variables (or add to init.sqs if you have one)
playersleft = 0;PublicVariable "playersleft"
activatelosetrigger = false;publicVariable "activatelosetrigger"

then a script that runs on every client that first adds 1 to playersleft (don't forget to make it public) and then checks every 10 secons (or like this) if he is alive, if not substracts 1 from playersleft (public). Then it checks if playersleft == 0 and if so sets activatelosetrigger = true (public)

activatelosetrigger is the condition for the lose-trigger


I think that should work, but I did not try it and I am new to scripting. I made a ready script, but it did forget to copy the text and all was lost because I was not logged in.. arhh.
But if you dont know how to make a script like this, ask me and I will type it again.


cu slowworm
« Last Edit: 23 Nov 2003, 15:36:49 by slowworm »

polvy

  • Guest
Re:Last question, I promise. :)
« Reply #2 on: 23 Nov 2003, 22:24:00 »
Appreciate the reply Slowworm. The first part that goes in the init is simple enough but I'm afraid I can't quite grasp the second part. Where would this go? Would you mind giving an example?

Thanks,
~Polvy  :D

slowworm

  • Guest
Re:Last question, I promise. :)
« Reply #3 on: 25 Nov 2003, 14:00:35 »
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
#thisnoserver



If you made a new init.sqs, and only then, add the following line:

exec

In 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 = true



I 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
« Last Edit: 25 Nov 2003, 16:26:23 by slowworm »

polvy

  • Guest
Re:Last question, I promise. :)
« Reply #4 on: 25 Nov 2003, 14:57:50 »
Thanks Slowworm. I'll give it a shot and let you know.

~Polvy