Jump to content
Stormridge

Client-created object (landmine) and Server references

Recommended Posts

Hi all,

 

I've done some searching and need input on how to approach a MP locality issue.

 

Background:

I have custom landmines that clients can create.  These are trip-wire mines based off of APERSTripMine_Wire_Mag, and they do custom stuff when triggered, including flares, sounds, and lights.

 

The client-side code catches the placement of these mines through the "Fired" eventhandler.  That event gets me the reference to the mine + position.  Then the client notifies the server that the mine was placed + position.

 

I want the server to monitor each mine and create the flares when the mine is triggered.  (I don't want clients doing CreateVehicle)

 

Problem:

Once the mine is placed, the client has a reference to the mine object, but I can't figure out how to pass the object reference to the server.  I am able to pass the position of the mine to the server, via publicVariableServer, but I'm 99% certain you can't pass the client object reference and have the server locate its own ref to that object.

 

 

I appreciate any tips.

 

Thanks

 

 

Share this post


Link to post
Share on other sites

Probably setOwner can help you to transfer ownership of the object to the server?

Share this post


Link to post
Share on other sites

I tried setting owner of the mine object to 2 (dedicated server) before triggering the public variable message to the server, but this does not work either.  

 

Passing the reference to the mine object in a publicVariableServer call results in a null object on the server side.

Share this post


Link to post
Share on other sites

Object references are just strings (or something like that) and the mine is created at the client, but a global object (it's owner is the client, but it still lives everywhere else, in contrast to createVehicleLocal objects).

You can simply pass the reference as a variable to the server because the server will reference the object by the same string.

 

But instead of using PublicVariable I would use this:

_mine = param [0];//Called by the eventhandler

[_mine] remoteExec ["my_fnc_registerMine", 2]; 

And on the server you have a function "my_fnc_registerMine" like this:

private["_pos"];
_mine = param[0];
_pos = getpos _mine;

//There are better ways to handle this,. by whiel/waituntil is the easiest right now

while{!alive _mine} do {
sleep 1;
};

//Create flare 50m over the mine
_flare = TypeOfFlare createvehicle (_pos vectorAdd [0,0,50]);

This is not perfect, als the flare will also trigger when: The mine is defused or the owner leaves the server, but it sould be enough to answer your question and get you startet.

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

×