Jump to content
Sign in to follow this  
nuxil

Server Sided Addon - Need a little help

Recommended Posts

Hello all.

Im trying to put together a server sided addon. however the addon only works on some of the mission, and some if fails.

I need some help figuring out how to fix this issue.

Im trying to make some sort of AntiTK addon that communicates with Bec, so one can do BE kick & BE Ban on players.

This is setup in a settings file. anyway my dll file and Bec Plugin is working fine.

Its the damn sqf files that are causing me headache.

My Config.cpp

class Bec
{
   name = "Bec NamedPipe Client";
   dir = "@Bec";
   version = "0.1";
   author[] = {"Stian Mikalsen"};
   authorUrl = "http://www.ibattle.org"; 
   requiredAddons[] = {};
   requiredVersion = 1;
   units[] = {};
   weapons[] = {};
   hideName = "false";
   hidePicture = "true";
   //picture = "";
   actionName = "Website";
   action = "http://www.ibattle.org"; // URL
   description = "";
};

class CfgPatches {
   class Bec_main : Bec {};
};

class CfgMods {
   class Bec_mod : Bec {};
};

class CfgFunctions
{
   class Bec
   {
       class main
       {
           //class startServer
           //{
           //    file = "\Bec\fn_init.sqf";
           //    postInit  = 1; 
           //};
           class init
           {
               file="\Bec\fn_init.sqf";
               preInit=1;
               //postInit=1;
           };

           class onPlayerConnected
           {
               file="\Bec\fn_onPlayerConnected.sqf";
               preInit=1;
           };

           class onKilled
           {
               file="\Bec\fn_onKilled.sqf";
           };
       };
   };
};

My fn_init.sqf

private ["_version"];

diag_log text format["fn_init.sqf started"];
//waitUntil {(time > 1)};
if (isServer) then 
{
   _version = "BecNpc" callExtension "version";
   diag_log text format["BecNpc.dll Version: %1", _version];
};

//onPlayerConnected {[_id, _uid, _name] spawn BEC_fnc_onPlayerConnected;};
["BattleyeExtendedControls_id", "onPlayerConnected", {[_id, _uid, _name] spawn BEC_fnc_onPlayerConnected;}] call BIS_fnc_addStackedEventhandler;

diag_log text format["Bec Addon - Adding OnPlayerConnected to BIS_fnc_addStackedEventhandler"];

My fn_onPlayerConnect.sqf

private ["_uid"];
_uid = _this select 1;

diag_log text format["fn_onPlayerConnected.sqf started"];


{
   private ["_side", "_name", "_Bec_eh_mpki", "_Bec_eh_mpri"];
   if (isPlayer _x) then 
   {
       if ((getPlayerUID _x) == _uid) exitWith
       {
           _side = side group _x;
           _name = name _x;

           // get the index of current MPKilled event..
           _Bec_eh_mpki = _x addMPEventHandler ["MPKilled", {if (isServer) then {_this call BEC_fnc_onKilled}}];

           _x setvariable ["BattleyeExtendedControls", [_side, _name, _Bec_eh_mpki]];

           diag_log text format["OnPlayerConnected Executed on %2 : %1", _side, _name];
       };
   };

} forEach playableUnits;

/*
..to do...
_check = [] spawn {
   diag_log text format["Running Bec EVH Check"];
   if (isServer) then 
   {
       if (isNil 'BecNpc_EVHC') then 
       {
           BecNpc_EVHC = true;

           while {BecNpc_EVHC} do 
           {
               sleep(5);
               {
                   private ["_side", "_name", "_Bec_eh_mpki","_Bec_eh_mpkit"];
                   if (isPlayer _x) then 
                   {
                       _side =  _x getvariable "BattleyeExtendedControls" select 0;
                       _name =  _x getvariable "BattleyeExtendedControls" select 1;    
                       _Bec_eh_mpki = _x getvariable "BattleyeExtendedControls" select 2;
                       _Bec_eh_mpkit = _x addMPEventHandler ["MPKilled", {true}];

                       // test if someone been messing around with the MPKilled eventhandlers..
                       if (((_Bec_eh_mpki + 1) <= _Bec_eh_mpkit)) then 
                       {
                           //ok ? since new events get +1 on index from what the previouse has ?...
                           true;
                       }
                       else
                       {
                           diag_log text format["Something removed the Bec MPKilled EVH"];

                           _Bec_eh_mpki = _x addMPEventHandler ["MPKilled", {if (isServer) then {_this call BEC_fnc_onKilled}}];
                           _x setvariable ["BattleyeExtendedControls", [_side, _name, _Bec_eh_mpki]];
                       };                

                   };

               } forEach playableUnits;
           };
       };
   };
};
*/

