Last active
January 20, 2016 11:48
-
-
Save Dahlgren/b249e02ceb91f52e6093 to your computer and use it in GitHub Desktop.
Fired EH Json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SerializeJson = { | |
_type = _this select 0; | |
switch _type do | |
{ | |
case "number": | |
{ | |
_this select 1; | |
}; | |
case "string": | |
{ | |
format ["""%1""", _this select 1]; | |
}; | |
case "object": | |
{ | |
private "_objects"; | |
_objects = []; | |
{ | |
private "_key"; | |
_key = _x select 0; | |
private "_value"; | |
_value = (_x select 1) call SerializeJson; | |
_objects pushBack (format ["""%1"": %2", _key, _value]); | |
} forEach (_this select [1, count _this]); | |
format ["{%1}", _objects joinString ","]; | |
}; | |
case "array": | |
{ | |
private "_array"; | |
_array = []; | |
{ | |
_array pushBack (_x call SerializeJson); | |
} forEach (_this select [1, count _this]); | |
format ["[%1]", _array joinString ","]; | |
}; | |
} | |
}; | |
ObjectPlayer = { | |
_player = _this; | |
["object", | |
["name", ["string", name _player]], | |
["uid", ["string", getPlayerUID _player]], | |
["nid", ["string", netId _player]] | |
]; | |
}; | |
ObjectPosition = { | |
_position = _this; | |
["object", | |
["x", ["string", _position select 0]], | |
["y", ["string", _position select 1]], | |
["z", ["string", _position select 2]] | |
]; | |
}; | |
FiredEH = { | |
_unit = _this select 0; | |
_weapon = _this select 1; | |
_ammo = _this select 4; | |
_arr = ["object", | |
["type", ["string", "UnitFired"]], | |
["weapon", ["string", _weapon]], | |
["ammo", ["string", _ammo]], | |
["player", _unit call ObjectPlayer], | |
["position", (getPos _unit) call ObjectPosition] | |
]; | |
_json = _arr call SerializeJson; | |
hint format ["%1", _json]; | |
}; | |
player addEventHandler ["Fired", FiredEH]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment