Home   Help Search Login Register  

Author Topic: Help me please with publicVariables!  (Read 2429 times)

0 Members and 1 Guest are viewing this topic.

Offline Lone~Wolf

  • Mission Tools & Mods
  • Members
  • *
  • Vladimir Dmitri Mikhail Andreevich Stamenov
Help me please with publicVariables!
« on: 18 May 2010, 23:26:52 »
Greetings OFP lovers,

I have just stumbled across the miracle of publicVariables (don't laugh, I have always found ways around desync in the past) and was looking for help in their use.

The BIS wiki is extremely brief in it's description of what they are and how to use them: So I am appealing for someone experienced in their use to fill me in on the full extent of their applications.

For example, how would I ensure that all computers on a server ran a drop script identically?
Or for that matter how would I synchronise the unlocking of a vehicle across all computers?

Help?  :dunno:

Thanks in advance,
        Lone~Wolf  ;)
Snarling creature, lurking in the background, still writing in .sqs

Offline RKurtzDmitriyev

  • Former Staff
  • ****
Re: Help me please with publicVariables!
« Reply #1 on: 18 May 2010, 23:56:46 »
Quote
So I am appealing for someone experienced in their use to fill me in on the full extent of their applications.

LOL, I've heard so many conflicting opinions on how one ought to build an OFP multiplayer mission that I'm not sure if anyone is experienced in the use of publicvariables or knows the full extent of their applications. :P

Have you read through this tutorial?

http://www.ofpec.com/ed_depot/index.php?action=details&id=545&game=ArmA

Quote
For example, how would I ensure that all computers on a server ran a drop script identically?
Or for that matter how would I synchronise the unlocking of a vehicle across all computers?

I've never done particle scripting, so I'm afraid I can't answer the first question. For the second one, try making a trigger with a condition like "unlockmyride", and an on activation line of "myRide lock false". Then have someone's computer execute code like

Code: [Select]
unlockmyride = true
publicVariable "unlockmyride"

That should do it. :cool2:
The OFP Editing Center wishes to remind you that the faithful COMREF will never threaten to stab you and, in fact, cannot speak.
However, in the event that it does speak, you are encouraged to heed its advice. ;)

Offline Lone~Wolf

  • Mission Tools & Mods
  • Members
  • *
  • Vladimir Dmitri Mikhail Andreevich Stamenov
Re: Help me please with publicVariables!
« Reply #2 on: 19 May 2010, 17:24:54 »
Okeydokey, that seems simple enough.

Thanks a bunch!  :good:
Snarling creature, lurking in the background, still writing in .sqs

Offline dr. seltsam

  • Members
  • *
Re: Help me please with publicVariables!
« Reply #3 on: 19 May 2010, 17:34:19 »
Quote
For example, how would I ensure that all computers on a server ran a drop script identically?

How do you mean that? Identically parameters? Identically timing? Identically executing?
Post that script... i'll see what to do with it.

Mostly it is not necessary to run pure drop scripts on a server. They do nothing relevant there. Drop commands are typical client business to increase the ambiente. More difficult it gets if you want to have combined effects like for example random explosions, drop fx, sound and damage. In this case you have to split the different jobs into server and client scripts. Please explain your task more detailed before we can help you.
:)

Offline Lone~Wolf

  • Mission Tools & Mods
  • Members
  • *
  • Vladimir Dmitri Mikhail Andreevich Stamenov
Re: Help me please with publicVariables!
« Reply #4 on: 19 May 2010, 19:21:52 »
Very well, attatched is a quick blood effect I made.

Please show me how to get it to run such that when Person A shoots the victim, every person on the server sees the blood effect.

Thx.
Snarling creature, lurking in the background, still writing in .sqs

Offline dr. seltsam

  • Members
  • *
Re: Help me please with publicVariables!
« Reply #5 on: 25 May 2010, 20:00:31 »
Well,

your script has this in its beginning:
Code: [Select]
_c = _this select 0

#LOOP
_dammage = (getdammage _c)
@(getdammage _c > _dammage)

In another topic
http://www.ofpec.com/forum/index.php?topic=22956.30
i found these lines for the damage/getdammage command:
Quote
damage object      works on (non)local object, rounding error on nonlocal object

I think it is possible that your script will lead to different results on different computers, the information "getdammage _c" seems not to have a high priority in a multiplayer mission. Let's go with "hit" eventhandlers...

1. We initialize variables fx_0,fx_1,fx_2,... for every unit, and apply indexed "hit" and "killed" eventhandlers.
Code: [Select]
; *****************************************************
; ** FX_Init                                
; *****************************************************

; an array containing all units that will carry the fx eventhandler
_u_ar=[s1,s2,s3,s4]

; the minimum distance that will make the fx appear
_d=2000

; the script that gets executed (client only) from every hit
_s="bloodthingy.sqs"

; a unit on the field that will bury dead corpses
_g=gd

; the minimum delay before body deletion in seconds
_min=60

