OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting Multiplayer => Topic started by: loki72 on 31 Jul 2008, 06:01:17

Title: setting damage (solved)
Post by: loki72 on 31 Jul 2008, 06:01:17
greetings,

this works great, unless i am on a dedicated server... any ideas why?

whatever.sqf
Code: [Select]

_pos = _this select 0;
onMapSingleClick "";
....
....

_obj = [];

sleep 0.5;
_obj = nearestObjects [_pos,["ALL"],70];

{_x setdammage 1} forEach _obj;

....
....

thx
Title: Re: setting damage
Post by: Spooner on 31 Jul 2008, 12:10:36
Objects ignore a lot of commands if the object is not local to the machine running the command. In mission-placed triggers, the code will be run on every machine, so you are therefore guaranteed to run it on the local machine and so never need to worry about locality. When you are dealing with client-side scripts, such as those run from actions or via onMapSingleClick, they are only run locally, so you have to manually communicate with the other machines if you are using "local-only" commands.

(Code is untested)

Code: (init.sqf - register interest, on all machines, in changes to destroyObjects variable) [Select]
"destroyObjects" addPublicVariableEventHandler
{
    _objects = _this select 1;
    {_x setdammage 1} forEach _objects;
};

Code: (whatever.sqf) [Select]
...
_obj = nearestObjects [_pos,["ALL"],70];

// Destroy any objects that are local to the client machine.
{_x setdammage 1} forEach _obj;

// Ask all other machines to destroy objects that are local to them.
destroyObjects = _obj;
publicVariable "destroyObjects";
....

This would then work fine on SP, MP hosted or MP dedicated. Please note, however, that by searching for "ALL", you will also be deleting game logics, which could cause compatibility problems, and mission-placed buildings. I'd suggest using "AllVehicles" instead, which will catch men and land/sea/air vehicles.

EDIT: Although it doesn't describe publicVariable events, since it was written before they were introduced, our MP tutorial (http://www.ofpec.com/ed_depot/mptutorial/) explains a number of locality issues.
Title: Re: setting damage
Post by: loki72 on 01 Aug 2008, 02:28:39
works perfect!  thanks spooner.

MP tutorial?!...totally missed that one.

i will spend the next couple of days pouring through it.