Jump to content
Sign in to follow this  
1para{god-father}

How to add Points system

Recommended Posts

I am trying to keep track of a score system not for each play but as a whole to display at the end of a mission. , i.e each time an AI is killed I need to add some points, would I have to add a EH to each AI that I spawn in ? if so what would be the best way to do this ? and would this cause any notable Lagg ?

These are the scripts i normally use to spawn AI in

_dis = 50;
_ang = random 300;
_dx = sin(_ang)*_dis;
_dy = cos(_ang)*_dis;
_positionToSpawnIn = [((getpos _vehiclscud1) select 0) + _dx, ((getpos _vehiclscud) select 1) + _dy, 0];
_upsgrp1 = [1,_positionToSpawnIn,1,["marker_scud1","spawned","showmarker","nowait","delete:",120]] execVM "SCRIPTS\UPSMON\MON_SPAWN.SQF";

or

_Grp1 = [_pos, EAST, (configFile >> "CfgGroups" >> "EAST" >> "BIS_TK_INS" >> "Infantry" >> "TK_INS_Group")] call BIS_fnc_spawnGroup;
[_Grp1, _pos, 80] call bis_fnc_taskPatrol;

Or any other suggestion to spawn in :)

Share this post


Link to post
Share on other sites

Yes but i need to be able to control i.e

Every OPFOR killed +5 point every Vehicle destroyed +10 points etc..

If played dies - points etc...

Share this post


Link to post
Share on other sites

use killed or MPKilled EH. MPKilled should stay on a player upon death/respawn.

Share this post


Link to post
Share on other sites

Thanks,

Still unsure really what to do !

so forgive me but how would I add a EH to a group and add the score to a PublicVariable ?

?


///Spawn in group
_Grp1 = [_pos, EAST, (configFile >> "CfgGroups" >> "EAST" >> "BIS_TK_INS" >> "Infantry" >> "TK_INS_Group")] call BIS_fnc_spawnGroup;
[_Grp1, _pos, 80] call bis_fnc_taskPatrol;

///add EH to group for score to each AI killed it would add 5 points to a variable ???////////
_Grp1 addMPEventHandler ["MPkilled", { addScore 5; }]; 	

Share this post


Link to post
Share on other sites

Something like this, I'm not sure what exactly is your intent. I didn't test this and also, someone may have a better solution.

init.sqf

is (isNil "scor") then { scor = 0 };
publicVariable "scor"; 

if (!isServer) exitWith {};

_nil=[]execVM "groups.sqf";

groups.sqf

_Grp1 = [_pos, EAST, (configFile >> "CfgGroups" >> "EAST" >> "BIS_TK_INS" >> "Infantry" >> "TK_INS_Group")] call BIS_fnc_spawnGroup; [_Grp1, _pos, 80] call bis_fnc_taskPatrol;
[_Grp1, _pos, 80] call bis_fnc_taskPatrol;


..other groups w/e...

sleep 1;

_nil=[]execVM "eventhandlers.sqf";

eventhandler.sqf

waitUntil{!(isNil "BIS_MPF_InitDone")};
{
       if (side _x == East) then
       {
           _x addMPEventHandler ["MPKilled", { scor = scor + 5; publicVariable "scor"; _text = parseText format["%1",scor];[nil,nil,rHint,_text] call RE }]

       }

} forEach allUnits;

{
       if (side _x == East) then
       {
           _x addMPEventHandler ["MPKilled", { scor = scor + 10;  publicVariable "scor"; _text = parseText  format["%1",scor];[nil,nil,rHint,_text] call RE }]

       }

} forEach vehicles;

waitUntil { scor == 100 }; // use {scor == (paramsArray select #)} instead if you set up lobby parameters

_text = parseText  format["The final score is %1",scor];[nil,nil,rHint,_text] call RE

Edited by Iceman77

Share this post


Link to post
Share on other sites

Would there be any way to just have the points added if Bluefor kill OPFOR as i noticed you get points some times as they Kill themselves or each-other by mistake.

Thanks

Share this post


Link to post
Share on other sites

Not sure if this will work.

waitUntil{!(isNil "BIS_MPF_InitDone")};

{

        if (side _x == East) then
       {
           _x addMPEventHandler ["MPKilled", { if (!isNull _this select 1) then {scor = scor + 5;  publicVariable "scor"; _text = parseText  format["%1",scor];[nil,nil,rHint,_text] call RE }}]

       }

} forEach allUnits;

{
       if (side _x == East) then
       {
           _x addMPEventHandler ["MPKilled", { if (!isNull _this select 1) then {scor = scor + 10;  publicVariable  "scor"; _text = parseText  format["%1",scor];[nil,nil,rHint,_text] call  RE }}]

       }

} forEach vehicles;

OR

waitUntil{!(isNil "BIS_MPF_InitDone")};

{

        if (side _x == East) then
       {
           _x addMPEventHandler ["MPKilled", { if (alive _this select 1) then {scor = scor + 5;  publicVariable "scor"; _text = parseText   format["%1",scor];[nil,nil,rHint,_text] call RE }}]

       }

} forEach allUnits;

