Jump to content
Sign in to follow this  
rangerrambo

Side Counting Vehicles

Recommended Posts

Basically I have couple ideas, but I wanted to check with you guys how to accomplish this.

I am working on a small TVT involving dog fighting and I want to make a controlled vehicle spawn. For that I need:

-to know how many players are on each side (not a problem)

-figure out how many vehicles are being used on each side (+empty ones that are on the airfield) and checking that at intervals on the server, which will determine whether a new vehicle has to be available at spawn or not

Now to count vehicles I know I an use vehicles command, but determining a list of all vehicles used or being available to east for example, I had 2 ideas:

1. Counting the Array after generating it with ForEach while using vehicle command on each player on one side.

2. Same but using Crew command

http://community.bistudio.com/wiki/vehicles

http://community.bistudio.com/wiki/vehicle

http://community.bistudio.com/wiki/crew

Share this post


Link to post
Share on other sites

I assume you are controlling the spawn based on how many people are on, so you dont get to many aircraft on one side.

Unless you need them to spawn, you could just start with all the aircraft on the ground, for example 10 aircraft.

When there are less than 10 people on the server then aircraft 5-10 are locked. Then as more people get on you can unlock the other aircraft.

Share this post


Link to post
Share on other sites

Edit: i did not get the question totally at first.

this code will delete any vehicle and only respawn them if there are 3 or more west players:

_null = this spawn {
       if (!isServer) exitWith {};
_veh = _this;
_type = typeOf _this;
_pos = getPos _this;
_dir = getDir _this;

deleteVehicle _veh;

while {true} do {
	waitUntil {sleep 1; ({(side _x) == west} count playableUnits) >= 3};
	_veh = createVehicle [_type, _pos, [], 0, "NONE"];
	_veh setPos _pos;
	_veh setDir _dir;
	waitUntil {sleep 1; (getDammage _veh) >= 1};
	waitUntil {sleep 1; !canMove _veh};
	sleep 10;
};
};

you can just adjust the number 3 to however many west players needed for a vehicle to be available.

and do same for east etc...

more info on what line does what in spoiler below fyi.

why make it difficult?

why not just place however many vehicles you want available for each side and respawn them when destroyed.

example, place code in init of any vehicle, addon or vanilla:

_null = this spawn {
_veh = _this;
_type = typeOf _this;
_pos = getPos _this;
_dir = getDir _this;
while {true} do {
[b]		waitUntil {sleep 1; (getDammage _veh) >= 1};
	waitUntil {sleep 1; !canMove _veh};
	sleep 10;[/b]
	_veh = createVehicle [_type, _pos, [], 0, "NONE"];
	_veh setPos _pos;
	_veh setDir _dir;
};
};

Notice ive highlighted 3 lines in the middle.

* line with getdammage will wait until vehicle is destroyed.

* line with !canmove will wait until vehicle is so damaged it cannot move, (out of fuel, no tires, no belts, etc severe damage)

just use one of them and delete the other.

* sleep 10 is how long after the wait it will respawn in at same place as start.

you can even add in a delete function before the createVehicle line to delete the old one.

_null = _veh spawn {sleep 60; deleteVehicle _this};

will delete the old one 60 seconds after the wait.

there is also the setVehicleVarname command you can work in after the createVehicle lines, if you need the vehicles to be named something specific, just collect name before while and reapply it after createVehicle.

Edited by Demonized
adjusted code to remove one line. and added isserver line.

Share this post


Link to post
Share on other sites

Riouken, exactly.

Basically what I wanted is if 5 people get in the game 3 on WEST side and 2 on the EAST only 2 planes will spawn on each side. The side with 3 players will have to put 1 player on the bench - will probably add a spectating script.

Now if another player leaves from EAST, then the script will start spawning only 1 plane on each side. Initially I wanted a script that would also delete the planes but there are couple consideration, where you don't want to delete a plane that someone is using.

