Jump to content
Sign in to follow this  
gdscei

Get ClientID from PublicVariableServer

Recommended Posts

So I run a script on a client that sends a public variable to a server, and the server needs to do something with this and send it back with a string to the client using PublicVariableClient. I need to figure out the ClientID though, to do this.

Is there a way to get the ClientID which makes sure that the ClientID is indeed from the client that send that publicvariable?

And yes, I have seen this thread but that code does not work, since you can only use objects with owner.

BTW, if this is not possible, can I send two different strings in the same variable, and seperate them on the server then to get the ClientID? (so that the first part of the variable would be the ID, and the second part the thing that I need the server to know (this is always of a certain length: 8 characters))

Edited by gdscei

Share this post


Link to post
Share on other sites
My_PV = [owner player, <value>];
publicVariableServer "My_PV";

Share this post


Link to post
Share on other sites
My_PV = [owner player, <value>];
publicVariableServer "My_PV";

Don't see how I couldn't have come up with this myself, thanks :)

Share this post


Link to post
Share on other sites

The owner command works only on the server and not on clients. Replace owner player with just player and execute the owner command on the server once it is broadcasted.

Xeno

Share this post


Link to post
Share on other sites

Never realized that, maybe because I've only done it that way but I figured it'd work both ways, thanks Xeno.

Share this post


Link to post
Share on other sites
The owner command works only on the server and not on clients. Replace owner player with just player and execute the owner command on the server once it is broadcasted.

Xeno

But when I try to execute owner on the server side then, I get a "Type string, expected object" error.

Share this post


Link to post
Share on other sites
You need the player's OBJECT not his UID.

I do this clientside:

playerclientid = player;
PublicVariableServer "playerclientid";

Serverside:

"playerclientid" addPublicEventHandler {
playerclientid = owner(_this select 1);
playerclientid PublicVariableClient "responsefromserver";
};

Does this not do that? (well obviously there is some issue with this since it gives an error)

Edited by gdscei

Share this post


Link to post
Share on other sites

Sorry for doing it, but this needs a bump. Thanks for anyone who can help out with this issue.

Share this post


Link to post
Share on other sites

No real need to bump your thread during the same day, but where are you getting the error? Can you post the full error for us?

Share this post


Link to post
Share on other sites
No real need to bump your thread during the same day, but where are you getting the error? Can you post the full error for us?

Sorry, this is the error (server-side):

7:52:23 Error in expression < str(_this select 1);
_playerclientid = owner (_this select 1);
diag_log("CHECK">
7:52:23   Error position: <owner (_this select 1);
diag_log("CHECK">
7:52:23   Error owner: Type String, expected Object

Share this post


Link to post
Share on other sites
Show the full code.

Client:

"serverresponse" addPublicVariableEventHandler {
// do stuff with server response
};
playerclientid = player;
publicVariableServer "playerclientid";

Server:

"playerclientid" addPublicVariableEventHandler {
_playerclientid = owner (_this select 1);
// do a bunch of stuff that sets the responsefromserver variable
_playerclientid PublicVariableClient "responsefromserver";
};

The stuff that I left out are fully working and tested and cannot contribute to the errors I'm getting.

Share this post


Link to post
Share on other sites

The error message tells us that you are still transfering or are using a string somewhere instead of the object reference...

Error owner: Type String, expected Object

Xeno

Share this post


Link to post
Share on other sites
The error message tells us that you are still transfering or are using a string somewhere instead of the object reference...

Error owner: Type String, expected Object

Xeno

Sorry, could you elaborate on that? I don't really understand what you mean. Are you saying that this error might happen if I use the variable first somewhere else?

Share this post


Link to post
Share on other sites

Without seeing the rest of your script(s) we can only guess what you are doing. You are most likely sending a second playerclientid pv with a string somewhere (but that is just guessing too).

And what's the "str(_this select 1)" error ?

Xeno

Share this post


Link to post
Share on other sites
Without seeing the rest of your script(s) we can only guess what you are doing. You are most likely sending a second playerclientid pv with a string somewhere (but that is just guessing too).

And what's the "str(_this select 1)" error ?

Xeno

So you're saying I cannot use the variable anywhere else?

Share this post


Link to post
Share on other sites

so this worked for me

//client

"ServerEvent" addPublicVariableEventHandler {

call (_this select 1);

ServerEvent = nil;

};

//server

"playerid" addPublicVariableEventHandler {

_playerid = owner (_this select 1);

ServerEvent = {hint "Here comes the server!"};

_playerid PublicVariableClient "ServerEvent";

ServerEvent = nil;

};

//execute local on client machine to retrieve server message

playerid = player;

publicVariableServer "playerid";

EDIT: fi sure you could also switch the code execution of ServerEvent for better security and less traffic in this example

Edited by raggamafia

Share this post


Link to post
Share on other sites

removed

Edited by gammadust
no point

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  

×