OFPEC Forum

Editors Depot - Mission Editing and Scripting => Arma2 - Editing/Scripting Multiplayer => Topic started by: Cougarxr7 on 01 Jul 2009, 04:56:39

Title: VehicleRadio works host and play but not on server! SOLVED!
Post by: Cougarxr7 on 01 Jul 2009, 04:56:39
I added a sound file in the eject code by Xeno it works host and play but not on a server.
Here the code;
Code: [Select]
// by Xeno/

if (!isServer) exitWith{};

_vehicle = _this select 0;
_position = _this select 1;
_enterer = _this select 2;
_enterer_name = typeOf _enterer;

if (_position == "driver") then {
if (_enterer_name != "USMC_Soldier_Pilot") then {
driver _vehicle action["Eject",_vehicle];
hint "Authorized personal only!";
_vehicle vehicleRadio "RadioMsg2";<I added the sound file here.
};
};

if (true) exitWith {};
I have another file "nallow.sqf" that causes a "Zero Divide Error", here's the code,
Code: [Select]
//players\nallow.sqf
_vehicle  = _this select 0;
_enterer = _this select 1;
_vehicle vehicleRadio "RadioMsg2";< Same sound file.
Player does get ejected on the server, but no sound gets played????
I tried execVM that file in the vehicle init and when I do it causes an error!
Here's the error.
Code: [Select]
"Error in expression <cle  = _this select 0;
 _enterer = _this select 1;
 _vehicle vehicleRadio "RadioMs>
   Error position: <select 1;
 _vehicle vehicleRadio "RadioMs>
   Error Zero divisor"

I'm going to try a few more things to see if I can get this to work. Anybody know why this is happenning?
thanks!
Title: Re: VehicleRadio works host and play but not on server!
Post by: Spooner on 01 Jul 2009, 13:27:55
The GetIn handler is using:
Code: [Select]
if (!isServer) exitWith{}; // Only run this script on the server.
which means that although the man gets out correctly, the hint/radio message, which is client-side, are not activated (when you are the host, you are on a server/client at the same time, just as in SP, so you get the messages).

What you actually want is
Code: [Select]
_vehicle = _this select 0;
_position = _this select 1;
_enterer = _this select 2;

if (_position == "driver") then {
if (_enterer isKindOf "USMC_Soldier_Pilot") then {
// Only eject & output messages for the player who is refused
// access (or if his AI are refused).
                if (local _enterer) then {
_enterer action ["Eject", _vehicle];
hint "Authorized personnel only!";
_vehicle vehicleRadio "RadioMsg2";
};
};
};

You probably don't need a hint as well as a radio message, since the radio message will have both sound and a text message.
Title: Re: VehicleRadio works host and play but not on server!
Post by: h- on 01 Jul 2009, 13:32:43
Looks to me that this belongs here at the MP Section...
Title: Re: VehicleRadio works host and play but not on server!
Post by: Cougarxr7 on 01 Jul 2009, 22:04:25
First, thanks for the help! h-, thanks for moving my posts to the correct forum.
Spooner, tried your code but it can back with an error. :dunno:
Error in expression <ehicle vehicleRadio "RadioMsg2";
};
};
}:
if (true) exitWith {};
if (true) exitWith {};
Error :: Type Any, expected switch
To make sure I am reading this correctly. In those 3 if statements, 1 and 3 will be true , [Pilot Seat,Local Player], yes/no?
 In #2 if the player is a Pilot, that makes that statement true, then the player will be ejcted from vehicle, yes/no?
If yes then does #2 needs to be (_enterer_name != "USMC_Soldier_Pilot") so nonpilots gets kicked. I want the pilots to have access to the airvehicles.
I tried some different variations, all returned with errors.
Gone to figure this out!
Thanks!

Title: Re: VehicleRadio works host and play but not on server!
Post by: Spooner on 01 Jul 2009, 22:51:59
Code: [Select]
if (true) exitWith {}; isn't necessary. People just add it at the end of scripts because they saw someone else do it. You only need to exitWith if you want to leave a script early.

