OFPEC Forum

Addons & Mods Depot => Arma2 - Configs & Scripting => Topic started by: Lone~Wolf on 11 Aug 2015, 03:39:42

Title: Making a mod that automatically adds an eventHandler to all units
Post by: Lone~Wolf on 11 Aug 2015, 03:39:42
Hi again guys,

I've got a problem that's driving me bananas. I've got a script that I want to run for every Man type unit whenever they get hit. So I want to put an eventHandler on all Man type units globally.
I want to do this as part of a mod so it runs on all missions, so for example I could run the mod with "-mod=@blahblah" and then open Trial By Fire or some other vanilla mission and the eventhandler would be applied to all units there.

I've spent five hours trying to solve this and I've reverse engineered tons of other mods to see how they do it and nothing I do seems to work, even when it seems to be the same code as other people's mods.

Please help me here, I'm going mad.
Title: Re: Making a mod that automatically adds an eventHandler to all units
Post by: h- on 11 Aug 2015, 15:41:38
It's not that hard I reckon..
What Arma is different from OFP is that it's pretty anal about inheritance, so you have to make the addon dependant on CACharacters so that the class CAManBase gets loaded up first, then you 'edit' that class as all men inherit from it..

Anyway, this should work  :dunno:

Code: [Select]
#define ReadAndWrite 0
#define ReadAndCreate 1
#define ReadOnly 2
#define ReadOnlyVerified 3

#define private 0
#define protected 1
#define public 2

#define true 1
#define false 0

class CfgPatches {
class sometestcrapo {
  units[]={};
  weapons[]={};
  requiredVersion=1.00;
  requiredAddOns[]={"CACharacters"};
  };
};

class CfgVehicles {
class CaManBase {
class EventHandlers {
init="[]spawn{sleep 1; hint 'WEE'}";
};
};
};

EDIT:
Also went all moderator and moved this to a more suitable place :P