Home   Help Search Login Register  

Author Topic: team deathmatch scoring  (Read 4834 times)

0 Members and 2 Guests are viewing this topic.

Offline trinec

  • Members
  • *
  • I'm a llama!
team deathmatch scoring
« on: 15 Sep 2005, 20:30:28 »
I have read the tutorial on creating a deathmatch but im kinda stuck on the scoring when it comes to a team deathmatch so that when each player makes a kill it scores for the team east vs west.  Also I need a way to show which individual person got the most points during the round as well as the whole teams score.

Thanks

Trinec

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
Re:team deathmatch scoring
« Reply #1 on: 17 Sep 2005, 17:05:09 »
you will need to research using killed event handlers and how to publicvariable

basically you add a killed eventhandler to each unit.

When a unit is killed, the event handler will return 2 values

Who was killed and by who

You can then check the side of the killer and add a score to their side

you could also add an individual score to the name of the killer

and then during your closing outro, you can display this in titletext messages or a hint message

Probably hint message due to the amount of units you would be displaying info for


something like the following

MISSION EDITOR
for the argument of this example, create 3 west and 3 east units
name then W1,W2,W3,E1,E2 and E3


INIT.sqs
Quote
;; following variables are for side scoring
tx_Wkills = 0
tx_Ekills = 0
;; following variables are for individual unit scoring
tx_W1score
tx_W2score
tx_W3score
tx_E1score
tx_E2score
tx_E3score
;; following is a killed eventhandler, this runs the playerkilled.sqs when the unit is killed (much more efficient than a series of triggers
tx_kill = player addEventHandler ["killed", {_this exec "playerkilled.sqs"}]

Playerkilled.sqs
Quote
_victim = _this select 0
_killer = _this select 1
_side = side _killer
player removeEventhandler ["Killed",tx_kill]
if(side _victim == _side)then{hint "teamkill occurred";exit}
goto (format ["%1",_side])

#EAST
if (name _killer == name E1)then {tx_E1score = tx_E1score + 1;tx_Ekills = tx_Ekills + 1; {Publicvariable _x}foreach ["tx_E1score","tx_Ekills"]}
if (name _killer == name E2)then {tx_E2score = tx_E2score + 1;tx_Ekills = tx_Ekills + 1; {Publicvariable _x}foreach ["tx_E2score","tx_Ekills"]}
if (name _killer == name E3)then {tx_E3score = tx_E3score + 1;tx_Ekills = tx_Ekills + 1; {Publicvariable _x}foreach ["tx_E3score","tx_Ekills"]}
goto "END"

#WEST
if (name _killer == name W1)then {tx_W1score = tx_W1score + 1;tx_Wkills = tx_Wkills + 1; {Publicvariable _x}foreach ["tx_W1score","tx_Wkills"]}
if (name _killer == name W2)then {tx_W2score = tx_W2score + 1;tx_Wkills = tx_Wkills + 1; {Publicvariable _x}foreach ["tx_W2score","tx_Wkills"]}
if (name _killer == name W3)then {tx_W3score = tx_W3score + 1;tx_Wkills = tx_Wkills + 1; {Publicvariable _x}foreach ["tx_W3score","tx_Wkills"]}
goto "END"

#END
;;; if respawn then add the following
@alive player
tx_kill = player addEventHandler ["killed", {_this exec "playerkilled.sqs"}]
exit

your outro script would then contain the following code
Quote
_message = ""
if(tx_Wkills > tx_Ekills}then{_message = "WEST WINS"}else{_message = "EAST WINS"}
if(tx_Wkills == tx_Ekills)then{_message = "Its A Draw"}
hint formaT [ "___ FINAL OUTCOME ___\n\n%1",_message]
~10
;; following are for the individual scoring screenprint
_w1 = format ["\n%1 had %2 kills",name W1, tx_W1score]
_w2 = format ["\n%1 had %2 kills",name W2, tx_W2score]
_w3 = format ["\n%1 had %2 kills",name W3, tx_W3score]
_E1 = format ["\n%1 had %2 kills",name E1, tx_E1score]
_E2 = format ["\n%1 had %2 kills",name E2, tx_E2score]
_E3 = format ["\n%1 had %2 kills",name E3, tx_E3score]

hint formaT [ "___ INDIVIDUAL SCORES ___\n%1%2%3%4%5%6",_w1,_w2,_w3,_E1,_E2,_E3]


the above system will add a point to the side of the _killer for each death, providing it isnt a teamkill and then add a score to the killer unit's personal score

NB>> I think the only way to maintain a check on who the _killer is for a respawning unit is to refer to it by name _unit, this is the reason for the lines
if(name_killer == name W1)then{....... etc


The above system can be made much more efficient and requiring much less lines of code by using the format command and nested arrays, however, i tried to keep it very simple to allow you to follow its logic without ctreating something which you would find unreadable and therefore not be able to adapt it more to your requirements

No doubt somebody will still do that and confuse you more, just watch for the additional posts :)

« Last Edit: 18 Sep 2005, 21:27:23 by Terox »
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123

Offline trinec

  • Members
  • *
  • I'm a llama!
Re:team deathmatch scoring
« Reply #2 on: 17 Sep 2005, 20:50:40 »
Im trying the  scripts that you gave me which i really appreciate ive come across a problem when i get killed.  It was giving me this  error removeeventhandler type number expected array  from this line  Player removeEventhandler tx_kill  does it need to be changed to this player removeEventhandler ["tx_kill",0].  Which I tried and it still gives an error on this line  _side = _side _killer error unknown operator _killer  ive only tested this with me getting killed as the player and ai doing the killing so not sure if thats where the problem is or not

trinec

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
Re:team deathmatch scoring
« Reply #3 on: 18 Sep 2005, 12:12:24 »
oops sorry two stupid syntax

player removeEventhandler tx_kill
should be
player removeEventhandler ["Killed",tx_kill]

and

_side = _side _killer
should be
_side = side _killer
« Last Edit: 18 Sep 2005, 12:13:01 by Terox »
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123

Offline trinec

  • Members
  • *
  • I'm a llama!
Re:team deathmatch scoring
« Reply #4 on: 18 Sep 2005, 19:11:29 »
Well that fixed those errors but now i have another one


goto _side     error goto type side expected String

thanks

trinec

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
Re:team deathmatch scoring
« Reply #5 on: 18 Sep 2005, 21:26:55 »
sorry another silly syntax.....replace the line
goto _side
with
goto (format ["%1",_side])
« Last Edit: 18 Sep 2005, 23:59:04 by Terox »
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123

Offline trinec

  • Members
  • *
  • I'm a llama!
Re:team deathmatch scoring
« Reply #6 on: 24 Sep 2005, 21:27:44 »
looks like the scripts are working is their a way to have a music file play for the team that wins  I already have the music files setup in the description.ext.  I am trying to get it to play a certain music file when west side wins it plays a music file and when the east side wins it plays a different music file.  I guess maybe it should call a script when either side wins so that it has the camera spin around the team that wins and plays a music file.
« Last Edit: 24 Sep 2005, 21:37:25 by trinec »

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
Re:team deathmatch scoring
« Reply #7 on: 25 Sep 2005, 11:47:26 »
musicname needs to be pre defined in the description.ext, as you know.

Lets name this musuc classes as

Wwins
Ewins
Draw

have your end/outro script run the following code

OUTRO
Quote
_Winner = 0
;;;_winner = 1 (for a west win)...=2 (for an east win)..=0 (for a draw)
_message = ""
if(tx_Wkills > tx_Ekills}then{_message = "WEST WINS";_winner = 1}else{_message = "EAST WINS";_winner = 2}
if(tx_Wkills == tx_Ekills)then{_message = "Its A Draw";_winner = 0}
hint formaT [ "___ FINAL OUTCOME ___\n\n%1",_message]
if(_winner==0)then{playmusic "Draw"}else{if(_winner==1)then{playmusic "WWins"}}else{if(_winner==2)then{playmusic "EWins"}}
~10
;; following are for the individual scoring screenprint
_w1 = format ["\n%1 had %2 kills",name W1, tx_W1score]
_w2 = format ["\n%1 had %2 kills",name W2, tx_W2score]
_w3 = format ["\n%1 had %2 kills",name W3, tx_W3score]
_E1 = format ["\n%1 had %2 kills",name E1, tx_E1score]
_E2 = format ["\n%1 had %2 kills",name E2, tx_E2score]
_E3 = format ["\n%1 had %2 kills",name E3, tx_E3score]

hint formaT [ "___ INDIVIDUAL SCORES ___\n%1%2%3%4%5%6",_w1,_w2,_w3,_E1,_E2,_E3]
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123

Offline trinec

  • Members
  • *
  • I'm a llama!
Re:team deathmatch scoring
« Reply #8 on: 25 Sep 2005, 20:26:28 »
Thanks alot Terox you have been a great help do you know if I can mix the outro with camera scripts?  For example the west wins the camera spins around the west flag and plays the WWins music.  can the camera stuff be in the same script like under #WWins for west etc. or do i need to call another script I prob can do the camera stuff but im just not sure on how to call it.

One other thing I just thought of is it seems these scripts would work with respawning units but would that work with the outro script because it would never get called if the game never ended I guess the tdm  was setup to only last so long then that would fix that part but to call the Outro when the time limit was over with Im not sure on..

ok ive tested the scoring side and I get this when it displays the score scaler bool array string 0xfcfffffff   kills

also on this line

if(_winner==0)then{playmusic "Draw"}else{if(_winner==1)then{playmusic "WWins"}}else{if(_winner==2)then{playmusic "EWins"}}

it gives me an error message from else but i cant read the whole message
« Last Edit: 26 Sep 2005, 02:46:17 by trinec »

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
Re:team deathmatch scoring
« Reply #9 on: 26 Sep 2005, 11:42:42 »
Simple Answer = YES

MP outro's arent the same thing as an SP outro, all they are is a scripted cutscene

Basically you change the camera target, start and end positions

lets make it very simple, then you can expand on it as much as you want

You could do
Quote
?(_winner == 0):goto "DRAW"
?(_winner == 1):goto "WWins"
?(_winner == 2):goto "EWins"

#DRAW
;; do your camera stuff & screenprint your messages etc
exit

#WWins
;; do your camera stuff & screenprint your messages etc
exit

#EWins
;; do your camera stuff & screenprint your messages etc
exit

or if you dont want to repeat your code and goto "labels"
You can define the camera positions like this

Quote
?(_winner == 0):_camstart = (getpos objectnameA);_target = objectnameB;_camend = (getpos objectnameC)
?(_winner == 1):_camstart = (getpos objectnameD);_target = objectnameE;_camend = (getpos objectnameF)
?(_winner == 2):_camstart = (getpos objectnameG);_target = objectnameH;_camend = (getpos objectnameI)

and then run your camera cutscene like this

_camera = "camera" camCreate _camstart
_camera camSetTarget _target
_camera camSetRelPos [1,1,1.25]
_camera camCommit 0
@camCommitted _camera
etc etc etc

« Last Edit: 26 Sep 2005, 11:50:49 by Terox »
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123

Offline trinec

  • Members
  • *
  • I'm a llama!
Re:team deathmatch scoring
« Reply #10 on: 28 Sep 2005, 01:49:46 »
Didnt know if you had seen the last part of my message i had added it latter so maybe not

ok ive tested the scoring side and I get this when it displays the score scaler bool array string 0xfcfffffff  kills

also on this line

if(_winner==0)then{playmusic "Draw"}else{if(_winner==1)then{playmusic "WWins"}}else{if(_winner==2)then{playmusic "EWins"}}

it gives me an error message from else but i cant read the whole message

next part below if  _Winner = 0 at the start then doesnt that automaticly set it to a draw


_Winner = 0
;;;_winner = 1 (for a west win)...=2 (for an east win)..=0 (for a draw)
_message = ""
if(tx_Wkills > tx_Ekills}then{_message = "WEST WINS";_winner = 1}else{_message = "EAST WINS";_winner = 2}
if(tx_Wkills == tx_Ekills)then{_message = "Its A Draw";_winner = 0}
hint formaT [ "___ FINAL OUTCOME ___\n\n%1",_message]
if(_winner==0)then{playmusic "Draw"}else{if(_winner==1)then{playmusic "WWins"}}else{if(_winner==2)then{playmusic "EWins"}}

Offline Fragorl

  • Coding Team
  • Former Staff
  • ****
Re:team deathmatch scoring
« Reply #11 on: 28 Sep 2005, 09:50:42 »
Take this code, then delete all the spaces so it fits on one line:
Code: [Select]
if(_winner==0)then{
     playmusic "Draw";
}else{
     if(_winner==1)then{
          playmusic "WWins";
     }else{
          if(_winner==2)then{
               playmusic "EWins";
          };
     };
};
The indentation is just there so that anyone can easily check if the code is correct - in fact I recommend that anyone writing function-type code, which they intend to fit on one line in a sqs script file, writes it like this first and then puts it onto one line.

OFP script is stupid in that it doesnt have any such thing as 'else if', only 'if' and 'else', and OFP reads Terox's code as
"if () then {} else {} else{}"
, which doesnt make sense. If you want to simulate "else if's" then you have to nest the if statement inside the else one.
« Last Edit: 28 Sep 2005, 10:01:51 by Fragorl »

Offline trinec

  • Members
  • *
  • I'm a llama!
Re:team deathmatch scoring
« Reply #12 on: 30 Sep 2005, 04:02:09 »
fraqori thanks for the help that fixed the music not playing my biggest problem is the individual scoring when it shows the hint box when the time runs out for the game and list the individual scores it shows the player names but states

trinec had scalar bool array string 0xfcfffffff  kills

which is from this line  
 _w1 = format ["\n%1 had %2 kills",name W1, tx_W1score]


this is from the playerkilled script im not sure if this is right or not?

#WEST
if (name _killer == name W1)then {tx_W1score = tx_W1score + 1;tx_Wkills = tx_Wkills + 1; {Publicvariable _x}foreach ["tx_W1score","tx_Wkills"]}

if (name _killer == name W2)then {tx_W2score = tx_W2score + 1;tx_Wkills = tx_Wkills + 1; {Publicvariable _x}foreach ["tx_W2score","tx_Wkills"]}
goto "END"
« Last Edit: 30 Sep 2005, 06:08:41 by trinec »

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
Re:team deathmatch scoring
« Reply #13 on: 30 Sep 2005, 12:02:17 »
First thing, make sure you have declared all your score variables as

variablename = 0 in

 the init.sqs

next thing, is a quick tutorial on how to debug a script.

All a script does is
1) Have inputs
2) process the inputs
3) Create  outputs

