Jump to content

Recommended Posts

 

 

 

Hello everyone!

 

I've recently started my first very own A2:OA Dayz Epoch server. It's all going well and I'm loving it, so I was trying to make some improvements and learn SQF scripting. 

I've found this mod on this forum some time ago: https://github.com/FullyGored/Cherno-Train-Service and I decided to implement it on my server. It really worked well. The only thing I didnt like about it, is the fact that the wagon is actually the Ikarius bus, so that the players can actuall get in (because normal wagons are not "proper" vehicles - you can get inside of it by climbing the ladder but you can't sit inside of it like you do in a car). It just looked silly to me and wasn't really immersive, so I decided to do something about it.

 

So if you look at the Train_Start.sqf file, in line 32 it's actually spawning the Ikarius Bus. I replaced it with the wagon and added my custom init script to it.

_wf = "Land_wagon_box" createVehicle _pos;
_wf setVehicleInit "nul = this execVM ""scripts\Train\InitWagon.sqf"";";
processInitCommands;

 

which contains the following:

_this addAction ["<t color='#FF0000'>Get on the train</t>", "scripts\Train\GetOn.sqf", [], 6, true, true, "","alive _target"];

the GetOn.sqf just attaches the player to the wagon:

_wagon = _this select 0;
_action = _this select 2;

player removeAction _action;
player attachTo [_wagon, [1, -2, -0.85]];
player setDir 270;

player setVariable ["isOnTrain", true, true];

 

So, here comes my first problem: why does the action menu disappear once the user is attached to an object?

That would make the whole thing 10x easier, because I would just add an action to get off the train and the problem would be fixed.

 

I tried many approaches, trying to detect key presses, etc. Basically I've been fighting with this script for 2 weeks time and gotten almost there. User can get on the train but can't get off.

 

I tried doing this:

I introduce a public variable on the top of the script after line 4:

trainCurrentStation = "Berezino Start";
publicVariable "trainCurrentStation";

Then, on top, under line 19 I added all station names where the train stops (check _stops variable - it holds all rail names which should )

_stopNames = ["Berezino Station", "Berezino", "Nizhnoye", "Solnichiy", "Solnichiy Factory", "Solnichiy Factory 2", "Kamyshovo", "Skalisty", "Elektrozavodsk", "Prigorodki", "Chernogorsk", "Balota", "Komarovo", "Kamenka"];

So then, since the variables are not too descriptive, I figured I can add this piece of code to line 142 - to execute that code every train stop

if (_i in _stops) then {
	[_train] spawn _horn;
	_currentStop = _stopNames select _b;
	trainCurrentStation = _currentStop;
	publicVariable "trainCurrentStation";
};

 

And then, I added a script for the clients to init.sqf which, I assumed, would listen to the changes in the trainCurrentStation variable and then react to it

waitUntil { !(isNil "trainCurrentStation") };

"trainCurrentStation" addPublicVariableEventHandler {
	_station = _this select 1;
	_isOnTrain = player getVariable "isOnTrain";

	if (!isNil "_isOnTrain") then {
		_hintText = format ["Thank you for choosing Cherno train services.\n Current station: %1 \n If you'd like to continue your journey, get back on the train.", _station];
		titleText [_hintText, "PLAIN DOWN"];
		detach player;

		sleep .3;

		player setVariable ["isOnTrain", nil, true];
		player setVariable ["st_mh6_enhance_ffv_active",false];
	};
};

I put into the init.sqf this way:

if (!isDedicated) then {
	// other DayZ init scripts

	// init train scripts
	execVM "scripts\Train\clientInit.sqf";

	// other DayZ init scripts
}

 

But this script does basically nothing. No script errors in the console (I'm connecting with the -showScriptErrors parameter), players are still stuck on the train forever (or unless you abort and re-join the game).

The script is getting executed though! I tested that and it runs, but just does nothing for some reason.

 

Any clue what I'm doing wrong? Is there a better way of doing all this stuff? Any clue if I can find another workaround (or just enable the action menu when the player is attached to an object?).

 

I was thinking on attaching the player and then forcing the player to sit down in the train and then wait for the change in his stance (if he gets up, then detach from the train) but I'm not quite sure how to do that.

 

Sorry for the long post, hoping someone can help with it.

 

  • Like 1

Share this post


Link to post
Share on other sites

Thanks for the script man, I was actually looking fo it for some time!

 

Still, it would be great to display a message to the users, but the script doesn't seem to see the difference. PublicVariable handler goes completely ignored.

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

×