Jump to content
Sign in to follow this  
belkon

Someone please help me with this script!

Recommended Posts

sleep (1 + (random 4));
_shooter = _this select 0;
_weapon = _this select 1;
_muzzle = _this select 2;
_ammo = _this select 4;
_vehicle = _this select 6;
_oldLeader = "";
_newLeader = "";
_shooterpos = position _shooter;
//systemChat format ["%1 shot a %2 loaded with %4 and a caliber of %3 in a %5",_shooter,_weapon,_muzzle,_ammo,_vehicle];
if (side _shooter == playerSide) then {
    _nearppl = _shooter nearEntities ["Man", 1000]; 
    {
        _newLeader = leader _x;
		// THIS IS WHERE THE EXECUTION ENDS - ANYTHING BELOW HERE DOESN'T WORK
        if (_oldLeader == _newLeader) then {systemChat "Nah";}
        else {
            systemChat "Yes";
            _group = group _x;
            _oldLeader = leader _group;
            systemChat format ["%1 heard that and is on his way", _oldLeader];
        };
    } forEach _nearppl;
};

So basically what's calling this script is a "FiredMan" handler defined here

PlayerShootsEH = player addEventHandler ["FiredMan", {[_this select 0,_this select 1,_this select 2,_this select 4,_this select 6] spawn EH_Hunt}];

I can't seem to figure out why it doesn't want to pass the "if (_oldLeader == _newLeader)" statement.

Share this post


Link to post
Share on other sites
        if (_oldLeader == _newLeader) then {systemChat "Nah";}

At first glance, you might want to lose that semicolon inside the then statement. Do you have showScriptErrors enabled? What does your .rpt say, if anything?

 

Also, this topic would fare better in the Scripting & Editing forum.

 

 

Share this post


Link to post
Share on other sites

The semicolon shouldn't be a problem.

 

I'm not sure what you're trying to achieve with the _oldLeader vs _newLeader check but somehow I don't think it makes sense.

If you want to make sure that it doesn't trigger multiple times per group ok, but your example would not work well if there is more than 1 group nearby.

 

Checking the side of the shooter against playerside also seems rather pointless to me, since the EH is attached to the player.

 

On 5.10.2017 at 2:26 AM, belkon said:

// THIS IS WHERE THE EXECUTION ENDS - ANYTHING BELOW HERE DOESN'T WORK

What does that mean, do you get an error? Otherwise one of the two systemChats should be visible.

 

 

 

Oh and you can handle those parameters a lot easier. I've modified it a bit, hope I understood your intentions correctly:

PlayerShootsEH = player addEventHandler ["FiredMan", {_this spawn EH_Hunt}];

and this:

sleep (1 + (random 4));
params["_shooter","_weapon","_muzzle","_mode","_ammo","_mag","_projectile","_vehicle"];

_nearppl = _shooter nearEntities ["Man", 1000];
_leaders = _nearppl apply {leader _x}; // convert it into an array consisting only of groupleaders
_leaders = _leaders arrayIntersect _leaders; // make the array unique so each leader is only listed once

{
	systemChat format ["%1 heard that and is on his way", _x];
} forEach _leaders;

 

  • Thanks 1

Share this post


Link to post
Share on other sites
5 hours ago, Tajin said:

The semicolon shouldn't be a problem.

 

Yeah, it just seemed out of place/unnecessary. Wasn't sure if it would actually cause a problem.

Share this post


Link to post
Share on other sites
6 hours ago, Tajin said:

The semicolon shouldn't be a problem.

 

I'm not sure what you're trying to achieve with the _oldLeader vs _newLeader check but somehow I don't think it makes sense.

If you want to make sure that it doesn't trigger multiple times per group ok, but your example would not work well if there is more than 1 group nearby.

 

Checking the side of the shooter against playerside also seems rather pointless to me, since the EH is attached to the player.

 

What does that mean, do you get an error? Otherwise one of the two systemChats should be visible.

 

 

 

Oh and you can handle those parameters a lot easier. I've modified it a bit, hope I understood your intentions correctly:


PlayerShootsEH = player addEventHandler ["FiredMan", {_this spawn EH_Hunt}];

and this:


sleep (1 + (random 4));
params["_shooter","_weapon","_muzzle","_mode","_ammo","_mag","_projectile","_vehicle"];

_nearppl = _shooter nearEntities ["Man", 1000];
_leaders = _nearppl apply {leader _x}; // convert it into an array consisting only of groupleaders
_leaders = _leaders arrayIntersect _leaders; // make the array unique so each leader is only listed once

{
	systemChat format ["%1 heard that and is on his way", _x];
} forEach _leaders;

 

The reason for the _shooter playerSide check is because I'm planning on adding the event handler to other AI units aswell. The script you wrote seems to suite exactly what I need to be done. Thanks

Share this post


Link to post
Share on other sites
9 hours ago, Tajin said:

and this:


sleep (1 + (random 4));
params["_shooter","_weapon","_muzzle","_mode","_ammo","_mag","_projectile","_vehicle"];

 

 

I should also thank you for waking me up to params. So much easier!

  • Like 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
Sign in to follow this  

×