Forum Jump :

Author Message


Posts: 6
Rank:


Level: Member

Country: uk
Location:
Occupation:
Age:
In-game name:

 
#1 Posted at 2013-10-07 12:40        
     
Hi every one, long time reader first time poster.

I've been having trouble getting my head around how to use the BIS_fnc_mp command and whether or not it's the correct method to use for my situation.

To simplify things I'll state an example that every one can follow.

How could I use BIS_fnc_mp to send a message to the server that should be broadcasted globally? I'm using an addon to separate my client side and server side game logic, once I actually understand how BIS_fnc_mp works I can actually get some communication going between the two.

I've googled around and searched these forums as well for a while to try and find a detailed example of where different things should be placed.

My current (possibly incorrect) understanding is that a client calls a BIS_fnc_mp function that is defined on the server, the server then executes that function remotely and returns a result to the client, after which execution returns to normal.

The examples I have been looking at are pretty confusing and don't specify which lines belong on either the client or the server side.

Many thanks,
- Everon.

This post was edited by Everon-V (2013-10-08 13:32, ago)


Author Message

HazJ  



Posts: 157
Rank:


Level: Member

Country: uk
Location: Somewhere
Occupation:
Age:
In-game name: Haz

 
#2 Posted at 2013-10-07 17:25        
     
What message? Like a message via side chat or? I may be able to help but could you explain a bit more?

Dirty Haz

Edit/Update:
I'm not sure if this is what you are looking for but... idk :-)
init.sqf:
if (!(isNull player)) then {
fnc_MP_sideChat = {
_message = "This will broadcast a message to all client's on the server and also to player's that connect.";
Crossroad = [WEST,"HQ"]; Crossroad sideChat _message;
};
};
You can call the above via init, trigger, script, etc like this:
blah = [true,"fnc_MP_sideChat",nil,true] spawn BIS_fnc_MP;
Sorry if I have misunderstood your question.

Dirty Haz

This post was edited by Dirty Harry (2013-10-07 17:33, ago)

Haz

Advertisement


Author Message


Posts: 6
Rank:


Level: Member

Country: uk
Location:
Occupation:
Age:
In-game name:

 
#3 Posted at 2013-10-07 19:43        
     
I may be completely missing the point with BIS_fnc_mp, I'm basically trying to get a client to call a function that is only defined on the server side (in an addon pbo).

I assumed and have had it mentioned to me by a few people and now that I've gotten around to it I may have gone about things wrong.

So, if a player joins - the client side mission file sends a request to the server to execute a custom function which for example would log that a player has joined and do some things with the data that is sent.

I'm not really sure how I can simplify it further. I could be enquiring about the wrong function completely!

I've tried to implement it from what I've read on the documentation and google and nothing seems to work.
One of the examples I used was on the BIS_fnc_mp page here: http://community.bistudio.com/wiki/BIS_fnc_MP

I tried the second example listed:
[["Hello World"],"BIS_fnc_guiMessage",nil,true] spawn BIS_fnc_MP;

I placed that code in both the server side and the client side and both at the same time with no change. Nothing was shown on screen. I then tried to put that code in to a loop in the server addon and there still wasn't any change.

Thanks for helping.
- Ev.


Author Message

HazJ  



Posts: 157
Rank:


Level: Member

Country: uk
Location: Somewhere
Occupation:
Age:
In-game name: Haz

 
#4 Posted at 2013-10-07 20:07        
     
Try this:
["Message","Header",nil,true] spawn BIS_fnc_guiMessage;
https://community.bistudio.com/wiki/BIS_fnc_guiMessage

Dirty Haz

Edit/Update:
Just tested and both work fine for me.
blah = [["Hello World"],"BIS_fnc_guiMessage",nil,true] spawn BIS_fnc_MP;
blah = ["Message","Header",nil,true] spawn BIS_fnc_guiMessage;
If you want to broadcast it to all client's on the server then try this:
if (!(isNull player)) then {
fnc_MP_guiMessage = {
blah = [["Hello World"],"BIS_fnc_guiMessage",nil,true] spawn BIS_fnc_MP;
};
};
You can call the above via init, trigger, script, etc like this:
blah = [true,"fnc_MP_guiMessage",nil,true] spawn BIS_fnc_MP;

Dirty Haz

This post was edited by Dirty Harry (2013-10-07 20:15, ago)

Haz

Author Message


Posts: 6
Rank:


Level: Member

Country: uk
Location:
Occupation:
Age:
In-game name:

 
#5 Posted at 2013-10-07 20:53        
     
So do the BIS_fnc_mp calls need to be on the client or the server?

- Ev.


Author Message

HazJ  



Posts: 157
Rank:


Level: Member

Country: uk
Location: Somewhere
Occupation:
Age:
In-game name: Haz

 
#6 Posted at 2013-10-07 21:01        
     
Not sure lol but, the function will broadcast whatever it is to all client's and to client's that connect. I am still learning this stuff too. :-)

Dirty Haz

Haz

Author Message


Posts: 6
Rank:


Level: Member

Country: uk
Location:
Occupation:
Age:
In-game name:

 
#7 Posted at 2013-10-07 22:32        
     
Alright, I used the following code on the client mission.

while {true}
do
{
	sleep (5);
	["Message","Header",nil,true] spawn BIS_fnc_guiMessage;
};

That works as expected and displays a message prompt every 5 seconds indefinitely.
But putting that in to the server's init.sqf file (the one in the addon pbo) fails to do any thing.

I was under the impression that it would cause the server to tell every client to do it every 5 seconds as well.
If possible, would you be available to talk about things on Teamspeak?

Added 14 hours 58 minutes later:

Right!
I've finally sorted my issue and I'll post the solution here for any one who comes looking for it.

What I originally wanted to do was to use BIS_fnc_mp to communicate with the server from a client, this is completely the wrong command to be using as BFMP (for short) is really used just to execute a command on every client on the server.

So after to speaking to another developer I finally found what I wanted.

//Client side mission init.sqf
X_Server = false;
if(isServer) then { X_Server = true;};

//Kick the server off
if(X_Server) then
{    
    [] execVM "\name_of_addon\init.sqf";
};

It turns out the issue was that the init.sqf file I created in the addon wasn't even being executed by the dedicated server, it had to be done manually with a conditional statement in the client side mission file.

The server init file would only be executed by the server it's self running the mission init.sqf file, there by also initialising the server side when the mission is started, simple!

I could now call code placed in the server side addon like so.

//Server side addon init.sqf
while {true} do
{
	sleep (5);
	blah = [["Hello World"],"BIS_fnc_guiMessage",nil,true] spawn BIS_fnc_MP;
}

This code was to used to check that it was working, a loop was used as the GUI message would only display at the start of the mission probably before I could even get in.

This method can be used to keep sensitive code used for things like a database securely locked away from clients who might use it maliciously.

Thread title changed to reflect.

- Ev.

This post was edited by Everon-V (2013-10-08 13:31, ago)