aie-boshell 22 Posted July 18, 2017 I'm working on a game mode where players can be promoted by score which allows them to recruit AI that are created at a barracks and would like to addscore to the player group leader each time one of his subordinates gets a kill and/or would otherwise gain score. Is this possible? Share this post Link to post Share on other sites
das attorney 857 Posted July 18, 2017 The easiest way I can think of is add an "entityKilled" EH to the server: https://community.bistudio.com/wiki/Arma_3:_Event_Handlers/addMissionEventHandler#EntityKilled So when someone dies, if the killer is in a player group then all the players in that group get points. You can always change it so only the leader gets points (or however you see fit - I wasn't sure how you wanted it exactly). There's no checking for sides so even friendly fire gets kills! (Again you can add a line of code in if you want to exclude that). It does some basic sorting for kill types as well but you can expand on that how you feel like. // server addMissionEventHandler ["EntityKilled", { params ["_killed", "_killer", "_instigator"]; if (isNull _instigator) then {_instigator = UAVControl vehicle _killer select 0}; if (isNull _instigator) then {_instigator = _killer}; _players = []; { if (isPlayer _x) then { _players pushBack _x } } forEach units group _instigator; if not ([] isEqualTo _players) then { _killed remoteExec [ "fnc_addScore", _players ] } }]; // initPlayerLocal tag_myScore = 0; fnc_addScore = { call { if (_this isKindOf "CAManBase") exitWith { tag_myScore = tag_myScore + 1 }; if (_this isKindOf "ship_f") exitWith { tag_myScore = tag_myScore + 2 }; if (_this isKindOf "air") exitWith { tag_myScore = tag_myScore + 4 }; if (_this isKindOf "landVehicle") exitWith { tag_myScore = tag_myScore + 3 }; }; }; 1 Share this post Link to post Share on other sites
aie-boshell 22 Posted July 20, 2017 On 7/18/2017 at 3:29 PM, das attorney said: tag_myScore = 0; fnc_addScore = { call { if (_this isKindOf "CAManBase") exitWith { tag_myScore = tag_myScore + 1 }; if (_this isKindOf "ship_f") exitWith { tag_myScore = tag_myScore + 2 }; if (_this isKindOf "air") exitWith { tag_myScore = tag_myScore + 4 }; if (_this isKindOf "landVehicle") exitWith { tag_myScore = tag_myScore + 3 }; }; }; Hello Das, I'm unable to get this working exactly as its instructed so there must be a conflict with another script or something. I'm going to tinker with it some more and see what I can figure out. Thanks so much again :-) EDIT: Although I should probably make sure I'm executing these properly, I'm doing the "// server" script through initserver.sqf, and the "// initPlayerLocal" is being ran through initplayerlocal.sqf. I don't have any errors, I'm just not getting the points for the AI kills on player hosted server, or dedicated server. My AI have not yet spawned at mission start, in case that's worth noting. They are created by "addaction" request script. Share this post Link to post Share on other sites
das attorney 857 Posted July 20, 2017 That's cool - it could well be something in my code. I didn't try it before posting so there could be some probs. I'll check it in a little while and come back to you. :) Share this post Link to post Share on other sites
aie-boshell 22 Posted July 20, 2017 10 hours ago, das attorney said: That's cool - it could well be something in my code. I didn't try it before posting so there could be some probs. I'll check it in a little while and come back to you. :) Awesome, in the meantime I will try to figure it out and will post update here if I make progress :-) Share this post Link to post Share on other sites
aie-boshell 22 Posted July 20, 2017 I really do like the idea of every player in the group getting the points for a kill regardless of leadership because I had already planned to add a join group type of addaction within a proximity of other AI groups that would be on missions. It would be super sweet to give each player in the group a certain amount of points for each beneficial thing that is done by any AI in the group (IE: getting kills, accomplishing objectives). This would motivate players to fight with their comrades rather than just as lone wolves. Thanks once again, Das! Share this post Link to post Share on other sites
das attorney 857 Posted July 20, 2017 Cool cool - I just checked on my dedi and it's working ok here' To test, I put the fnc_addScore variable into one of the watch fields on the debug console and it updated as expected. When you say it's not working right, do you mean you see no visual indication? If so, that was intended, so you can either plug the variable into the script Larrow gave you or use another method to display it. Here's a version of the scripts that shows the score in systemChat (also, I've put in a couple of checks for friendly fire and killing civs etc) // initserver.sqf addMissionEventHandler ["EntityKilled", { params ["_killed", "_killer", "_instigator"]; if (isNull _instigator) then {_instigator = UAVControl vehicle _killer select 0}; if (isNull _instigator) then {_instigator = _killer}; _players = []; { if (isPlayer _x) then { _players pushBack _x } } forEach units group _instigator; if not ([] isEqualTo _players) then { [_instigator,_killed] remoteExec [ "fnc_addScore", _players ] } }]; // initPlayerLocal.sqf tag_myScore = 0; fnc_addScore = { params ["_instigator","_killed"]; // are we friends? private _isFriendly = [side _instigator,side _killed] call BIS_fnc_sideIsFriendly; // if friends then deduct. If not then add private _coef = if (_isFriendly) then {-1} else {1}; call { if (_killed isKindOf "CAManBase") exitWith { tag_myScore = tag_myScore + (1 * _coef) }; if (_killed isKindOf "ship_f") exitWith { tag_myScore = tag_myScore + (2 * _coef) }; if (_killed isKindOf "landVehicle") exitWith { tag_myScore = tag_myScore + (3 * _coef) }; if (_killed isKindOf "air") exitWith { tag_myScore = tag_myScore + (4 * _coef) }; }; // some sort of display on screen - here we use systemChat systemChat format ["your score: %1",tag_myScore]; true }; Bear in mind as well that if you napalm a car full of bad guys, then your score would be higher than expected: (4 * 1) for the men and 3 for the vehicle. so 7 etc etc. There might be a few quirks (like if you destroy empty vehicles - I haven't tested that). Hope that helps. Let me know how you get on. Share this post Link to post Share on other sites
aie-boshell 22 Posted July 21, 2017 Hmmm, I must be doing something wrong. I put all of this code in the proper places; initserver.sqf and initplayerlocal.sqf, then I run my dedicated server and I have one AI unit in my group. When he starts killing enemies, I check my score and it is still 0. I'm a bit stumped to what I'm doing wrong but definitely appreciate all the help very much. Share this post Link to post Share on other sites