As far as the code from Demonized, I just tested it in but swaped the

(side _x) == west} count playableUnits) >= 3

a>= 3

and then just changed a in the debugger.

Code is great, hats off and definitely putting you in my credits Demonized.

The only thing and that is why my post is delayed, is when players disconnect the planes do not get deleted from the spawn.

I haven't tested this if it works but I'll probably do this for determining what is the minimum players on each side.

((side _x) == west} count playableUnits)) min ((side _x) == east} count playableUnits)) >= 3

Again thank you and I learned a lot from this:

1. Parrarel running of code.

2. You can actually put that much code in the init of the unit in editor

P.S. I might also put this in a script and call in using execVM or something, seems more tidy. Plus add parameters and allow picking of aircrafts.

Edited by rangerrambo

Share this post


Link to post
Share on other sites

I was hoping to get the code from Demonized into a sqf and then call it while giving paramets [this, c], where c would be the number of players required to spawn.

Also I changed in the script to _this select 0 and 1 respectively.

_null = [this, 3] spawn compile preprocessFileNumbers "rscripts\crespawn.sqf";

Doesn't work.

Share this post


Link to post
Share on other sites

place in init of vehicle:

_null = [this,3] execVM "script.sqf";

script.sqf:

if (!isServer) exitWith {};
_veh = _this select 0;  // the vehicle.
_amp = _this select 1;  // amount of players.
_type = typeOf _this;
_pos = getPos _this;
_dir = getDir _this;

deleteVehicle _veh;

while {true} do {
waitUntil {sleep 1; ({(side _x) == west} count playableUnits) >= _amp};
_veh = createVehicle [_type, _pos, [], 0, "NONE"];
_veh setPos _pos;
_veh setDir _dir;
waitUntil {sleep 1; (getDammage _veh) >= 1};  // here we use the destroyed option.
//waitUntil {sleep 1; !canMove _veh};
sleep 10;
};

you can also make it usable for all sides by adding in side.

_null = [this,3,west] execVM "script.sqf";

and in top of script after _amp add:

_side = _this select 2;

and change the

(side _x) == west

to

(side _x) == _side

Share this post


Link to post
Share on other sites

Thanks, Demonized.

Didn't know that you could swap the spawn with execvm.

Another thing has taken like about 6 hours now and I can't figure it out.

1. I want to use the same emtpy vehicles (lets say F35s) on both side

2. Players (or in this case AI) get in and it should all work ok right?

Well the picture speaks for itself, I have checked any commands that could solve this and also searched the forums, no luck.

ifzd38.jpg

Share this post


Link to post
Share on other sites

do you have respawn in your test mission? if not that would explain why the count goes down.

for the red vehicle target, im not sure but the vehicles have their own side and should be updated via pilot inside, but after testing it doesnt, you cant TAB for auto target, but you can rightclick on target and lock on.

Share this post


Link to post
Share on other sites

Currently there is no respawn, however the count goes down because the player is not considered WEST after hitting the F35 (check pictures).

Again if we solve this one I believe its a major one.

I mean I wanted to be able to provide both sides with same planes for balance, but I guess I won't be able to do that. I am amazed the issue hasn't been brought up before.

I have been just searching and searching and I think this hasn't been answered yet.

http://forums.bistudio.com/showthread.php?t=106479

http://i54.tinypic.com/xbcylx.jpg

http://i53.tinypic.com/5trn4.jpg

Edited by rangerrambo
changed to adhere with rules, how do you even figure out what the image size of those 2 images was other than downloading it?

Share this post


Link to post
Share on other sites

Forum rules:

§15) Do not hotlink images over 100kb (102400 bytes) in size

Do not link images over 100kb using the IMG tags to display an image in your post. If you wish to post an image larger then 100 kb feel free to post the URL instead of hotlinking.

;)

Edited by Buliwyf

Share this post


Link to post
Share on other sites

