Arma 3
kill counter working, but not counting units that spawn later
for instance i have opfor units that are placed around the area, as well as opfor units that will spawn at a later time in the same area. the counter works just fine for the opfor that have been placed into the editor, however the units that spawn at a later time do not count. im using the Zombies and Demons mod from the workshop and using their spawner and setting the units that spawn to opfor.
zombie_kills = 0; execVM "scoreboard.sqf"; zombie_kill_limit = 3; zombie_counter = { if (_this >= zombie_kill_limit) then { player sidechat "mission end"; // end mission, do whatever }; }; if isserver then { { if (side _x == EAST) then { _x addEventHandler ["killed", { zombie_kills = zombie_kills + 1; publicvariable "zombie_kills"; if !isdedicated then { zombie_kills call zombie_counter; }; }]; }; } foreach allunits; }; if !isdedicated then { "zombie_kills" addpublicvariableeventhandler { (_this select 1) call zombie_counter }; };
in the scoreboard.sqf
while{true} do {
hint format["zombie kills: %1", zombie_kills];
sleep 2;
};
Last edited by IM SORRY BUFFALO; Apr 8, 2016 @ 10:52pm
< >
Showing 1-13 of 13 comments
NobodysLaw Apr 9, 2016 @ 2:34am 
Your code only calls once (on mission start) the addEventHandler on all units. You need to make it a loop (which is not good), or ad the eventhandler when the units are spawned (which is good)
Last edited by NobodysLaw; Apr 9, 2016 @ 2:35am
MATTXYO Apr 9, 2016 @ 4:09am 
How are those 'if' statements not flagging up errors? isserver instead of (isServer) etc.

Also quite a few Caps are lower case: (isDedicated),(!isDedicated), forEach allUnits etc.
Last edited by MATTXYO; Apr 9, 2016 @ 5:28am
What Nobody said,you need to add the Eventhandler via the script you use to spawn OPFOR
IM SORRY BUFFALO Apr 9, 2016 @ 10:18am 
Originally posted by MATTXYO:
How are those 'if' statements not flagging up errors? isserver instead of (isServer) etc.

Also quite a few Caps are lower case: (isDedicated),(!isDedicated), forEach allUnits etc.
ive never had any issues not using caps. if im just testing something i dont use any caps however once everything is working i go through and do it just to make it look nice and tidy.
MATTXYO Apr 9, 2016 @ 10:57am 
Originally posted by TKgokitty199:
Originally posted by MATTXYO:
How are those 'if' statements not flagging up errors? isserver instead of (isServer) etc.

Also quite a few Caps are lower case: (isDedicated),(!isDedicated), forEach allUnits etc.
ive never had any issues not using caps. if im just testing something i dont use any caps however once everything is working i go through and do it just to make it look nice and tidy.
Always thought it was case sensitive, and are the 'if' statements not causing errors with the conditions not being inside ( ) ?
IM SORRY BUFFALO Apr 9, 2016 @ 11:02am 
Originally posted by MATTXYO:
Originally posted by TKgokitty199:
ive never had any issues not using caps. if im just testing something i dont use any caps however once everything is working i go through and do it just to make it look nice and tidy.
Always thought it was case sensitive, and are the 'if' statements not causing errors with the conditions not being inside ( ) ?
nope no errors.
IM SORRY BUFFALO Apr 9, 2016 @ 11:04am 
Originally posted by Nobody:
Your code only calls once (on mission start) the addEventHandler on all units. You need to make it a loop (which is not good), or ad the eventhandler when the units are spawned (which is good)
i cant figure out a way to add the event handler when the units spawn. im using the spawner module that comes with the mod so i might have to do it another way
NobodysLaw Apr 9, 2016 @ 11:53am 
Then look for the script that spawns them and alter it ;)

That's why you should not use other scripts - always a pain to modify to your liking :D
IM SORRY BUFFALO Apr 10, 2016 @ 8:46am 
Originally posted by Nobody:
Then look for the script that spawns them and alter it ;)

That's why you should not use other scripts - always a pain to modify to your liking :D
your 100% right lol already got them spawning how i want within a matter of 10 minutes and already works better than that spawning module that came with it and i can actually change the darn thing and easily add the event handler after it. makes me feel stupid. thanks for the help
IM SORRY BUFFALO Apr 11, 2016 @ 7:20pm 
Originally posted by Nobody:
Then look for the script that spawns them and alter it ;)

That's why you should not use other scripts - always a pain to modify to your liking :D
hey question, how would i go about having the points go up for each player seperatly? instead of the points going up everytime ANYBODY kills a opfor unit, make everyone have their own points, such as if i get 15 kills then i would have 15 points, and if my friend got 10 kills he would have 10 points. so my score would be 15 and his would be 10.
NobodysLaw Apr 12, 2016 @ 1:23am 
Let's say you have 10 players, then you need to make 10 variables in the init.sqf
if(isServer || isDedicated) then { p1_kills = 0; publicVariable "p1_kills"; . . . p10_kills = 0; publicVariable "p10_kills"; };

Then you must name all playable units, p1 to p10 or whatever.

In the addEventHandler start a script when a guy is killed, let's call it killcounter.sqf. You can do it with a lot of ifs, but a switch is in this case better and faster
_killer = _this select 1; switch (_killer) do { case p1: { p1_kills = p1_kills + 1; }; . . . case p10: { p10_kills = p10_kills + 1; }; };
IM SORRY BUFFALO Apr 12, 2016 @ 10:18am 
Originally posted by Nobody:
Let's say you have 10 players, then you need to make 10 variables in the init.sqf
if(isServer || isDedicated) then { p1_kills = 0; publicVariable "p1_kills"; . . . p10_kills = 0; publicVariable "p10_kills"; };

Then you must name all playable units, p1 to p10 or whatever.

In the addEventHandler start a script when a guy is killed, let's call it killcounter.sqf. You can do it with a lot of ifs, but a switch is in this case better and faster
_killer = _this select 1; switch (_killer) do { case p1: { p1_kills = p1_kills + 1; }; . . . case p10: { p10_kills = p10_kills + 1; }; };
thank you. thats alot simpler than i thought. really similar to c++
NobodysLaw Apr 12, 2016 @ 10:24am 
Well, the logic is the same in every programming language only the functions and commands are different.
< >
Showing 1-13 of 13 comments
Per page: 1530 50

Date Posted: Apr 8, 2016 @ 10:50pm
Posts: 13