Jump to content
Sign in to follow this  
CarlGustaffa

MP: isNull or isPlayer

Recommended Posts

Hi

I have this little snippet I intened to use in a medical firstaid-kit script for Domination. When I try in singleplayer, it works fine. But when I try in multiplayer, the hint returns 'scalar' on both parts.

I guess it's the _med1-3 that doesn't get set properly so the adding up doesn't work. But why? Note that I have also tried isPlayer, but also then I'm ending up with an error. I was not testing with a medic at the time, but as long as one fails, I guess the whole maths fails, so it really shouldn't matter.

I should note that the script is run local to the player from an automatic action generation, no fuzz.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

       _med1 = isNull alpha_10;

       _med1 = if (_med1) then {1} else {0};

       _med2 = isNull bravo_3;

       _med2 = if (_med2) then {1} else {0};

       _med3 = isNull charlie_3;

       _med3 = if (_med3) then {1} else {0};

       _meds = _med1 + _med2 + _med3;

       _fact = 0.3-(_meds*0.05);

       _gain = _fact * (0.8+(random 0.2));

       hint format ["Factor = %1\nGain = %2",_fact,_gain];

       player setDamage ((damage player)-_gain);

And a side question, is it good practice to change variable contents as I do in the if statement(from bool to number), in order to reduce number of variables used? Or is it better to increase the variable count and maybe readability?

Edit:

For clarity: I'm testing this as only player on a dedi server with all tested slots being empty. I really only want a change to kick in if the tested slot has a human player, regardless if he is alive or not.

Share this post


Link to post
Share on other sites

Sounds like you need to do isNil checks instead. They'll probably never be null anyway, even if dead, but will probably be nil if not occupied.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_med1 = if (isNil "alpha_10") then {0} else {1};

Share this post


Link to post
Share on other sites

isNil seems to have done the trick. Thanks. Can't believe I didn't bother to try it, but the Biki on isNil at the time in this respect didn't make sense, so I discarted it. Now it doesn't.

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  

×