Jump to content
Sign in to follow this  
{USI}_Zombie

tweaking an old script

Recommended Posts

I used the following script in OFP:R without problems but have an issue now in A2:

;;criteria for starting jump distance is 1 meter as height
?((getpos _vcl select 2) < 1) : goto "speedloop"
;;player sidechat "measuring jump distance"
_startgl = "Logic" camcreate getpos _vcl
@ ((getpos _vcl select 2) < 1)
_dx = (getpos _startgl select 0) - (getpos _vcl select 0)
_dy = (getpos _startgl select 1) - (getpos _vcl select 1)
_dist = sqrt ((_dx * _dx) + (_dy * _dy));
deletevehicle _startgl

(driver _vcl) globalchat format ["%2  jumped %1 meters!!!",_dist, name driver _vcl]

It appears to run, but gives a jump distance of something like 11355.49 for example, it does change, when we obviously aren't jumping that far. Any ideas? Thanks

Share this post


Link to post
Share on other sites

I think read somewhere that you can't create game logics with createvehicle anymore in A2, so might be same for camcreate.

Share this post


Link to post
Share on other sites

I have gotten this script working now reliably, but I have another problem. It reports 1 distance to the player, but broadcasts a slightly different distance to other players. Do I need to use global variables? or public variables? ideas? It seems I am creating the gamelogics reliably, so the original probably had an issue with camcreate or the createvehiclelocal fixed the issue, didn't try just createvehicle.

_vcl = _this select 0

#speedloop
?((getpos _vcl select 2) < 1) : goto "speedloop"
(driver _vcl) sidechat "measuring jump distance"
_startgl = "logic" createvehiclelocal getpos _vcl
@ ((getpos _vcl select 2) < 1)
_landlogic = "logic" createvehiclelocal getpos _vcl

;;note next 2 lines work and don't need all the math
_dist = _startgl distance _landlogic
_distr = round _dist

;;note, this is the old way don't remember why all the math was needed, maybe if jumping downhill?
;;_dx = (getpos _startgl select 0) - (getpos _vcl select 0)
;;_dy = (getpos _startgl select 1) - (getpos _vcl select 1)
;;_dist = sqrt ((_dx * _dx) + (_dy * _dy))

(driver _vcl) sidechat format ["%2  jumped %1 meters!!!",_distr, name driver _vcl]
;;note don't remember why this delay was needed in the first place but it doesn't seem to cause any problems
~4
deletevehicle _startgl
deletevehicle _landlogic
Goto "speedloop"

#end
Exit

Edited by {USI}_Zombie

Share this post


Link to post
Share on other sites

Hi :)

please try the following script.

