Jump to content

vehicle GetIn event


horbin

Recommended Posts

I am trying to set up a notification to players, such that when they enter a vehicle that is temporary (created from an encounter, for example) they get a message that tells them this fact.

 

Anyone know of an easy way to do this?  I have attempted the follow: (see below) but no chat messages are being sent to the client. I do see the log message on the server so I know it is firing.

  tellthem = 
        { 
             systemChat _this select 0;
            hint (_this select 0);
            diag_log format ["%%%%% tellthem executed"];
         };
        _veh addEventHandler ["GetIn",
        { 
            // _this select 2 needs to be owner id
            _owner = owner (_this select 2);
            _nil = ["Warning: Vehicle Will Disappear on Restart!","tellthem",_owner,false,false] call BIS_fnc_MP;
            diag_log format ["#### EH GetIn called for %1 entering %2", _owner, _this select 0];
        }];

idea pulled from VEMF.

Link to comment
Share on other sites

Assign a Variable to each vehicle:

_veh setVariable ["TEMP",true,true];  //[Var_Name,Var_Value,Public_to_all_players]

In Mission Folder, init.sqf add:
 

WarnPlayer_Veh = {
   [] spawn {
      while {true} do {
         waituntil{vehicle player != player};
         if ((vehicle player != player) && ((vehicle player) getVariable "TEMP")) then {
            systemchat("Warning: This vehicle will disappear on restart!");
         };
         waituntil{vehicle player == player};
      };
   };
};

call WarnPlayer_Veh;
player addEventHandler ["Respawn", {call WarnPlayer_Veh;}];

//Have not tested.. but you get the gist

Link to comment
Share on other sites

Thanks for the input.  Could not get it to fire, nor some other variations using "Init".

 

Went with this approach which is working well.

 

In the code that creates the vehicle I add: (this runs on the server!)

_veh addEventHandler ["GetIn",
        {
            _vehobj = _this select 0;
            _vehseat = _this select 1;
            _owner = _this select 2;
            _idowner = owner _owner;
            TEMPVEHICLE = true;
            _idowner publicVariableClient "TEMPVEHICLE";
        }];

Then in my "is a player" portion of my 'Init.sqf' I have the following:

"TEMPVEHICLE" addPublicVariableEventHandler
{
    systemChat "Warning! This vehicle will disappear on server restart!";
};
Link to comment
Share on other sites

 

Thanks for the input.  Could not get it to fire, nor some other variations using "Init".

 

Went with this approach which is working well.

 

In the code that creates the vehicle I add: (this runs on the server!)

_veh addEventHandler ["GetIn",
        {
            _vehobj = _this select 0;
            _vehseat = _this select 1;
            _owner = _this select 2;
            _idowner = owner _owner;
            TEMPVEHICLE = true;
            _idowner publicVariableClient "TEMPVEHICLE";
        }];

Then in my "is a player" portion of my 'Init.sqf' I have the following:

"TEMPVEHICLE" addPublicVariableEventHandler
{
    systemChat "Warning! This vehicle will disappear on server restart!";
};

This seems to be more eloquent than my code... nice work

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...