Jump to content
Sign in to follow this  
shadow

Eventhandler issue

Recommended Posts

I cannot for the life of me get the eventhandlers for the viewdistances to work. I've modified an existing respawn-script to include the EHs for changing viewdistance and if you're not a pilot you get kicked out. The latter works fine. Its just the viewdistance that dont work.

Any ideas?

Quote[/b] ]//*****************************************************

//** Operation Flashpoint Script File

//*****************************************************

//BEGIN vrs_AI.sqf

//Original script by KaRRiLLioN modified by norrin for AI units 7th Feb 2007

//IMPORTANT: ADD A GAMELOGIC NAMED Server

//to the mission to prevent multispawn

private ["_vcl","_respawndelay","_vclemptydelay","_dir",&q

uot;_pos","_type","_unit","_run","_wait",&quo

t;_delay"];

if (!local Server) exitWith {};

_vcl = _this;

//specify the respawn wait times for empty vehicles and destroyed vehicles in the following 2 lines

_vclemptydelay = 7200;

_respawndelay = 1;

_dir = getDir _vcl;

_pos = getPos _vcl;

_type = typeOf _vcl;

_unit = driver _vcl;

sleep 5;

while {true} do {

while {_vcl distance _pos < 5 && canMove _vcl} do {

sleep 1;

};

while {canMove _vcl && count crew _vcl > 0 && ({damage _x}forEach crew _vcl)!= 1} do {

_wait = Time + _vclemptydelay;

sleep 1;

};

while {canMove _vcl && count crew _vcl < 1 && Time < _wait} do {

sleep 1;

};

while {canMove _vcl && {damage _x} forEach crew _vcl >= 1 && Time < _wait} do {

sleep 1;

};

_delay = Time + _respawndelay;

while {!canMove _vcl && Time < _delay} do {

sleep 1;

};

if (count crew _vcl < 1) then {

deleteVehicle _vcl;

_vcl = _type createVehicle _pos;

_vcl addEventHandler ["getin",{if(player==_this select 2) then {setViewDistance 3000;setTerrainGrid 25;}}];

_vcl addEventHandler ["getout",{if(player==_this select 2) then {setViewDistance 1200;setTerrainGrid 12.5;}}];

_vcl addeventHandler ["getin",{if ((typeof (_this select 2)!="SoldierWPilot") and (_this select 1=="driver")) then {_this select 2 action ["getout",_this select 0]}}];

_vcl setdir _dir;

sleep 1;

_vcl setvelocity [0,0,0];

_vcl setpos _pos;

sleep 1;

_vcl setvelocity [0,0,0];

sleep 2;

};

if ({damage _x} forEach crew _vcl >= 1)then {

deleteVehicle _vcl;

_vcl = _type createVehicle _pos;

_vcl addEventHandler["getin",{if(player==_this select 2) then {setViewDistance 3000;setTerrainGrid 25;}}];

_vcl addEventHandler["getout",{if(player==_this select 2) then {setViewDistance 1200;setTerrainGrid 12.5;}}];

_vcl addeventHandler ["getin",{if ((typeof (_this select 2)!="SoldierWPilot") and (_this select 1=="driver")) then {_this select 2 action ["getout",_this select 0]}}];

_vcl setdir _dir;

sleep 1;

_vcl setvelocity [0,0,0];

_vcl setpos _pos;

sleep 1;

_vcl setvelocity [0,0,0];

sleep 1;

};

sleep 2;

};

Share this post


Link to post
Share on other sites

you're runing it on the SERVER only aren't you?

the 'Client' won't 'see' the event happen... maybe, ugh, it's late, sorry I'm probably wrong...

Share this post


Link to post
Share on other sites

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if (!local Server) exitWith {};

Means it runs on the server only.Donno,what is the return for "player" on a server?

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_vcl addEventHandler ["getin",{if(player==_this select 2) then {setViewDistance 3000;setTerrainGrid 25;}}];

Maybe try to run this code local?

Share this post


Link to post
Share on other sites

Yes, the script is run on server-side only, but the EH for getting kicked out works.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_vcl addeventHandler ["getin",{if ((typeof (_this select 2)!="SoldierWPilot") and (_this select 1=="driver")) then {_this select 2 action ["getout",_this select 0]}}];

Basicly, everything works as it should untill the aircraft respawn. Then the view-EHs dont work, but SoldierWPilot is still the only type that can pilot the aircraft.

Quote[/b] ]Maybe try to run this code local?

How can I do that when I dont know the unitname?

Share this post


Link to post
Share on other sites

Your eh for the pilot bit...

That works 'cause even though it's registered server-side your telling and specific unit to do a specific action... and actions get 'broadcast'.

