Add support for inheritance in KP_objectInits, improve example

This commit is contained in:
Filip Maciejewski 2019-10-07 22:00:18 +02:00
parent f971b74829
commit dcc80d2fbf
No known key found for this signature in database
GPG Key ID: 53D1504CC3DBCD46
2 changed files with 26 additions and 4 deletions

View File

@ -1,6 +1,16 @@
/* - Specific object init codes depending on classnames.
Format = [Array of classnames as strings, Code to apply]
_this is the reference to the object with the classname */
/*
Specific object init codes depending on classnames.
Format = [Array of classnames as strings <ARRAY>, Code to apply <CODE>, Allow inheritance <BOOL>]
_this is the reference to the object with the classname
Example:
KPLIB_objectInits = [
[["O_soldierU_F"], {systemChat "CSAT urban soldier was spawned!"}],
[["CAManBase"], {systemChat format ["Some human named '%1' was spawned!", name _this]}, true]
];
];
*/
KPLIB_objectInits = [
// Set KP logo on white flag

View File

@ -18,7 +18,19 @@
params [["_object", objNull, [objNull]]];
private _elements = KPLIB_objectInits select {(toLower (typeOf _object)) in ((_x select 0) apply {toLower _x})};
private _elements = KPLIB_objectInits select {
_x params ["_classes", "", ["_inheritance", false]];
if (_inheritance) then {
{
if (_object isKindOf _x) exitWith {true};
false
} forEach _classes // return
} else {
// return
(toLower (typeOf _object)) in (_classes apply {toLower _x})
};
};
if (_elements isEqualTo []) exitWith {
false