Sqeemin 1 Posted February 3, 2013 (edited) hi i have made 3 Separate Scripts that do the same thing for 3 Different Players, it's supposed to get the civilian that the players cursor is on top of into the nearest Car but it only works for the host, when my friends try nothing happens. also i'm new to scripting in ArmA 2 here is the code: _civ = cursorTarget; _nearCar = getPos _civ nearestObject "Car"; if(isServer) then { _civ moveInCargo _nearCar; }; thanks Edited February 3, 2013 by Sqeemin Share this post Link to post Share on other sites
cuel 25 Posted February 3, 2013 Hello. It's because there's an if (isServer) condition for moving the civilian into the car. That's only true for the host. Share this post Link to post Share on other sites
Sqeemin 1 Posted February 3, 2013 i tried making it if(!isServer) and taking if(isServer) out but it still doesn't work Share this post Link to post Share on other sites
blackmamb 2 Posted February 3, 2013 Yeah, a bit more complicated than that, as the civilian is probably local to the server anyway. Are you doing this via addAction? Do you use CBA? Share this post Link to post Share on other sites
nimrod_z 8 Posted February 3, 2013 could'nt you just use a publicVariableEventHandler to broadcast it ? here's an example http://forums.bistudio.com/showthread.php?103270-Updating-tasks-in-multiplayer Share this post Link to post Share on other sites
bad benson 1733 Posted February 3, 2013 i had the same problem some time ago. this is what helped me. it's one of the commands from the multiplayer framework http://community.bistudio.com/wiki/Multiplayer_framework if you scroll down there is a list of the available commands. they are basically MP friendly versions of the normal ones. make sure you have the functions module on the map (i think if you use CBA it won't be needed). [nil, _obj, "loc", rMOVEIN, _car, "Cargo"] call RE; _obj is the unit and _car is the vehicle. "Cargo" can also be "Driver" and "Gunner". Share this post Link to post Share on other sites
blackmamb 2 Posted February 4, 2013 If you use CBA, you certainly don't want to use the Multiplayer Framework. Actually, you don't want to use it at all, in most cases. Share this post Link to post Share on other sites
bad benson 1733 Posted February 4, 2013 it would be nice if you could explain why and if this is one of those cases. and also maybe provide an alternative better solution. is there a universal method that should be used to transmit local code or is it different from case to case? Share this post Link to post Share on other sites
blackmamb 2 Posted February 4, 2013 Basically you don't want to use the MPF because: a) the syntax is awful b) whenever you want to execute remote code, it sends the whole code all over the network, which creates a lot of unnecessary bandwith usage. If you use CBA, it's pretty easy, you only have to use the relevant function, here it would be CBA_fnc_remoteLocalEvent. If you're searching for a universal method, this is probably the one. Now, as I play in an addon-free community, what I do is I use a extended and modified version of a script that Muzzleflash released here some time ago. I think (I'm not sure) you can find it if you search something like Lite Extended Event Handlers. In this particular case, if you want to really understand what needs to be done: Your action executes one script: _civ = cursorTarget; _nearCar = getPos _civ nearestObject "Car"; if (local _civ) then { // if the civilian is local, we can execute the command _civ moveInCargo _nearCar; } else { MyPV = [_civ, _nearCar]; // if not, we inform the server he has to do something about it. We send him a variable containing the civie and the relevant car publicVariableServer "MyPV"; }; Now the server and clients need to know what to do when this happens, so we define a PVEH (in a script that's run globally, why not the init.sqf): "MyPV" addPublicVariableEventHandler { _myV = _this select 1; _civ = _myV select 0; _car = _myV select 1; // we retrieve the info from the broadcasted variable if (local _civ) then { // if the civilian is local to the receiver, we can execute the command _civ moveInCargo _nearCar; } else { if isServer then { // if the receiver is the server and the civilian is not local to the server, _owner = owner _civ; // we find where the civilian is local and send the variable that way. MyPV = _myV; _owner publicVariableClient "MyPV"; }; }; }; That's a simple way of doing it, there's even simpler, but this one demonstrates how you can reduce the exchanges of info over the network: the only info that's transmitted are the parameters to the event, and they only go from the player that initiate the action to the server, and if necessary to the relevant client. Share this post Link to post Share on other sites
bad benson 1733 Posted February 4, 2013 awesome! thanks alot! i have some questions though. 1. when are units actually local? as far as i understood it createunit and createvehicle are global commands. and aren't units and vehicles always global except when created with createvehicleLocal? so what does local really mean in this case? 2. shouldn't it be like this? "MyPV" addPublicVariableEventHandler { _myV = _this select 1; _civ = _myV select 0; _nearCar = _myV select 1; // we retrieve the info from the broadcasted variable if (local _civ) then { // if the civilian is local to the receiver, we can execute the command _civ moveInCargo _nearCar; } else { if isServer then { // if the receiver is the server and the civilian is not local to the server, _owner = owner _civ; // we find where the civilian is local and send the variable that way. MyPV = _myV; _owner publicVariableClient "MyPV"; }; }; }; when i had this problem with moveInCargo it seemed that only the command itself was local and that that was the problem not the unit itself being local. please elaborate a bit more since i'm kind of confused with the term local still. thanks in advance. sorry if i'm missing something. just trying to really understand the issue since it's something i'm struggling with in general myself. Share this post Link to post Share on other sites
Sqeemin 1 Posted February 4, 2013 @BlackMamb how does the first set of code go with the second? are they supposed to be in the same file? and im using addAction but im not using CBA Share this post Link to post Share on other sites
iceman77 18 Posted February 4, 2013 the PVEH can go into your init.sqf. The other can be stored into a function anywhere or in a seperate script. Share this post Link to post Share on other sites
Sqeemin 1 Posted February 4, 2013 finally got it working thanks everyone for your input Share this post Link to post Share on other sites
blackmamb 2 Posted February 4, 2013 @ Sqeemin: No problem dude, glad to see you got it working! @ Bad Benson: - 1 : No, vehicles and units are never global. Most of the time, empty vehicles and AI units are local to the server." A unit is local to a specific machine" means that that machine handle that vehicle, then broadcasts its state across the network. I recommend you have a look at this, but don't hesitate if you have questions afterwards. - 2 : No, it's not necessary here, although for the sake of clarity I should have kept the same name. Variables defined with an underscore before their names are local variables (this time, local refers to the fact that they only pertain to the innermost scope they were defined in). Here, that _nearCar variable, defined in the first script, has no value anywhere else. What I did, is I sent that value (not that variable) inside the publicvariable, as the second item in an array. In the PVEH, I retrieve the second item in that array, and affects its value to a new local variable, which I can name how ever I want. See this for more info. Also, technically, moveinCargo is a global command: you only need to execute it once, on one single machine, to see its effects broadcasted to everyone. But, its arguments are to be local. Which means you have to execute it where the unit you want to move is local. Share this post Link to post Share on other sites
bad benson 1733 Posted February 4, 2013 thx for the clarification. much appreciated! that's a bit of information that was always missing for me to really get the concept. but it makes a lot of sense. about 2.: i get how the vaiables are fetched from the first script. the problem was that in the second one they didn't match. you had this "MyPV" addPublicVariableEventHandler { _myV = _this select 1; _civ = _myV select 0; _car = _myV select 1; // we retrieve the info from the broadcasted variable if (local _civ) then { // if the civilian is local to the receiver, we can execute the command _civ moveInCargo _nearCar; } else { if isServer then { // if the receiver is the server and the civilian is not local to the server, _owner = owner _civ; // we find where the civilian is local and send the variable that way. MyPV = _myV; _owner publicVariableClient "MyPV"; }; }; }; so the second one should be _car or the first one _nearCar. so maybe this would be best to keep it from looking like the local var _nearcar travels to the second script. "MyPV" addPublicVariableEventHandler { _myV = _this select 1; _civ = _myV select 0; _car = _myV select 1; // we retrieve the info from the broadcasted variable if (local _civ) then { // if the civilian is local to the receiver, we can execute the command _civ moveInCargo _car; } else { if isServer then { // if the receiver is the server and the civilian is not local to the server, _owner = owner _civ; // we find where the civilian is local and send the variable that way. MyPV = _myV; _owner publicVariableClient "MyPV"; }; }; }; Share this post Link to post Share on other sites
blackmamb 2 Posted February 4, 2013 Oh. Yeah. My bad. Copy-beer-paste. Share this post Link to post Share on other sites