Home   Help Search Login Register  

Author Topic: setting damage (solved)  (Read 1479 times)

0 Members and 1 Guest are viewing this topic.

Offline loki72

  • Former Staff
  • ****
    • Loki's Nightmare
setting damage (solved)
« 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
« Last Edit: 01 Aug 2008, 11:32:41 by Planck »

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: setting damage
« Reply #1 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 explains a number of locality issues.
« Last Edit: 31 Jul 2008, 12:15:48 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline loki72

  • Former Staff
  • ****
    • Loki's Nightmare
Re: setting damage
« Reply #2 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.