Jump to content
Sign in to follow this  
nebulazerz

Need Help With Side Select In Event Handler.

Recommended Posts

I wanna thank everyone who helped me get this far with this script but no matter what i try and no matter where I move the line thats not working, i cannot get this to work right even though there are no error codes given to me. I am trying to make it so only enemies will give you my "cash" variable and friendlies will give you a message telling you that you shouldn't kill friendlies. What I can get it to do in many spots is still give me the money no matter who I kill and never with the message which leads me to believe that for some reason its completely ignoring the line. Is it the formatting of it or am is the hint in the wrong place and should be in the cashonKillerFunction? I am testing this by using the init of enemy and friendly AI and I will be using the MP version of the eventhandler for players. 

 

Edit: These are the closest I gotten it to working, it seems like it ignoring playerSide check no matter where I put it

 

Edit2: been messing with the BIS_fnc_objectSide but i still cant figure out quite how to use it right, here is where im at right now

 

Edit3: I think Im really close, its giving me an error that it was expecting side bool. what could i change to fix that?

this addEventHandler ["Killed", 
 { 
   
  _killed = param [0,objNull]; 
  _killer = param [1,objNull]; 
  if ((side player == side _killed) call bis_fnc_objectside) exitWith {"You killed a friendly player! bad boy!" remoteExec["hint", _killer]}; 
  if (isPlayer _killer) then  
  { 
   [] call cashonKillerFunction; 
  }; 
 } 
];

 

Share this post


Link to post
Share on other sites

Your usage of bis_fnc_objectside is nonsensical,

the rest of your script snippet shows that you're rather new to scripting so I'll lend you a hand.

You don't need to return default values with the 'param' command, since the Eventhandler will already do that,

there will always be a killed unit.

This line:

if ((side player == side _killed) call bis_fnc_objectside) exitWith {"You killed a friendly player! bad boy!" remoteExec["hint", _killer]}; 

should give you an error, the if condition expects bool, the bis_fnc_objectside expects an object as first and bool as second parameter.

How this doesn't throw up any errors on your side is beyond me, it sure does with -showScriptErrors enabled.

 

The odd thing about a killed eventhandler is, as soon as a unit is dead, they join the civilian side for whatever reason.

So you need to either set a variable on the unit containing the side before it was killed (not optimal),

or you use the following solution, grabbing the units side from the config.

Using global MP eventhandler so it's called on every machine:

this addMPEventHandler ["MPKilled",
  {

    params ["_killed","_killer"];
    if !(isPlayer _killer) exitWith {true};
    _killedSide = [getNumber (configfile >> "CfgVehicles" >> typeOf _killed >> "side")] call BIS_fnc_sideType;
    _sameSide = side _killer isEqualTo _killedSide;
    if (_sameSide) exitWith {
      "You killed a friendly unit! bad boy!" remoteExec["hint", _killer];
    };
    _giveCash = [] call cashonKillerFunction;
  }
];

Cheers

  • Like 2

Share this post


Link to post
Share on other sites

Your usage of bis_fnc_objectside is nonsensical,

the rest of your script snippet shows that you're rather new to scripting so I'll lend you a hand.

You don't need to return default values with the 'param' command, since the Eventhandler will already do that,

there will always be a killed unit.

This line:

if ((side player == side _killed) call bis_fnc_objectside) exitWith {"You killed a friendly player! bad boy!" remoteExec["hint", _killer]}; 

should give you an error, the if condition expects bool, the bis_fnc_objectside expects an object as first and bool as second parameter.

How this doesn't throw up any errors on your side is beyond me, it sure does with -showScriptErrors enabled.

 

The odd thing about a killed eventhandler is, as soon as a unit is dead, they join the civilian side for whatever reason.

So you need to either set a variable on the unit containing the side before it was killed (not optimal),

or you use the following solution, grabbing the units side from the config.

Using global MP eventhandler so it's called on every machine:

this addMPEventHandler ["MPKilled",
  {

    params ["_killed","_killer"];
    if !(isPlayer _killer) exitWith {true};
    _killedSide = [getNumber (configfile >> "CfgVehicles" >> typeOf _killed >> "side")] call BIS_fnc_sideType;
    _sameSide = side _killer isEqualTo _killedSide;
    if (_sameSide) exitWith {
      "You killed a friendly unit! bad boy!" remoteExec["hint", _killer];
    };
    _giveCash = [] call cashonKillerFunction;
  }
];

Cheers

I had started trying a bunch of nonsense things because i couldnt figure out why it wasnt working until later in the day when kylania told me about the line that shows the target and your side. We changed side to faction and it worked without the bis_fnc_objectside (that was me grasping at straws after trying to figure it out all day.) I see what you are doing there with the killed side. so is the sidetype taking the default side type that the object was when it was created?

Share this post


Link to post
Share on other sites

idk if I got ur question but i try it:

    _killedSide = [getNumber (configfile >> "CfgVehicles" >> typeOf _killed >> "side")] call BIS_fnc_sideType;

this line first gets a side ID from the configfile CfgVehicles. typeOf _killed is the classname of killed object and for that classname its gettinge the side ID.

BIS_fnc_sideType just translates those ID into east, west or civilian ...

 

that means that te given side is the side which is preconfigured in the config file for that classnmae. it is not the side where the unit was created in all cases because u r able to create units on a different side. its possible to create a bluefor unit using an opfor classname. in this case u would have an opfor looking soldier who is member of side west... in this case the above line wouldnt work because it would detect side east because of the classname...

 

 

@Grumpy:

why using remoteExec if that EH is executed on killers machine? Ithink this

if (_sameSide) exitWith {
      "You killed a friendly unit! bad boy!" remoteExec["hint", _killer];
};

could just be this?

if (_sameSide) exitWith {hint "You killed a friendly unit! bad boy!";};
  • Like 1

Share this post


Link to post
Share on other sites

Regular hint should do the trick, was focused on solving the side shenanigans first.

My solution could cause issues when shooting a captive unit or a unit that's being joined into a different sides group, so you need to watch out for that.

 

Cheers

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  

×