Very basically this means
1) Variables in
2) Do something with them
3) Variable output


So to figure out why something isnt working as expected, we have some great tools

Hint or Titletext
Side/group/vehiclechat
and
Format

Together these are simply used to display a text message on screen.

The text message can either be a simple string

eg
hint "DEBUG: Killed event script, at Label LOOP"
Which
you would place just after the #LOOP line
This tells you that your script, when ran got at least this far

If you wanted to monitor a lot of labels in a fast looping script, you could use
Player groupchat "DEBUG: At label 1"
Player sidechat "DEBUG: At label 2"
Player vehiclechat "DEBUG: At label 3"

this then allows you to scroll up the messages in the chat window at leisure and each label can clearly be distinguished by the different coloured chat text


FORMAT
Probably the most powerful command you will need to know for debugging purposes

Lets take your killed event script.

In particular, the tx_W1score

It should be declared in the init.sqs as having a value of 0

so to check, we place the the following line at the end of the Init.sqs

hint format ["Variable tx_W1score has value\n %1",tx_W1score]

if the Output is 0, you know the problem doesnt lie here

so you go to the next script that uses it and once again you place the same line in the script and wait to see the output


another approach, is taking a "Copy" of the value of "tx_W1score" before and after it is processed

eg

in a script that states

tx_W1score = tx_W1score + 1