; the maximum delay
_max=120
 
_client=local player
_script="FX_Check.sqs"

_str_1  = "fx_%1=false"
_str_2  = "_u addEventHandler [{hit},{fx_%1=true; publicvariable {fx_%1}}]"
_str_3  = "_u addEventHandler [{killed},{_this exec {FX_Delete.sqs}}]"
_str_ar = [_str_1,_str_2,_str_3]

fx_gravedigger = _g
fx_del_min     = _min
fx_del_max     = _max

_i=0
_c=count _u_ar
while {_i < _c} do {_u=_u_ar select _i; {call format [_x,_i]} foreach _str_ar; if _client then {[_u,_i,_d,_s] exec _script}; _i=_i+1}
exit

2. A client script for every single unit will check the corresponding variable and execute "bloodthingy.sqs" in case of a hit. If the unit dies, we end its "FX_Check.sqs" and save performance.
Code: [Select]
; *****************************************************
; ** FX_Check                              
; *****************************************************

_u=_this select 0
_i=_this select 1
_d=_this select 2
_s=_this select 3

_str1=format ["fx_%1",_i]
_str2="=false"

# FX
@ (call _str1) or (not alive _u)
if ((vehicle _u) distance (vehicle player) < _d) then {_this exec _s}
if (alive _u) then {call (_str1+_str2); goto "FX"}
exit


3. The death of an enemy does not only lead to body deletion, we bury him before, that looks much cooler. The timing is random, and can be choosen by the mission maker. This here runs from the "killed" eventhandler.
Code: [Select]
; *****************************************************
; ** FX_Delete
; *****************************************************

_body=_this select 0

~1

_del=fx_del_min+random (fx_del_max-fx_del_min)

~_del

fx_gravedigger action ["hidebody",_body]

~15

deleteVehicle _body

exit

4. I changed "bloodthingy.sqs" a bit.
Code: [Select]
; Put [this] exec "bloodthingy.sqs" in the init line of the victim.
; modified by dr. seltsam

_c = _this select 0

;#LOOP
;_dammage = (getdammage _c)
;@(getdammage _c > _dammage)

_types = ["cl_water"]
_ctypes = count _types

;"koulesvetlo"
;"obrysove svetlo"
;"cl_fire"
;"cl_water"
;"cl_basic"

_user  = _c

_count = 0
_pos = [(getpos _user select 0),(getpos _user select 1),(getpos _user select 2)+1]
_i = 0
_maxspd = 20
_mass  = 100
_vol   = -10
_rubb  = 0
_size  = [2,0.5,0.75,1]
_numdrops = 10
; _angbase=(getdir _c)+45+(random 30)-15
_angbase=(random 359)
#explosion
_maxspd = (random 6)
_mass  = (random 300)
_vol   = (0-(random 10))
_rubb  = 0
_size  = [(random 1),(random 0.2),(random 0.6),(random 1)]
_count = (_count + 1)
_ang = (random (random (random 359))) + _angbase
_rad = random _maxspd
_vel = [sin(_ang)*_rad, cos(_ang)*_rad, random _maxspd]
_rand = random _ctypes
_typen = (_rand - (_rand mod 1))
_type = _types select _typen
drop [_type, "", "Billboard", 1, (random 3), _pos, _vel, 0.5, _mass, _vol, _rubb, _size, [[(random 1),0,0,(random 1)], [(random 1),0,0,(random 1)], [(random 1),0,0,(random 1)], [(random 1),0,0,(random 1)], [(random 1),(random 1),(random 1),0]], [0,0,0], 0, 0, "", "", ""]
_rad = random _maxspd
_vel = [sin(_ang)*_rad, cos(_ang)*_rad, random _maxspd]
_rand = random _ctypes
_typen = (_rand - (_rand mod 1))
_type = _types select _typen
drop [_type, "", "Billboard", 1, (random 3), _pos, _vel, 0.5, _mass, _vol, _rubb, _size, [[(random 1),0,0,(random 1)], [(random 1),0,0,(random 1)], [(random 1),0,0,(random 1)], [(random 1),0,0,(random 1)], [(random 1),(random 1),(random 1),0]], [0,0,0], 0, 0, "", "", ""]
_i = _i + 1
; ~0.005
_pos = [(getpos _user select 0),(getpos _user select 1),(getpos _user select 2)+1]
? (_count < (random 100)) : goto "explosion"
;? (alive _c) : goto "LOOP"
;_direc=(getdir _c)+225+(random 30)-15
;_c setdir _direc
;_c switchmove "CombatRunBDyingVer2"
;~((random 5)+15)
;deletevehicle _c

For the final animation i have no idea at the moment. Does a body that is in "switchmove" on the client computers, but deleted on the server, lead to problems? Anybody knows?

I hope this script set here will help your project. All is packed together in a little sample mission on desert island.
:cool2:
« Last Edit: 25 May 2010, 22:18:27 by dr. seltsam »