Jump to content
kammy23

help with this code

Recommended Posts

Quote

{if(!isPlayer _x && side _x != sideEnemy) then {
if (player distance _x <= 9) then 
    {
hint "close to enemy"
    } else
    {
hint "far away"
    };  
}}forEach allUnits;

So basically what i want to archive is when i run closer distance to enemy text should show up and if i move away far then it should show the text. its not working maybe it needs to be in loop also so it checks always.😢

Share this post


Link to post
Share on other sites
while {alive player} do
{
 sleep 0.3;
 if (((allUnits - allDeadMen) - allPlayers) select {side _x getFriend side player < 0.6} findIf {(player distanceSqr _x) < 81} > -1) then 
 {
  hint "close to enemy";
 }
 else hint "far away";
};

maybe this could work but it's not tested

 

better would be to attach a trigger to the player I think

Edited by sarogahtyp
typo

Share this post


Link to post
Share on other sites

Maybe your first condition

Quote

_x != sideEnemy

means the unit _x is not Enemy. Is it a typo in your copy/paste ?

Share this post


Link to post
Share on other sites
24 minutes ago, tanin69 said:

Maybe your first condition

means the unit _x is not Enemy. Is it a typo in your copy/paste ?

seems to be a typo but sideEnemy is not the enemy side. It's the team killers side!

 

see getFriend to get friendly or enemy side.

  • Like 1

Share this post


Link to post
Share on other sites
4 hours ago, sarogahtyp said:

while {alive player} do
{
 sleep 0.3;
 if (((allUnits - allDeadMen) - allPlayers) select {side _x getFriend side player < 0.6} findIf {(player distanceSqr _x) < 81} > -1) then 
 {
  hint "close to enemy";
 }
 else hint "far away";
};

maybe this could work but it's not tested

 

better would be to attach a trigger to the player I think

 

Doesnt the 'else' require a front bracket?

Share this post


Link to post
Share on other sites
1 minute ago, froggyluv said:

 

Doesnt the 'else' require a front bracket?

afaik there is no need for brackets for then or else part  if u have just one single command but maybe thats wrong...

Share this post


Link to post
Share on other sites
On 3/26/2019 at 6:08 PM, sarogahtyp said:

afaik there is no need for brackets for then or else part  if u have just one single command but maybe thats wrong...

There is..

else is a command that takes two pieces of code as argument. If you don't pass code (text between { and })  it will error.

 

On 3/26/2019 at 6:08 PM, sarogahtyp said:

but maybe thats wrong... 

Very easy to find out: https://community.bistudio.com/wiki/else

Share this post


Link to post
Share on other sites

Very easy to test!

 

if(alive player) then hint "yes";
else hint "no";

no error here. you don't need brackets if it is just one line.

Share this post


Link to post
Share on other sites
16 minutes ago, sarogahtyp said:

Very easy to test!

 


if(alive player) then hint "yes";
else hint "no";

no error here. you don't need brackets if it is just one line.

🤦‍♂️

 

No.. That's not how that works at all.

it executes in this order
hint "yes" (returns nil)
hint "no" (returns nil)
nil else nil (returns nil)

alive player (returns.... true?)

if (true) (returns ifType)

ifType then nil.

 

If you want to test then please test properly. If you do test properly you'll find that it does infact not work.

 

Commands that you give nil as argument will be silently ignored and will just return nil.
 

 

How did you test even? Your code cannot work at all, you have a semicolon after your hint "yes"
Meaning you are trying to call the else command with just one argument, which doesn't work. It's a binary command that needs two arguments.

  • Thanks 1

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

×