Where as your 'viewdistance' eh is not telling a specific unit to change it's viewdistance it's saying 'ok a unit got in the chopper' i'm going to set the viewdistance locally (in this case on the server) which of course doesn't get seen by the clients...

so, i reckon you need to run this script locally... as patton said.

edit: also, you may want to check out the 'vehicleRespawn' command... I updated the biki early 'cause it does actually work... it may be 'relevant' to your respawning of vehicles...

probably the easiest thing to do would be just add your <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_vcl addEventHandler ["getin",{if(player==_this select 2) then {setViewDistance 3000;setTerrainGrid 25;}}];

to all the init lines for the vehicles in question... then they'll be there on every client...

Share this post


Link to post
Share on other sites

Thats an option Synide,but I am afraid it wont work on respawning vehicles...

Mp,respawning vehicles and eventhandlers...,not simple.

Nothing to test on here,so what happens:

--1--:_vcl addEventHandler ["getin",{setViewDistance 3000;setTerrainGrid 25}];

Does this only run for he who got in or for everybody?

--2--:_vcl addEventHandler ["getin",{_this exec "script.sqs"}];

script.sqs:

_enterer = _this select 2

?(player != _enterer):exit

setViewDistance 3000;setTerrainGrid 25

exit

Does this runs everywhere,alltho executed within server only scope?Or write this line above the ""if (!local Server) exitWith {};""

--3--:_vcl setVehicleInit "EH stuff here"

Does this make your EH work on a respawned vehicle?

Share this post


Link to post
Share on other sites

You have to assign the getin event handler on all clients. If you want the event to execute for all the clients.

Quote[/b] ]Then the view-EHs dont work, but SoldierWPilot is still the only type that can pilot the aircraft.

The events are just being called server side. Thats why the GetOut action still works. Any AI getting in and out of the vehicle is also local to the server, unless it's part of your group, then it's local to you.

Quote[/b] ]How can I do that when I dont know the unitname?

Yeah, because you have to create your vehicle only on the server. It used to be a problem in OFP. But now you can do this:

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

_InitString="This addEventHandler [""getin"",{if(player==_this select 2) then {setViewDistance 3000;setTerrainGrid 25;}}]; This addEventHandler [""getout"",{if(player==_this select 2) then {setViewDistance 1200;setTerrainGrid 12.5;}}]; This addeventHandler [""getin"",{if ((typeof (_this select 2)!=""SoldierWPilot"") and (_this select 1==""driver"")) then {_this select 2 action [""getout"",_this select 0]}}];";

_vcl SetVehicleInit _InitString;

processInitCommands;

_vcl SetVehicleInit "";

Now the event handlers will be assigned to all clients from the Server.

P.S I think you should add two functions to handle the GetIn and GetOut event code. It would make the code easier to read.

Share this post


Link to post
Share on other sites

UNN,

I just got done spending hours struggling with this until I got mine to work. I wish I would have read this thread before then. However, my next task is proving this will work for JIP as well.

The plan is to delete the following line.

Quote[/b] ]_vcl SetVehicleInit "";

Then you might be able to have your JIP clients run ProcessInitCommands; which of course is reported to only work once so it should only fire the ones that haven't been fired on the new client. This assumes that the JIP client will receive the new vehicle along with its INIT line intact upon connection.

I have NOT tested this yet because its bed time. But I will. My question is in case you guys have tested it already...

How do you handle JIP after using UNN's code?

Share this post


Link to post
Share on other sites

I second Maul's post.

Also, I personally would execute the processInitCommands after finishing creating all the setVehicleInit's so they can be sent in 1 burst over the network.

Share this post


Link to post
Share on other sites

Yeah, JIP is another thing all together. I've not begun to mess around with that. I think I will have to be careful how I use ProcessInitCommands.

But it's such a useful command for running scripts across the network, I would like to be able to use it as and when required. One thing I noticed was, only using set VehicleInit on the server, then running ProcessInitCommands on the client, had no effect. So there is some locality, if you can just use the server to handle the JIP's?

Quote[/b] ]Then you might be able to have your JIP clients run ProcessInitCommands; which of course is reported to only work once so it should only fire the ones that haven't been fired on the new client.

Yeah, it did only run once per object. I could then reset it with the empty string or execute another batch of code. One thing to test is, are all the ProcessInitCommands stored in anticipation of a JIP player. Or will you have to run the command, everytime a player connects?

Quote[/b] ]This assumes that the JIP client will receive the new vehicle along with its INIT line intact upon connection.

From what I mentioned above about locality, I'm not so sure it will. But how much of a vehicle is sent to a JIP player, is another thing for me to test to.

Quote[/b] ]The plan is to delete the following line.

