Jump to content

Recommended Posts

Hello. When I try to add an event handler to a newly spawned vehicle, the event handler is NOT working. 

[_helicopter] remoteExec ["jey_helicopter_restriction",0,true];

jey_helicopter_restriction =
{
	_vehicle = _this select 0;
	_vehicle addEventHandler ["GetIn",{_this call checkpilot}];
	_vehicle addEventHandler ["Engine",{_this call checkengine}];
};

But if I add an event handler to an already spawned vehicle (that has been there from the mission start) it works :

chopp3 addEventHandler ["GetIn",{_this call checkpilot}];
chopp3 addEventHandler ["Engine",{_this call checkengine}];

Any ideas?

Share this post


Link to post
Share on other sites

define the function first:


 

jey_helicopter_restriction = {
  _vehicle = _this select 0;
  _vehicle addEventHandler ["GetIn",{_this call checkpilot}];
  _vehicle addEventHandler ["Engine",{_this call checkengine}];
};

[_helicopter] remoteExec ["jey_helicopter_restriction",0,true];

 

Share this post


Link to post
Share on other sites

I used call compile preprocessfilelinenumbers before I used the functions. It's already defined.

Share this post


Link to post
Share on other sites

How do you try it?  SP? MP hosted? dedicated?  I can't reproduce the problem replacing the checKpilt and checkEngine by a simple hint...

If you can pass more info...

Share this post


Link to post
Share on other sites

How do you try it?  SP? MP hosted? dedicated?  I can't reproduce the problem replacing the checKpilt and checkEngine by a simple hint...

If you can pass more info... what about _helicopter also. Are you sure it returns an object?

Share this post


Link to post
Share on other sites

Dedicated.

 

//This whole file is compiled, so the function call is already known to the clients and server.

[_helicopter] remoteExec ["jey_helicopter_restriction",0,true]; //With the true paramter it should work for every JIP right?

jey_helicopter_restriction =
{
	_vehicle = _this select 0;
	_vehicle addEventHandler ["GetIn",{_this call checkpilot}];
	_vehicle addEventHandler ["Engine",{_this call checkengine}];
};



//somewhere else (also compiled)

checkpilot = 
{
  _vehicle = _this select 0;
  _seat = _this select 1;
  _player = _this select 2;

    if(_seat == "driver") then 
      {
        if (typeOf _player != "rhsusf_army_ocp_helipilot")
          then
          {
            moveOut _player;
          };
      };
};
checkengine = 
{
  _vehicle = _this select 0;
  _pilot = driver _vehicle;

  if ((typeOf _pilot != "rhsusf_army_ocp_helipilot") || isNull _pilot)
    then {
    _vehicle engineOn false; 
  };
};
//Where _helicopter is a newly spawned object. And yes it is an object and I am sure it is returned. Here look:
//_helicopter = "classname" createvehicle blablabla

 

Share this post


Link to post
Share on other sites
call compile "
  [car1] remoteExec ['jey_helicopter_restriction',0,true];
  jey_helicopter_restriction = {
    _vehicle = _this select 0;
    _vehicle addEventHandler ['GetIn',{hint str _this}];
   _vehicle addEventHandler ['Engine',{hint str _this }];
  };
"

doesn't work.

 

call compile "
  jey_helicopter_restriction = {
    _vehicle = _this select 0;
    _vehicle addEventHandler ['GetIn',{hint str _this}];
   _vehicle addEventHandler ['Engine',{hint str _this }];
  };
  [car1] remoteExec ['jey_helicopter_restriction',0,true];
"

 

work.

Share this post


Link to post
Share on other sites

I still don't understand. If you compile it, why would the order matter?

Share this post


Link to post
Share on other sites

Not expert sorry, so it's a discussion, not an affirmation.

I guess you're compiling something wrong in the same scope.

You could compile your jey_helicopter_restriction only, then call/remoteExec this function in a sqf... or compile something workable at once.

Not tested, but this should be the same with cfgFunctions classes : if a function depends on another one, it must be written below (after) in order to refer it.

May be I'm wrong. I hope some more skilled remarks also.

Share this post


Link to post
Share on other sites

What do you mean when you say, for the top part, that that file is compiled for everyone. You mean you "call compile" it? In that case you would run the remoteExec once for EACH player and the server, and thus add too many event handlers.

 

Are checkpilot and checkengine compiled by everyone, or just the server?

Share this post


Link to post
Share on other sites

Everyone, but it's working now. SO that's what matters.

Share this post


Link to post
Share on other sites

Like muzzleflash said you'll end up with the same command getting spammed several times which can lead to all sort of funky problems later on, depending on your other code.

 

On 3.11.2017 at 12:45 PM, JeyR said:

I still don't understand. If you compile it, why would the order matter?

Read (in this order):

https://community.bistudio.com/wiki/preprocessFileLineNumbers (returns string)

https://community.bistudio.com/wiki/compile (returns code)

https://community.bistudio.com/wiki/call (runs code)

 

None of that magically scans your code for functions and then pre-defines them.

The code is run as is and if you have your things in the wrong order there, it wont work.

 

Also, if you want to define your functions properly, read this aswell:

https://community.bistudio.com/wiki/Functions_Library_(Arma_3)

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

×