My fn_onKilled

private ["_victim", "_killer", "_side_victim", "_side_killer", "_name_victim", "_name_killer"];

diag_log text format["fn_onKilled.sqf started"];

_victim = _this select 0;
_killer = _this select 1;
_side_victim = _victim getvariable "BattleyeExtendedControls" select 0;
_side_killer = _killer getvariable "BattleyeExtendedControls" select 0;
_name_victim = _victim getvariable "BattleyeExtendedControls" select 1;
_name_killer = _killer getvariable "BattleyeExtendedControls" select 1;

diag_log text format["OnKilled Executed: Victim : %1 , Killer %2", _victim, _killer];

if (isplayer _killer) then {
   diag_log text format["EH MPKILLED : PLAYER %1 : %2 KILLED BY PLAYER %3 : %4",_side_victim, _name_victim, _side_killer, _name_killer];
}
else
{
   diag_log text format["EH MPKILLED : PLAYER %1 : %2 KILLED BY AI %3 : %4",_side_victim, _name_victim, side _killer, name _killer];
};



if ((_side_victim == _side_killer) && (isplayer _killer)) then 
{
   "BecNpc" callExtension format["%1 ::: %2", _name_victim, _name_killer];;
};

Now when i test on my own simple mission and some other usermade it all works as it should.

some others it will not work on example BeCTI and many more.

i suspect that OnPlayerConnected gets overwritten somehow. because in my rpt log i can see this.

or there is some issue with my playableUnits code.

fn_init.sqf started

BecNpc.dll Version: 0.1.0.0

Bec Addon - Adding OnPlayerConnected to BIS_fnc_addStackedEventhandler

fn_onPlayerConnected.sqf started

when it should be writeing somethis along this lines.

fn_init.sqf started

BecNpc.dll Version: 0.1.0.0

Bec Addon - Adding OnPlayerConnected to BIS_fnc_addStackedEventhandler

fn_onPlayerConnected.sqf started

OnPlayerConnected Executed on BitBrain : WEST

...

so it seems that it only prints the diag_log text format but nothing else.

Any advice on how to fix this ??

Edited by nuxil

Share this post


Link to post
Share on other sites

please use code tag. without formatting its hard to read - or use pastebin and link to it

Share this post


Link to post
Share on other sites

Did that..

Altho after speaking with some people it all boils down to "ab"use of onPlayerConnected in mission.

Mission makers needs a slap in the face.

If you are a mission maker for Arma3 and reading this.

NEVER USE THIS IN YOUR MISSION.

onPlayerConnected {[_id, _uid, _name] ......;};

it wil break addon using onPlayerConnected.

you need to adopt your code and use the BIS_fnc_addStackedEventhandler

["This_is_you_id", "onPlayerConnected", {[_id, _uid, _name] ...your code;}] call BIS_fnc_addStackedEventhandler;

now i consider this issue resolved and time to move on to extended eventhandler...

Share this post


Link to post
Share on other sites

well did you try to overwrite it after a delay / constantly (if changed) with what BIS_fnc_addStackedEventhandler relies upon?

Share this post


Link to post
Share on other sites

Im not sure i understood your question correct.

I was using BIS_fnc_addStackedEventhandler in my addon.

This doesnt owerwrite anything afik. it will just add more event to the stack with your id.

Where as onPlayerConnected not used with BIS_fnc_addStackedEventhandler can overwrite all onPlayerConnected if this is run after you have set the BIS_fnc_addStackedEventhandler[ ...

So i didnt want to mess more with that.

I am using another method now to get the work done.

And so far it seems to work on all missions with unecessary code to readd|checks etc..

Share this post


Link to post
Share on other sites

my theory is this:

the mission "overwrites" BIS_fnc_addStackedEventhandler (it probably hooks into onPlayerConnected, so when the mission sets it itself, it can no longer get stacked)

as such to overwrite it yourself with a delay probably makes it working again

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  

×