I did have my doubts about this line. By casually clearing the InitCommands, you might screw up someone else’s code used in another script or addon. It would be nice if you could read the assigned initCommands, so you can restore any you remove. But you may not want\need to leave code sat around in the InitCommands. For example, Shadow could assign his events from the client thats joining using the vehicles command.

Im approaching this from the direction of addon scripting, as opposed to mission scripting, for now. The problem Shadow had, would not be an issue, as you can assign your events from the addons config.

I'm looking at having to use three or four different methods to communicate all the info I want to a JIP player. JIP is certainly going to complicate things, in a good way.

Share this post


Link to post
Share on other sites

It's kinda simple... you must execute processInitCommands on the machine where you executed setVehicleInit, which would be the server for me in any cases. AFAIK when a client JIP's he receives the data, without the need to execute the: ProcessInitCommands; again on the server but it should indeed be tested smile_o.gif

Share this post


Link to post
Share on other sites
Nothing to test on here,so what happens:

--1--:_vcl addEventHandler ["getin",{setViewDistance 3000;setTerrainGrid 25}];

Does this only run for he who got in or for everybody?

Doesnt change the viewdistance at all.

Quote[/b] ]--2--:_vcl addEventHandler ["getin",{_this exec "script.sqs"}];

script.sqs:

_enterer = _this select 2

?(player != _enterer):exit

setViewDistance 3000;setTerrainGrid 25

exit

Tried this in the editor only. It runs the script (added a hint"" to make sure), but viewdistance and terrain is not changed. I guess it changes the values for the vehicle and not the player.

--3--:_vcl setVehicleInit "EH stuff here"

Does this make your EH work on a respawned vehicle?/QUOTE]

I'm sorry, but I dont understand what you mean.

I'm a total noob when it comes to EHs and SQF (so I'm really having a blast now...not).

Thanks for explaining why the viewdistance is not translated to the player, Synide. Makes perfect sense why it doesnt work now.

UNN, I'm not sure I understand your script-sample.

Where would I put this?

UNN, Vipermaul and Sickboy are scaring me help.gif

By the way, I already have all EHs working for JIP-players. Its just the part when a vehicle has respawned I'm having trouble with.

I am running the EHs in init.sqs plus this in init.sqs for JIP-players

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">? (local host) : onplayerconnected "[] exec ""viewdist.sqs"" "

viewdist.sqs just contain the 3 EHs and nothing else.

I would like to thank you all for taking the time to look into this.  smile_o.gif

Share this post


Link to post
Share on other sites

I've commented out the code it's supposed to replace. I also removed the blank InitCommand for now.

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

//** Operation Flashpoint Script File

//*****************************************************

//BEGIN vrs_AI.sqf

//Original script by KaRRiLLioN modified by norrin for AI units 7th Feb 2007

//IMPORTANT: ADD A GAMELOGIC NAMED Server

//to the mission to prevent multispawn

private ["_vcl","_respawndelay","_vclemptydelay","_dir","_pos","_type","_unit","_run","_wait","_delay"];

if (!local Server) exitWith {};

_vcl = _this;

//specify the respawn wait times for empty vehicles and destroyed vehicles in the following 2 lines

_vclemptydelay = 7200;

_respawndelay = 1;

_dir = getDir _vcl;

_pos = getPos _vcl;

_type = typeOf _vcl;

_unit = driver _vcl;

sleep 5;