Just to stay on the topic, just tested this issue with players on dedicated server, problem persists.

1. If player was EAST, he could see all 3 F35s as red on radar

2. If player was WEST, he could see all 3 F35s as green on radar

Share this post


Link to post
Share on other sites

I apologize if I am being little too persistent here, but I am just looking for some sort of answer either:

a) this is the solution

or

b) sorry this is a known issue.

Referring to post

http://forums.bistudio.com/showpost.php?p=1983408&postcount=7

http://forums.bistudio.com/showpost.php?p=1983468&postcount=9

of this thread.

Thank you.

Share this post


Link to post
Share on other sites

the player is most likely considered enemy because he got a negative rating after "killing" a "friendly" plane, so he is no longer in west list.

fix: addRating the lost amount.

for the issue with seeing friendly planes with enemy pilots in them, its a matter of reality, if you see an A10 on the battlefield you asume its a western pilot, if you see a mig, you lean towards any "communist", russia, china etc (not political correct :D )

however you can manually target that plan by clicking on it, manual targeting.

fix: dont use f35s for all sides or get a addon that has f35 listed as a additional east plane.

Share this post


Link to post
Share on other sites

EDIT: Figured out the problem. Server finished game, clients didn't, now I have to figure out how to fix this.

Thank you Demonized. I have couple new issues that have arisen.

1. This only happens on the dedicated server. At one point everything freezes up, player can't access gear (it shows only for a split second then disappears), player can't get in the plane, planes don't respawn.

Server FPS is 47+.

2. Also I don't know why the following line doesn't work when executed from the server.

player globalChat format ["BLUFOR %1 planes",o];

Other than that I can only link my scripts here:

init.sqf

enableSaving [false, false];

setViewDistance 8000;
ace_settings_enable_vd_change = true;

"marker_blufor" setMarkerAlpha 0;
"marker_opfor" setMarkerAlpha 0;

[] execVM "rscripts\func_assessmentHandler.sqf";

blufor respawn for planes

if (!isServer) exitWith {};
_veh = _this select 0;
_amp = _this select 1;
_type = typeOf _veh;
_pos = getPos _veh;
_dir = getDir _veh;
b = 0;
deleteVehicle _veh;

while {true} do {
waitUntil {sleep 1; (({(side _x) == west} count playableUnits) min ({(side _x) == east} count playableUnits)) >= _amp};
_veh = createVehicle [_type, _pos, [], 0, "NONE"];
_veh setPos _pos;
_veh setDir _dir;
waitUntil {sleep 1; (getDammage _veh) >= 1};
deleteVehicle _veh;
b = b + 1 ;
player globalChat format ["BLUFOR %1 planes",b];   //this doesn't seem to be seen by the player
sleep 10;
};

opfor respawn

if (!isServer) exitWith {};
_veh = _this select 0;
_amp = _this select 1;
_type = typeOf _veh;
_pos = getPos _veh;
_dir = getDir _veh;
o = 0;
deleteVehicle _veh;

while {true} do {
waitUntil {sleep 1; (({(side _x) == west} count playableUnits) min ({(side _x) == east} count playableUnits)) >= _amp};
_veh = createVehicle [_type, _pos, [], 0, "NONE"];
_veh setPos _pos;
_veh setDir _dir;
waitUntil {sleep 1; (getDammage _veh) >= 1};
deleteVehicle _veh;
o = o + 1;
player globalChat format ["BLUFOR %1 planes",o];
sleep 10;
};

and assesment handler for the end


if (!isServer) exitWith {};

sleep 150;