It's not tested yet because I'm at work :(

private ["_vlc","_startgl","_landlogic","_action"];

_vcl = _this select 0;_startgl = objNull;_landlogic = objNull;mDistance = -1;_action = true;

if(isServer) then
{
_startgl = "logic" createvehiclelocal [0,0];
_landlogic = "logic" createvehiclelocal [0,0];
while{_action} do
{
	sleep 0.01;
	if((position _vcl select 2) >= 1) then
	{
		mDistance = 0;publicvariable "mDistance";
		if(local player) then {player sidechat "measuring jump distance"};
		_startgl setpos position _vcl;
		waituntil{((position _vcl select 2) < 1)};
		_landlogic setpos position _vcl;
		mDistance =  round(_startgl distance _landlogic);
		publicvariable "mDistance";
		if(local player) then {player sidechat format ["%2  jumped %1 meters!!!",mDistance, name driver _vcl]};
		sleep 1;
	}
	else
	{
		if((getdammage _vcl) == 1) then
		{
			_action = false;
			if(local player) then {player sidechat "vehicle destroyed"};
			exitwith {{deletevehicle _x}foreach [_startgl,_landlogic]};
		};
	};
};
}
else
{
while{_action} do
{
	waituntil{(mDistance > -1) || ((getdammage _vcl) == 1)};
	if(mDistance > -1) then
	{
		player sidechat "measuring jump distance";
		waituntil{(mDistance > 0)};
		player sidechat format ["%2  jumped %1 meters!!!",mDistance, name driver _vcl];
		mDistance = -1;
		sleep 1;
	}
	else
	{
		player sidechat "vehicle destroyed";_action = false;
	};
};
};

Greeting

Silola

Share this post


Link to post
Share on other sites

Thanks Silola, but many problems. If I try to call the script like this

this execvm "jumpdistance.sqf"

from the units initialization the editor says:

Type script, expected nothing

If I try

this exec "jumpdistance.sqf"

I get many errors in the .rpt and it doesn't work because sqf's have to be execvm'd (right?).

Do I need to call the script in the init? I also use the following in each vehicle's initialization

this addEventHandler ["HandleDamage", {false}];  this AddAction ["Turbo On","RTS3-VCL-TurboOn.sqs"];this AddAction ["Brake","brake.sqs"];

so I don't need the getdammage section

Share this post


Link to post
Share on other sites

Hi,

You have to start the script like this (Init line):

check = this execVM "jumpdistance.sqf"

Greeting

Silola

*edit* I have missunderstand your script I think :-/

I had thought that you want to check a single vehicle and then send the results to all clients.

Edited by Silola

Share this post


Link to post
Share on other sites
*edit* I have missunderstand your script I think :-/

I had thought that you want to check a single vehicle and then send the results to all clients.

That is what I want to do, but there are many vehicles to choose from and up to 8 players in the map

Share this post


Link to post
Share on other sites

Hi,

if you get an error, first try this little change:

check = [this] execVM "jumpdistance.sqf"

Greeting

Silola

Share this post


Link to post
Share on other sites

this is how I called the script then:

this addEventHandler ["HandleDamage", {false}];  this AddAction ["Turbo On","RTS3-VCL-TurboOn.sqs"];this AddAction ["Brake","brake.sqs"]; ;check = this execVM "jumpdistance.sqf"

it also didn't work with

check = [this] execVM "jumpdistance.sqf"

It doesn't work and gives me the following errors in the rpt

Error in expression <sidechat "vehicle destroyed"};
exitwith {{deletevehicle _x}foreach [_startgl,_la>
 Error position: <{{deletevehicle _x}foreach [_startgl,_la>
 Error Missing ;
File E:\Documents and Settings\Dave\My Documents\ArmA 2 Other Profiles\Zombie\mpmissions\stuntman.Chernarus\jumpdistance.sqf, line 36
Error in expression <sidechat "vehicle destroyed"};
exitwith {{deletevehicle _x}foreach [_startgl,_la>
 Error position: <{{deletevehicle _x}foreach [_startgl,_la>
 Error Missing ;
File E:\Documents and Settings\Dave\My Documents\ArmA 2 Other Profiles\Zombie\mpmissions\stuntman.Chernarus\jumpdistance.sqf, line 36
Error in expression <,"_landlogic","_action"];

_vcl = _this select 0;_startgl = objNull;_landlogic =>
 Error position: <select 0;_startgl = objNull;_landlogic =>
 Error select: Type Object, expected Array,Config entry
File E:\Documents and Settings\Dave\My Documents\ArmA 2 Other Profiles\Zombie\mpmissions\stuntman.Chernarus\jumpdistance.sqf, line 9
Creating debriefing

thanks for your help, btw, I think we are close...biggest problem is I really don't know how to read/write/use sqf's, been comfortable with sqs's since 2003 and I am old and stubborn!

Share this post


Link to post
Share on other sites

ok, a new try ;) ...

private ["_vlc","_startgl","_landlogic","_action"];

_startgl = objNull;_landlogic = objNull;mDistance = -1;_action = true;_vcl = objNull;

if(typeName _this == "ARRAY") then {_vcl = _this select 0} else {_vcl = _this};

if(isServer) then
{
_startgl = "logic" createvehiclelocal [0,0];
_landlogic = "logic" createvehiclelocal [0,0];
while{_action} do
{
	sleep 0.01;
	if((position _vcl select 2) >= 1) then
	{
		mDistance = 0;publicvariable "mDistance";
		if(local player) then {player sidechat "measuring jump distance"};
		_startgl setpos position _vcl;
		waituntil{((position _vcl select 2) < 1)};
		_landlogic setpos position _vcl;
		mDistance =  round(_startgl distance _landlogic);
		publicvariable "mDistance";
		if(local player) then {player sidechat format ["%2  jumped %1 meters!!!",mDistance, name driver _vcl]};
		sleep 1;
	}
	else
	{
		if((getdammage _vcl) == 1) then
		{
			_action = false;
			if(local player) then {player sidechat "vehicle destroyed"};
			deletevehicle _startgl;deletevehicle _landlogic;
		};
	};
};
}
else
{
while{_action} do
{
	waituntil{(mDistance > -1) || ((getdammage _vcl) == 1)};
	if(mDistance > -1) then
	{
		player sidechat "measuring jump distance";
		waituntil{(mDistance > 0)};
		player sidechat format ["%2  jumped %1 meters!!!",mDistance, name driver _vcl];
		mDistance = -1;
		sleep 1;
	}
	else
	{
		player sidechat "vehicle destroyed";_action = false;
	};
};
};

... and this script call is right (from init line):

check = this execVM "jumpdistance.sqf"

maybe it's better to use the right name:

check = NameOfVehicle execVM "jumpdistance.sqf"

Greeting

Silola

---------- Post added at 03:53 PM ---------- Previous post was at 03:33 PM ----------

You can also try to start the script from an init.sqf like this:

// the names of all vehicle placed in the editor;
_myVehicles = [car1,car2,car3,car4]; 

//start the script for all vehicles;
{[_x] execVM "jumpdistance.sqf"}foreach _myVehicles;

Greeting

Silola

Share this post


Link to post
Share on other sites

ok, that variant worked without errors in the game or rpt, Won't know for sure if it displays the same distance to both the driver and everyone else until my friend logs in and we can verify it.

Will definately let you know when we have finished the map I am using this on...thanks for your help.

btw...what does this line actually do and why is it needed?

if(typeName _this == "ARRAY") then {_vcl = _this select 0} else {_vcl = _this};

I can't see where array is used or called

Share this post


Link to post
Share on other sites

:) np. And yes, Arma community is great !

btw...what does this line actually do and why is it needed?

The script checks how the parameter is passed. For example:

check = [vehicle] execVM "jumpdistance.sqf" >>> within an array

check = vehicle execVM "jumpdistance.sqf" >>> without an array

Edited by Silola

Share this post


Link to post
Share on other sites

so far so good Silola, now that Dirtydeeds is on my local host we can confirm that

a) all distances match

but

b) if he gets in a vehicle and I don't, it works fine for him and I see matching data

c) if I get in a vehicle everything is fine for me but he sees "error: novehicle jumped..." for himself and me

the rpt shows this: Server: Update of object 2:304 arrived from nonowner

Share this post


Link to post
Share on other sites

hmm ... bad :confused:

ok, try this one:

private ["_vlc","_startgl","_landlogic","_action"];

_startgl = objNull;_landlogic = objNull;mDistance = -1;_action = true;_vcl = objNull;

if(typeName _this == "ARRAY") then {_vcl = _this select 0} else {_vcl = _this};

if(isServer) then
{
_startgl = "logic" createvehiclelocal [0,0];
_landlogic = "logic" createvehiclelocal [0,0];
while{_action} do
{
	sleep 0.01;
	if((position _vcl select 2) >= 1) then
	{
		mDistance = 0;publicvariable "mDistance";
		if(local player) then {player sidechat "measuring jump distance"};
		_startgl setpos position _vcl;
		waituntil{((position _vcl select 2) < 1)};
		_landlogic setpos position _vcl;
		mDistance =  round(_startgl distance _landlogic);
		publicvariable "mDistance";
		if(local player) then
		{
			player sidechat format	[
										"%2  jumped %1 meters!!!",
										mDistance,
										if(format["%1",driver _vcl] == "<NULL-object>") then {_vcl} else {name driver _vcl};
									];
		};
		sleep 1;
	}
	else
	{
		if((getdammage _vcl) == 1) then
		{
			_action = false;
			if(local player) then {player sidechat "vehicle destroyed"};
			deletevehicle _startgl;deletevehicle _landlogic;
		};
	};
};
}
else
{
while{_action} do
{
	waituntil{(mDistance > -1) || ((getdammage _vcl) == 1)};
	if(mDistance > -1) then
	{
		player sidechat "measuring jump distance";
		waituntil{(mDistance > 0)};
		player sidechat format	[
									"%2  jumped %1 meters!!!",
									mDistance,
									if(format["%1",driver _vcl] == "<NULL-object>") then {_vcl} else {name driver _vcl};
								];
		mDistance = -1;
		sleep 1;
	}
	else
	{
		player sidechat "vehicle destroyed";_action = false;
	};
};
};

Greeting

Silola

Share this post


Link to post
Share on other sites

will do...will let you know

ok, it doesn't work now and gives the following in the rpt

Error in expression <t>") then {_vcl} else {name driver _vcl};
];
};
sleep 1;
}
else
{
if((getdammage>
 Error position: <;
];
};
sleep 1;
}
else
{
if((getdammage>
 Error Missing ]
File E:\Documents and Settings\Dave\My Documents\ArmA 2 Other Profiles\Zombie\mpmissions\stuntman.Chernarus\jumpdistance.sqf, line 28
Error in expression <t>") then {_vcl} else {name driver _vcl};
];
};
sleep 1;
}
else
{
if((getdammage>
 Error position: <;
];
};
sleep 1;
}
else
{
if((getdammage>
 Error Missing ]
File E:\Documents and Settings\Dave\My Documents\ArmA 2 Other Profiles\Zombie\mpmissions\stuntman.Chernarus\jumpdistance.sqf, line 28

over and over

Edited by {USI}_Zombie

Share this post


Link to post
Share on other sites

Hi,

maybe you have made an error while paste© the script?

On the other hand, I see two unnecessary ";" characters.

So, we made a new test :)

private ["_vlc","_startgl","_landlogic","_action"];

_startgl = objNull;_landlogic = objNull;mDistance = -1;_action = true;_vcl = objNull;

if(typeName _this == "ARRAY") then {_vcl = _this select 0} else {_vcl = _this};

if(isServer) then
{
_startgl = "logic" createvehiclelocal [0,0];
_landlogic = "logic" createvehiclelocal [0,0];
while{_action} do
{
	sleep 0.01;
	if((position _vcl select 2) >= 1) then
	{
		mDistance = 0;publicvariable "mDistance";
		if(local player) then {player sidechat "measuring jump distance"};
		_startgl setpos position _vcl;
		waituntil{((position _vcl select 2) < 1)};
		_landlogic setpos position _vcl;
		mDistance =  round(_startgl distance _landlogic);
		publicvariable "mDistance";
		if(local player) then
		{
			player sidechat format	[
										"%2  jumped %1 meters!!!",
										mDistance,
										if(format["%1",driver _vcl] == "<NULL-object>") then {_vcl} else {name driver _vcl}
									];
		};
		sleep 1;
	}
	else
	{
		if((getdammage _vcl) == 1) then
		{
			_action = false;
			if(local player) then {player sidechat "vehicle destroyed"};
			deletevehicle _startgl;deletevehicle _landlogic;
		};
	};
};
}
else
{
while{_action} do
{
	waituntil{(mDistance > -1) || ((getdammage _vcl) == 1)};
	if(mDistance > -1) then
	{
		player sidechat "measuring jump distance";
		waituntil{(mDistance > 0)};
		player sidechat format	[
									"%2  jumped %1 meters!!!",
									mDistance,
									if(format["%1",driver _vcl] == "<NULL-object>") then {_vcl} else {name driver _vcl}
								];
		mDistance = -1;
		sleep 1;
	}
	else
	{
		player sidechat "vehicle destroyed";_action = false;
	};
};
};

Good luck :)