you would do the following

_a = tx_W1score
tx_W1score = tx_W1score + 1
_b = tx_W1score
hint format ["Variable _a = %1\n\n Variable _b = %2",_a,_b]



do the same for the variables

name _killer etc etc etc


Using the above methods will then allow you to define where your problem lies and exactly what the problem is


Maybe a tutorial should be submitted to the editors depot, called "Debugging Tutorial"


Try using the above debugging system, then if you are still unable to resolve the problem, get back to us
« Last Edit: 30 Sep 2005, 12:07:01 by Terox »
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123

Offline trinec

  • Members
  • *
  • I'm a llama!
Re:team deathmatch scoring
« Reply #14 on: 01 Oct 2005, 04:22:34 »
Sorry Terox I didnt realize you gave me a broken init.sqs were some of the variables were not defined which is from your first post so now it works thanks for the debug info.


Init.sqs

;; following variables are for side scoring
tx_Wkills = 0
tx_Ekills = 0
;; following variables are for individual unit scoring
tx_W1score
tx_W2score
tx_W3score
tx_E1score
tx_E2score
tx_E3score

;; following is a killed eventhandler, this runs the playerkilled.sqs when the unit is killed (much more efficient than a series of triggers
tx_kill = player addEventHandler ["killed", {_this exec "playerkilled.sqs"}]


trinec