Home   Help Search Login Register  

Author Topic: Confused about local and global  (Read 1485 times)

0 Members and 1 Guest are viewing this topic.

JPSelter

  • Guest
Confused about local and global
« on: 12 Sep 2005, 12:58:46 »
I have 2 important scripts in my init.sqs

a) respawning with default BW-Mod weapons
b) showing a short camera ride from the killed player to the killer

It works for a single player, but not for a multiplayer session. Here is my init.sqs

Code: [Select]
tx_weapons = weapons player
tx_ammo = magazines player
tx_primary = primaryweapon player
player addEventHandler ["killed", {_this exec "respawn.sqs"}]
player addEventHandler ["killed", {_this exec "deadplayer.sqs"}]

I had a) working with multiplayer when I added P1,P2,P3 and P4 (thatÂ's how I named the other 4 playable soldiers) for each line:

Code: [Select]
tx_weapons = weapons Player
tx_weapons1 = weapons P1
tx_weapons2 = weapons P2
tx_weapons3 = weapons P3
tx_weapons4 = weapons P4
tx_ammo = magazines Player
tx_ammo1 = magazines P1
tx_ammo2 = magazines P2
tx_ammo3 = magazines P3
tx_ammo4 = magazines P4
tx_primary = primaryweapon Player
tx_primary1 = primaryweapon P1
tx_primary2 = primaryweapon P2
tx_primary3 = primaryweapon P3
tx_primary4 = primaryweapon P4
Player addEventHandler ["killed", {_this exec "respawn.sqs"}]
P1 addEventHandler ["killed", {_this exec "respawn1.sqs"}]
P2 addEventHandler ["killed", {_this exec "respawn2.sqs"}]
P3 addEventHandler ["killed", {_this exec "respawn3.sqs"}]
P4 addEventHandler ["killed", {_this exec "respawn4.sqs"}]

But when I did this with b) I saw the camera ride when one of my soldiers was killed:

Code: [Select]
Player addEventHandler ["killed", {_this exec "deadplayer.sqs"}]
P1 addEventHandler ["killed", {_this exec "deadplayer1.sqs"}]
P2 addEventHandler ["killed", {_this exec "deadplayer2.sqs"}]
P3 addEventHandler ["killed", {_this exec "deadplayer3.sqs"}]
P4 addEventHandler ["killed", {_this exec "deadplayer4.sqs"}]

What do I have to change so that every playable soldier has their respawn script and only the player (everyone in mp) has their own death-camera?

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
Re:Confused about local and global
« Reply #1 on: 12 Sep 2005, 18:24:39 »
If a unit is local to your machine, and each unit in your group is, if you are there squad leader

then you will see the code that they run

so you can do one of 2 things

either use

?(Player == P1):.......

that will only run if the unit is P1

or ?!(Player == P1):
the code following, the anbove line will only run if unit P1 is not a player


Ref your script
Player addeventhandler......
and P1 addeventhandler

will run 2 eventhandler scripts, if P1 is a player
because
you attached one killed eventhandler to P1 as unit p1
and you attached another eventhandler to the player


hope that helps


As a brief rule

All groups made entirely of AI are local to the server

All units in a vehicle are local to the player in that vehicle (I think)
All units in a players group, where the player is a group leader are local to the player
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123

Kyle Sarnik

  • Guest
Re:Confused about local and global
« Reply #2 on: 12 Sep 2005, 20:57:10 »
 :P Such a messy respawn script, your making alot of extra work for yourself by using global variables and eventhandlers. Here, try this:

init.sqs
Code: [Select]
player exec "respawn.sqs"
player addeventhandler ["killed",{_this exec "deadplayer.sqs"}]
exit

respawn.sqs
Code: [Select]
_unit = _this

@! (alive _unit)
~0.5
? _unit != player : exit
_weapons = weapons _unit
_magazines = magazines _unit
_primary = primaryweapon _unit
#Alive
? !(alive player) : goto "Alive"
removeallweapons player
{player addmagazine _X} foreach _magazines
{player addweapon _X} foreach _weapons
{player selectweapon _primary
player exec "respawn.sqs"
exit

That should solve all of your problems, because in multiplayer, you have the wonderful option of executing certian scripts independently on each person's machine, so that way you don't need seperate scripts or variables for each player, because in the init.sqs, you can use the variable player to activate a script on all of the players completly independently. So now, only the active players will be given the killed eventhandler and you won't have to worry about seeing other people's cutscenes, because everyone has their own EH that is running on their own machine independent of yours and everyone elses.

JPSelter

  • Guest
Re:Confused about local and global
« Reply #3 on: 14 Sep 2005, 09:31:50 »
Thanks a lot! That cleared up things :) I knew I had a messy script but didnÂ't how to solve this. The main problem I had was that I gave id-names to each playable soldier. ThatÂ's why your script didnÂ't worked in the first place, after I cleared the ids it did :)