_victoryPoints = o/b;

 _winner = "";
 switch (true) do {
   case (_victoryPoints >= 1.8): {
     _winner = "BluFor Decisive Victory";
   };
   case (_victoryPoints < 1.8 && _victoryPoints >= 1.25): {
     _winner = "BluFor Marginal Victory";
   };
   case (_victoryPoints < 1.25 && _victoryPoints > 0.8): {
     _winner = "Draw";
   };
   case (_victoryPoints <= 0.8 && _victoryPoints > 0.55): {
     _winner = "RedFor Marginal Victory";
   };
   case (_victoryPoints <= 0.55): {
     _winner = "RedFor Decisive Victory";
   };
 };


 _text = format [
"Mission End - Time Limit Reached
\n%1
\n
\n**** BluFor ****
\nPlanes Lost: %2
\n
\n**** RedFor ****
\nPlanes Lost: %3
", _winner, b, o];

 titleText [_text, "BLACK"];
 removeAllWeapons player; 
 player enableSimulation false;

 sleep 60;
 endMission "LOSER";

Edited by rangerrambo

Share this post


Link to post
Share on other sites

1: something else is lagging up your game, maybe its related to 2.

anyhow, i see you use ACE, and there is major differences in how ACE and Vanilla run the game.

2: because there is no players on the server(dedicated) side, notice top line:

if (!isServer) exitWith {};

means, all that is not server, exit with nothing.

use MP framework to broadcast sidechat etc from here.

you need a functions module for that btw.

Share this post


Link to post
Share on other sites

I just had my problems solved by a cool guy named Jaynus using CBA. Everything is redone the way I wanted, with couple cosmetics that I can do later. Either way tested on dedi so far and it works.

Among the stuff I need:

PAPABEAR=[West,"HQ"]; PAPABEAR SideChat "Hi there";

Figuring out how to have a random callsign say the msg in global vs the player.

Ok here is what I did for the rest of peeps.

if (!isServer) exitWith {};
_veh = _this select 0;
_amp = _this select 1;
_type = typeOf _veh;
_pos = getPos _veh;
_dir = getDir _veh;
o = 0;
deleteVehicle _veh;

while {true} do {
   waitUntil {sleep 1; (({(side _x) == west} count playableUnits) min ({(side _x) == east} count playableUnits)) >= _amp};
   _veh = createVehicle [_type, _pos, [], 0, "NONE"];
   _veh setPos _pos;
   _veh setDir _dir;
   waitUntil {sleep 1; (getDammage _veh) >= 1};
   deleteVehicle _veh;
   o = o + 1;
   [-1, {player globalChat format ["OPFOR lost %1 planes",_this];}, o] call CBA_fnc_globalExecute;      /changed passing the o variable from the server.
   sleep 10;
};

this function is called from init



if (!isServer) exitWith {};

sleep 300;

_victoryPoints = o/b;

 _winner = "";
 switch (true) do {
   case (_victoryPoints >= 1.8): {
     _winner = "BluFor Decisive Victory";
   };
   case (_victoryPoints < 1.8 && _victoryPoints >= 1.25): {
     _winner = "BluFor Marginal Victory";
   };
   case (_victoryPoints < 1.25 && _victoryPoints > 0.8): {
     _winner = "Draw";
   };
   case (_victoryPoints <= 0.8 && _victoryPoints > 0.55): {
     _winner = "RedFor Marginal Victory";
   };
   case (_victoryPoints <= 0.55): {
     _winner = "RedFor Decisive Victory";
   };
 };



[-2, {_this  execVM "rscripts\EndStats.sqf"},[_winner,o,b]] call CBA_fnc_globalExecute;   /passing down the variables that the server figures out and passes down to everyone

this then gets passed to the next script and executed on every mashine and showing a nice ending

_winnerf = _this select 0;
_numo = _this select 1;
_numb = _this select 2;


_text = format [
"Mission End - Time Limit Reached
\n%1
\n
\n**** BluFor ****
\nPlanes Lost: %2
\n
\n**** RedFor ****
\nPlanes Lost: %3
", _winnerf, _numb, _numo];

titleText [_text, "BLACK"];
removeAllWeapons player; 
player enableSimulation false;
sleep 15;
endMission "LOSER";

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  

×