{
       if (side _x == East) then
       {
           _x addMPEventHandler ["MPKilled", { if (alive _this select 1) then {scor = scor + 10;  publicVariable  "scor"; _text = parseText   format["%1",scor];[nil,nil,rHint,_text] call  RE }}]

       }

} forEach vehicles;

Edited by Iceman77

Share this post


Link to post
Share on other sites

Thanks - the points still toted up when they killed each other, i tried this and it seems to work , would it work on dedi do you know ?

    _x addMPEventHandler ["MPKilled", { if ([color="#FF0000"]_this select 1 == player)[/color] then {scor = scor + 10;  publicVariable  "scor"; _text = parseText   format["%1",scor];[nil,nil,rHint,_text] call  RE }}]

Share this post


Link to post
Share on other sites

I am spawning more group later and trying to add the EH to the group but i get a error? did not thyink i could issue it to Allunits again would it add another EH ? i.e 2 to each group ?

Please advise what i ma going wrong here ...thanks


_ang = random 360;  
_dis = 200;
_dx = sin(_ang)*_dis;
_dy = cos(_ang)*_dis;
_positionToSpawnIn = [((getpos _vehicleambush) select 0) + _dx, ((getpos _vehicleambush) select 1) + _dy, 0];
_upsgrp1 = [1,_positionToSpawnIn,1,["ambushconvoy1","spawned","nowait","showmarker","delete:",60]] execVM "SCRIPTS\UPSMON\MON_SPAWN.SQF";
sleep .2;

{

        if (side _x == East) then
       {
           _x addMPEventHandler ["MPKilled", { if (_this select 1 == player) then {totalscore = totalscore + 5;  publicVariable "totalscore"; _text = parseText   format["%1",totalscore];[nil,nil,rHint,_text] call RE }}]

       }

} forEach _upsgrp1;

RPT error

Error in expression <[nil,nil,rHint,_text] call RE }}]

}

} forEach _upsgrp1;

_ang = random 180;  
>
 Error position: <forEach _upsgrp1;

_ang = random 180;  
>
 Error foreach: Type Script, expected Array

Share this post


Link to post
Share on other sites

{           

                  if (side _x == East) then 
                    {             
                       _x addMPEventHandler ["MPKilled", { if (_this select 1 == player) then {totalscore = totalscore + 5;  publicVariable "totalscore"; _text = parseText   format["%1",totalscore];[nil,nil,rHint,_text] call RE }}]        
                    } 


} forEach [color=#ff0000]units[/color] _upsgrp1;

Edited by Iceman77

Share this post


Link to post
Share on other sites

Whilst the correction offered by Iceman above is certainly correct, I think the problem here is also that the spawning script is not returning the group spawned.

Share this post


Link to post
Share on other sites

Yep I think you are correct , as it does not work , but if i use "allUnits" it works so the group is not being returned.

I presume it will not add another EH so will stick with allUnits

Share this post


Link to post
Share on other sites

I think it will add another EH. You can double them up so to speak.

Share this post


Link to post
Share on other sites

just double checked on wiki and it will not overwrite a existing EH so should be OK

"if you add an event handler of type "killed" and there already exists one, the old one doesn't get overwritten"

Share this post


Link to post
Share on other sites

I take that to mean there will then be 2 EH and so you will get double the points?

Share this post


Link to post
Share on other sites

I don't understand why you can't put the eventhandler just on the newly spawned group...


_ang = random 360;  
_dis = 200; 
_dx = sin(_ang)*_dis;
_dy = cos(_ang)*_dis; 
_positionToSpawnIn = [((getpos _vehicleambush) select 0) + _dx, ((getpos _vehicleambush) select 1) + _dy, 0]; 
_upsgrp1 = [1,_positionToSpawnIn,1,["ambushconvoy1","spawned","nowait","showmarker","delete:",60]] execVM "SCRIPTS\UPSMON\MON_SPAWN.SQF"; 
sleep .2;

{           

                  if (side _x == East) then 
                    {             
                       _x addMPEventHandler ["MPKilled", { if (_this  select 1 == player) then {totalscore = totalscore + 5;  publicVariable  "totalscore"; _text = parseText    format["%1",totalscore];[nil,nil,rHint,_text] call RE }}]        
                    } 


} forEach [color=#ff0000]units[/color] _upsgrp1;

Share this post


Link to post
Share on other sites

If the spawn script isn't set up to return the group the handle indicates the script, not the group array, hence the error at the end: Error foreach: Type Script, expected Array

Share this post


Link to post
Share on other sites

Ahh nvm, I see he's using upsmon. I assumed he was actually creating a group, didn't look to hard .

*(searches for glasses)

Share this post


Link to post
Share on other sites

Its also my understanding that using execVM the script won't return anything anyway... I think you have to use call.

Share this post


Link to post
Share on other sites

It's early, but I have another idea, that may or may not work, as I'm not so familiar with upsmon (only vaguely). What if you spawned a group normally and then set the leaders init to run upsmon? Then you could ad the EH to the group itself.

Share this post


Link to post
Share on other sites

Good idea. The only alternative I can think of would be adjusting the UPSmon spawn script to return the group and call it instead. I don't think adding the EH to allUnits is going to work... but I've been wrong before.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×