The end of my code is:
Code: [Select]
};
};
};
But your error gives:
Code: [Select]
};
};
}:

; is not the same as :
Title: Re: VehicleRadio works host and play but not on server!
Post by: Cougarxr7 on 02 Jul 2009, 16:38:02
Spooner,
 You're right, that was not your code, that was my sloppy copy and paste from the RPT file, sorry.
As far as that colon, :dunno: All I can say is I'm old and I take alot of meds.
With all the testing I am using this code.
Code: [Select]
if (!isServer) exitWith{};
_vehicle = _this select 0;
_position = _this select 1;
_enterer = _this select 2;

_enterer_name = typeOf _enterer;

if (_position == "driver") then {
if (_enterer_name != "USMC_Soldier_Pilot") then {
driver _vehicle action["Eject",_vehicle];
hint "Authorized Pilots Only!";
_vehicle vehicleRadio "RadioMsg2";
};
};
It works except on a server, no sound or hint.
For some reason when I would use,  "if (local _enterer) then" , it would kill the ejection.
Tried different syntax, "if (_enterer_name == local) then", still did not work.
The kicking works for now, put this on a shelf. Find solution later.
Thanks for your help!









Title: Re: VehicleRadio works host and play but not on server!
Post by: Spooner on 02 Jul 2009, 18:58:43
If you reread my post, you'll see that the problem was that you were using if isServer exitWith {}, which is why I didn't include it in my version!
Title: Re: VehicleRadio works host and play but not on server!
Post by: Cougarxr7 on 03 Jul 2009, 00:34:09
Spooner, your code works, I'm the one who is learning.
However it kicks the pilot. I tried this,
       "(_enterer != "USMC_Soldier_Pilot")" instead of
       "(_enterer isKindOf "USMC_Soldier_Pilot")
but that return an error.
What would be the correct snytax to change it to kicking all but the pilots?
Thanks big time!
Title: Re: VehicleRadio works host and play but not on server!
Post by: Spooner on 03 Jul 2009, 00:52:55
Sorry, brain not firing on all cylinders. Yes, this will only kick pilots and no-one else, which is an inversion of what it should have been! Should use:
Code: (best working method) [Select]
if (not (_enterer isKindOf "USMC_Soldier_Pilot")) then {
This is the preferred method over the original, which was:
Code: (working, but not best method) [Select]
_enterer_name = typeOf _enterer;
if (_enterer_name != "USMC_Soldier_Pilot") then {
But then literally only that pilot class could use it, not any pilot classes that were based on that one. It (isKindOf) is also case-independent so you don't have to worry about case of the class name, so it is generally a better option.
Code: (not working) [Select]
if (_enterer != "USMC_Soldier_Pilot") then {
won't work because you are comparing an object (_enterer) with a string ("USMC_Soldier_Pilot") which is an error.
Title: Re: VehicleRadio works host and play but not on server!
Post by: Cougarxr7 on 03 Jul 2009, 03:25:20
Spooner,
 This works completly however, it kicks all, including pilots.
Code: [Select]
_vehicle = _this select 0;
_position = _this select 1;
_enterer = _this select 2;

if (_position == "driver") then {
if (not(_enterer isKindOf "USMC_Soldier_Pilot")) then {
if (local _enterer) then {
_enterer action ["Eject", _vehicle];
hint "Authorized Pilots Only";
_vehicle vehicleRadio "RadioMsg2";
};
};
};
SOLVED!
This finally works correctly. Thanks for all your help Spooner!
The following code works, Server side and Host & Play.
Code: [Select]
_vehicle = _this select 0;
_position = _this select 1;
_enterer = _this select 2;
_enterer_name = typeOf _enterer;

if (_position == "driver") then {
if (_enterer_name != "USMC_Soldier_Pilot") then {
if (local _enterer) then {
_enterer action ["Eject", _vehicle];
hint "Authorized Pilots Only";
_vehicle vehicleRadio "RadioMsg2";
};
};
};


Thanks!
Title: Re: VehicleRadio works host and play but not on server! SOLVED!
Post by: Spooner on 03 Jul 2009, 13:19:55
My version works perfectly for me.