while {true} do {

while {_vcl distance _pos < 5 && canMove _vcl} do {

sleep 1;

};

while {canMove _vcl && count crew _vcl > 0 && ({damage _x}forEach crew _vcl)!= 1} do {

_wait = Time + _vclemptydelay;

sleep 1;

};

while {canMove _vcl && count crew _vcl < 1 && Time < _wait} do {

sleep 1;

};

while {canMove _vcl && {damage _x} forEach crew _vcl >= 1 && Time < _wait} do {

sleep 1;

};

_delay = Time + _respawndelay;

while {!canMove _vcl && Time < _delay} do {

sleep 1;

};

if (count crew _vcl < 1) then {

deleteVehicle _vcl;

_vcl = _type createVehicle _pos;

//_vcl addEventHandler ["getin",{if(player==_this select 2) then {setViewDistance 3000;setTerrainGrid 25;}}];

//_vcl addEventHandler ["getout",{if(player==_this select 2) then {setViewDistance 1200;setTerrainGrid 12.5;}}];

//_vcl addeventHandler ["getin",{if ((typeof (_this select 2)!="SoldierWPilot") and (_this select 1=="driver")) then {_this select 2 action ["getout",_this select 0]}}];

//UNN - Start adding lines here

_InitString="This addEventHandler [""getin"",{if(player==_this select 2) then {setViewDistance 3000;setTerrainGrid 25;}}]; This addEventHandler [""getout"",{if(player==_this select 2) then {setViewDistance 1200;setTerrainGrid 12.5;}}]; This addeventHandler [""getin"",{if ((typeof (_this select 2)!=""SoldierWPilot"") and (_this select 1==""driver"")) then {_this select 2 action [""getout"",_this select 0]}}];";

_vcl SetVehicleInit _InitString;

processInitCommands;

//UNN - End adding lines here

_vcl setdir _dir;

sleep 1;

_vcl setvelocity [0,0,0];

_vcl setpos _pos;

sleep 1;

_vcl setvelocity [0,0,0];

sleep 2;

};

if ({damage _x} forEach crew _vcl >= 1)then {

deleteVehicle _vcl;

_vcl = _type createVehicle _pos;

//_vcl addEventHandler["getin",{if(player==_this select 2) then {setViewDistance 3000;setTerrainGrid 25;}}];

//_vcl addEventHandler["getout",{if(player==_this select 2) then {setViewDistance 1200;setTerrainGrid 12.5;}}];

//_vcl addeventHandler ["getin",{if ((typeof (_this select 2)!="SoldierWPilot") and (_this select 1=="driver")) then {_this select 2 action ["getout",_this select 0]}}];

//UNN - Start adding lines here

_InitString="This addEventHandler [""getin"",{if(player==_this select 2) then {setViewDistance 3000;setTerrainGrid 25;}}]; This addEventHandler [""getout"",{if(player==_this select 2) then {setViewDistance 1200;setTerrainGrid 12.5;}}]; This addeventHandler [""getin"",{if ((typeof (_this select 2)!=""SoldierWPilot"") and (_this select 1==""driver"")) then {_this select 2 action [""getout"",_this select 0]}}];";

_vcl SetVehicleInit _InitString;

processInitCommands;

//UNN - End adding lines here

_vcl setdir _dir;

sleep 1;

_vcl setvelocity [0,0,0];

_vcl setpos _pos;

sleep 1;

_vcl setvelocity [0,0,0];

sleep 1;

};

sleep 2;

};

The added commands are just applying the AddEvents from your original script. Only this way you make sure the events are added to every client.

Share this post


Link to post
Share on other sites

It doesnt respawn at all now and I got this during mission-start:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">Error in expression <"_respawndelay","_vclemptydelay","_dir",&q

uot;_pos","_type","_unit","_run","_wa>

 Error position: <&q

uot;_pos","_type","_unit","_run","_wa>

 Error Invalid number in expression

File mpmissions\__CUR_MP.Sara\vrs.sqf, line 10

For some reason the first part of my script was screwed when I pasted it in here in the first place.

It should read like this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">private ["_vcl","_respawndelay","_vclemptydelay","_dir","_pos","_type","_unit","_run","_wait","_delay"];

Trying again.

Edit again. Arma doesnt like IB-code, go figure...

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

Thats awesome, UNN!!!

Your modifications works perfectly, even with JIP.

Now I just need to learn the whys and hows inlove.gif

I removed the errors in your script-post so others can just copy the entire script.

Share this post


Link to post
Share on other sites
Quote[/b] ]Edit again. Arma doesnt like IB-code, go figure...

Lol..Sorry. I tried to highlight the code additions, did not work so I thought I removed them all.

Glad to hear it works ok now. Did a bit of experimenting with JIP and the processInitCommands myself.

As sickboy said, processed InitCommands are stored for when someone JIPs.

It will even remember any InitCommands for units that are killed or have been deleted during the mission. Not sure what’s returned with This if the unit has been deleted, forgot to check that. But it should be easy enough to add a condition to the code, to check for such things. It could be problematic in long missions with lots of spawning, but I hope the new clearVehicleInit command will sort that out.

You can add multiple SetVehicleInit lines, so no worries about clashing with other scripts.

Share this post


Link to post
Share on other sites
It could be problematic in long missions with lots of spawning, but I hope the new clearVehicleInit command will sort that out.

I'll soon find out. I have a test-version of my mission running 24/7 on my server now. Voting is disabled so noone can restart or change the mission.

Share this post


Link to post
Share on other sites

@Shadow... no worries... When ever I look at a glob of script I think to myself 'in what context is this script running' I find asking myself that question constantly as I'm reading through script helps alot.

lol, Shadow... are you refering to 'Black Eagle' Coop mission running on 'Shadows playground'? which I can't join... 'cause... it's 1.08?

Share this post


Link to post
Share on other sites

@UNN...

So, what your saying is...?

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

v setVehicleInit a;

........

b = "some more init stuff";

v setVehicleInit b;

It concatenates all the setVehicleInit's for a vehicle and right at the end you'd do a 'processInitCommands;' ?

Is that correct?

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  

×