Home   Help Search Login Register  

Author Topic: Essential Multiplayer Information  (Read 2052 times)

0 Members and 1 Guest are viewing this topic.

Offline Callaghan

  • Members
  • *
Essential Multiplayer Information
« on: 08 Mar 2008, 19:04:11 »
I have searched hi and low for this simple yet essential information and I cannot find it anywhere.
Coops are easy to make, I churn them out no problem.
Team Deathmatches and sector controls on the other hand I have no idea how to do and really can't find anything on the subject.
Pretend i'm an absolute beginner.
What scripts do I need to make, where do I call them from and generally what, where, how and why.
All I need is enough information to make a team deathmatch template, that tallies up the scores and declares victories after a 100 point limit.
Any and all help will be appreciated, thanks in advance.

Offline Rommel92

  • Members
  • *
Re: Essential Multiplayer Information
« Reply #1 on: 10 Mar 2008, 07:11:36 »
Best bet would be to open up another persons map and look at that, but in any case.

Gathering your doing a typical team deathmatch.

Setup two respawn points, (respawn_west - respawn_east) just as you would in a Coop.
And then two playable sides, the rest are just bonus features.  :good:

Offline Callaghan

  • Members
  • *
Re: Essential Multiplayer Information
« Reply #2 on: 10 Mar 2008, 13:50:10 »
Thanks but that I already know, the things I need to get my head around include
public variables - how do they work and how do I use them?
Score systems - is there a template available anywhere or what are the scripts I need to tally scores for both sides, say who has won, and display the team scores on screen?
How do I make events from the game add to the scores i.e. +1 to wscore each time an opfor player is killed or vice versa, taking into account teamkills and falling etc.

Offline Loyalguard

  • Former Staff
  • ****
Re: Essential Multiplayer Information
« Reply #3 on: 12 Mar 2008, 10:19:33 »
Callaghan-

Here is a quick summary of public variables.  First, if you haven't already review these in entries in the Comref:

publicVariable

addPublicVariableEventHandler

A public variable is just a global variable that has been broadcast to all clients (individual player machines) and the server.  Here is an example. Player A does something that earns his team "points".  Code will run on his machine that adds the point to the score (recorded in a public variable):

Code: [Select]
teamScoreW = teamScoreW + 10; // Add 10 points to the west team's score.
Now, to make sure the server and all clients know that the team's score has been increased (right now, only Player A's computer knows) you use the publicVariable command to broadcast it.  So, we add the a new line of code:

Code: [Select]
teamScoreW = teamScoreW + 10; // Add 10 points to the west team's score.
publicVariable "teamScoreW"; // Broadcast the score to all clients and the server.

Now, teamScoreW will be the same on all clients and the server.  If similar code runs on all the west team's computers whenever they score points then the score will be updated on everyone's machines as changes occur. 

Since the 1.09 beta, we have a new command that helps us react to when publicVariables change: addPublicVariableEventHandler.  Say we want to display a hint every time the score changes.  We can use this command to do this for us.

Code: [Select]
"teamScoreW" addPublicVariableEventHandler {hint format ["West Score: %1", (_this select 1)]}; // Display a hint clients that did not broadcast a new public variable value.
Just remember, addPublicVariableEventHandler does not work in 1.08 and earlier.  Also note that this code will NOT display a hint on the client that broadcasted the public variable, only those clients that did not change it.  So, if you want to display a hint on Player A's client as well we have to add a new line to the code where we broadcast the public variable:

Code: [Select]
teamScoreW = teamScoreW + 10; // Add 10 points to the west team's score.
publicVariable "teamScoreW"; // Broadcast the score to all clients and the server.
hint format ["West Score: %1", teamScoreW]; // Display a hint on this client only with the new score.

I don't know of any scoring templates because scoring needs can vary from mission maker to mission maker.  Here is a post I made in another thread that describes one way: Re: Support-script [help]

Lastly, there are various ways of changing scores.  For the scenario you described:

Quote
+1 to wscore each time an opfor player is killed or vice versa, taking into account teamkills and falling etc.

You could use a "Killed" event handler.  A killed event handler will record two values whenever a unit has been added one. The unit assigned the event handler (i.e. that is killed) and the object that killed it (the killer).  These are recorded in the magic variable _this:

_this select 0: Unit assigned the event handler
_this select 1: object that killed it

Here is how we can use it to fulfill your scenario above:

Add this code to the unit's init line in the editor:

this addEventHandler ["killed", {_this execVM "scoring.sqf";}];

This code will add a killed event handler to that unit and whenever that unit dies it will execute scoring.sqf and pass to it the magic variable _this (which contains the information of who was killed and who killed it).

Then, create a script called scoring.sqf:

Code: [Select]
private ["_killed", "_killer"]; // Introduce local variables to the innermost scope.