Share this post


Link to post
Share on other sites

latest code report: all works well for zombie (he is the host)

however, my hint is broken :eek:

jump1.jpg

** edit**

problem is variable, upon restart, zombies hint is as in screenshot, mine is working properly, and now the distance is NOT synched, we are seeing different numbers ( 1-10 meters depending on distance)

where is the facepalm smiley ? :D

Edited by [DirTyDeeDs]-Ziggy-

Share this post


Link to post
Share on other sites

ok, thx for report.

please try this (just to see what happens):

Use only one bike in a test mission, so that the script is starting only one time.

Then zombie drive the first round ... be careful what happens about the distance (synched?).

After this action, zombie gets out and you get in and drive the second round.

What happens then?

First we have to fix this distance problem ;)

Greeting

Silola

Share this post


Link to post
Share on other sites

ok, next I will try to change the code a little bit to fix the p3d message error... :cool:

Share this post


Link to post
Share on other sites

Good luck with this code (Please the same procedures as before) ;) :

private ["_vlc","_startgl","_landlogic","_action"];

_startgl = objNull;_landlogic = objNull;mDistance = -1;_action = true;_vcl = objNull;mDriver = "";

if(typeName _this == "ARRAY") then {_vcl = _this select 0} else {_vcl = _this};

if(isServer) then
{
_startgl = "logic" createvehiclelocal [0,0];
_landlogic = "logic" createvehiclelocal [0,0];
while{_action} do
{
	sleep 0.01;
	if((position _vcl select 2) >= 1) then
	{
		mDistance = 0;publicvariable "mDistance";
		mDriver = format["%1",name (driver _vcl)];publicvariable "mDriver";
		if(local player) then {player sidechat "measuring jump distance"};
		_startgl setpos position _vcl;
		waituntil{((position _vcl select 2) < 1)};
		_landlogic setpos position _vcl;
		mDistance =  round(_startgl distance _landlogic);
		publicvariable "mDistance";
		if(local player) then
		{
			player sidechat format	[
										"%2  jumped %1 meters!!!",
										mDistance,
										mDriver
									];
		};
		sleep 0.1;
	}
	else
	{
		if((getdammage _vcl) == 1) then
		{
			_action = false;
			if(local player) then {player sidechat "vehicle destroyed"};
			deletevehicle _startgl;deletevehicle _landlogic;
		};
	};
};
}
else
{
while{_action} do
{
	waituntil{(mDistance > -1) || ((getdammage _vcl) == 1)};
	if(mDistance > -1) then
	{
		player sidechat "measuring jump distance";
		waituntil{(mDistance > 0)};
		player sidechat format	[
									"%2  jumped %1 meters!!!",
									mDistance,
									mDriver
								];
		mDistance = -1;mDriver = "";
		sleep 0.1;
	}
	else
	{
		player sidechat "vehicle destroyed";_action = false;
	};
};
};

Greeting

Silola

Share this post


Link to post
Share on other sites

first jump for either of us introduce a 'measuring distance' spam, about ten lines.

distances continue to be synched

zombie always sees the proper hint, calling out the name

I see both the name or the number.

ME watching zombie jump

jump2.jpg

ME jumping

jump3.jpg

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  

×