_killed = _this select 0; // Record the  the killed unit in a local variable.
_killer = _this select 1; // Record the killer in a local variable.

If ((side _killed) == (side _killer)) exitWith {hint "Team Kill or Accident - No Points}; // If the the unit that was killed and the unit that killed it are on the same side then exit the script without adding points.

teamScore = teamScore + 1; // If this was a legitimate kill then add one point to the other team.

// Add publicVariable code here if applicable.

The above script receives the notification of whom was killed (_this select 0) and the killer (_this select 1) and records them for local use.  Then if the killed and killer are on the same side or the killed unit killed himself (fall, collision, etc.) then the script exits without adding points (If a unit kills itself then it will be the killed and the killer and obviously on the same side).  If someone from another side killed the unit then the points are added.  If you want to broadcast the new value insert publicVariable where I noted in comments.

I have not tested any of the above code so excuse any typos or syntax errors but this should be enough to get you started.  Good luck!

Offline Callaghan

  • Members
  • *
Re: Essential Multiplayer Information
« Reply #4 on: 26 Mar 2008, 17:49:36 »
thanks for the detailed post!
Il try and get my head round it lol, then apply it.
Will be back with more no doubt.
Callaghan

Offline Callaghan

  • Members
  • *
Re: Essential Multiplayer Information
« Reply #5 on: 27 Mar 2008, 11:01:22 »
OK few more MP(ish) questions. If you can answer 1 or more i'd appreciate it..

1. a) How do I move a marker, in this case a respawn point, around as objectives change.
    b) This links in to the next question, can an obj be 'failed' when a trigger is deactivated and 'done' when its active (the trigger is on activated repeatedly), an extra trigger ends the game when objectives 1,2 and 3 are all 'true'. I'd like the spawn point to be at obj1 at the start, obj2 when obj1 is done, and moved back to obj1 if it is recaptured by the enemy.

2. What is the format for an addaction that calls a script with several parameters.
I'm trying to make a suicide bomb script but the IED script I have doesnt seem to work, does it not recognise 'men' as objects?
Code: [Select]
bomber1 addaction ["Detonate","IED.sqs",["bomber1","Huge"]]this kills the man but no bomb is spawned.

3. How do I add separate objectives for East and West?

4. How do I make sounds come from a source when a certain event occurs.
In this case i'd like a 'distant artillery' sound to play at the location of an artillery gun when it fires, it needs to be the same volume over a couple of kilometers distance, the original sound of the gun will override it when you are close as it will be louder.

5. Is there a way to create a waypoint for a player, in a different group, onMapclick?
i.e. a forward observer can give waypoints to a CAS unit.

Thanks in advance.

Offline Loyalguard

  • Former Staff
  • ****
Re: Essential Multiplayer Information
« Reply #6 on: 27 Mar 2008, 14:03:15 »
1a. To move a marker use the setMarkerPos command triggered by the change in objective status.

1b. You should be able to, just change the On Act and On Dea trigger fields accordingly.  I have not tested it but something like this:

On Act.:  "1" objStatus "DONE"
On Dea: "1" objStatus "ACTIVE"

You may find it useful to track the status of objectives by using variables to store their status.  See this page of the Beginner's tutorial on how.

2. If you need to pass several arguments for use as parameters in a script executed by an addAction command you will most likely have to store them within an array and include that array in the addAction:

Code: [Select]
_argArray = ["bomber1","Huge"];
bomber1 addaction ["Detonate","IED.sqs", _argArray];

Then in IED.sqf the parameter (the entire array) will be available as _this select 3. You will then need to retrieve the individual elements you need for your your script from within:

Code: [Select]
// IED.sqf

_paramArray = _this select 3;

_bomber = _paramArray select 0;
_expType = _paramArray select 1;

// Remainder of code here...

class Man is "recognizable" as an object via most/all commands but I am unfamiliar with the exact script so I am unable to diagnosis further.

All this is untested of course.

3. You probably need to link a trigger via the activation property or to a specific side so that it only units from that side can activate it an change the pertinent objective status.

4. I have used the say command to do this in the past.  Place a game logic at the location of where you want the sound to originate from and then use the say command on it.  You will most likely have to do a lot of experimentation to make the volume of the sound of the guns to your satisfaction in your sound editor and in the Description.ext.

5. I am very weak on waypoints so I will leave it for someone else...sorry.
« Last Edit: 27 Mar 2008, 15:03:57 by Loyalguard »

Offline Callaghan

  • Members
  • *
Re: Essential Multiplayer Information
« Reply #7 on: 27 Mar 2008, 14:53:49 »
thanks for the advice I shall try it once i am home
onMapclick waypoints anyone?
« Last Edit: 28 Mar 2008, 11:47:43 by Callaghan »