Jump to content
Sign in to follow this  
tophe

Running script when player connects

Recommended Posts

I need to run a script to public a few variables when a player joins in progress. I know this have been discussed but I can't find the answer to it.

I have one variable (at the moment) that needs to be broadcasted to any newly connected players. So I made a script of one line:

jip.sqs

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

publicVariable "to_dc"

But then I want that script to be run when a player connects. How do I do that?

I tried a trigger going:

Cond: local server and onplayerconnected

On Act: [] exec "jip.sqs"

but obviously that won't work.

Maybe I could just fire the trigger on any client and start the script with ?(!local server):exit and then public the variable.

But how do I get the trigger to start when a new player is connected?

Share this post


Link to post
Share on other sites

Add this line in init.sqs:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">?(local server): onplayerconnected "[_name,_id] exec ""jip.sqs"""

Share this post


Link to post
Share on other sites

Thank you!

I acctually found that here on the forum after posting. But I wasn't sure that was the sollution. Thank you!

Share this post


Link to post
Share on other sites

That acctually didn't work.

It seems that the script is run on the newly connected client, so it will publicVariable his version of to_dc. That makes everyone get the variable set to zero.

I need the script to be run on the server only when a player connects. So that the server will publicVariable its version of the variable. How do I do this?

Share this post


Link to post
Share on other sites

Heh??

Quote[/b] ]It seems that the script is run on the newly connected client

So you are saying that

?(local server):-->makes a script run on a client? crazy_o.gif

Are U sure U have a GameLogic called "server" on your map?

Share this post


Link to post
Share on other sites

Yep I have the logic.

I'm not 100% sure it acctually runs it on the newly connected client. But the script only gives PublicVariable "to_dc".

And it turns into 0 when the script is run... the only one that has the variable set at 0 is the JiP client. If it would publicvariable the to_dc from the server it would turn into what ever the current value is.

The thing is that this variable is increased by 1 every time a player is killed, then publicVariable it and gives the amount in a Hint on all clients. And after a player has JiP and a player is killed it says "casualties 1". No matter what the value was earlier in the game. That means that to_dc is set to 0 when someone JiP.

I can't figure this one out.

Do you have a sollution for updating variables on a player that joins in progress? I may be way out of line here...

Thank you for taking time.

Share this post


Link to post
Share on other sites

w/o game logic

in some init.sqs

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_ex = "logic" createvehicle [0,0,0];

IS_SERVER = local _ex;

delete _ex;

IS_DEDICADED = IsNull player;

in some script

[/code]

...

;Server

?IS_SERVER:[] run "serverscript.sqs"

...

;Dedicaded server

?IS_DEDICADED:goto "skipVisual"

...




			
		

Share this post


Link to post
Share on other sites

...can`t edit post...

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_ex = "logic" createvehicle [0,0,0];

IS_SERVER = local _ex;

deletevehicle _ex;

IS_DEDICADED = IsNull player;

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

...

;Server

?IS_SERVER:[] run "serverscript.sqs"

...

;Dedicaded server

?IS_DEDICADED:goto "skipVisual"

...

Share this post


Link to post
Share on other sites

I'm not sure what you mean the Mr.Flea...

What would this acctually do?

_ex = "logic" createvehicle [0,0,0];

IS_SERVER = local _ex;

delete _ex;

IS_DEDICADED = IsNull player;

And what would this do?

...

;Server

?IS_SERVER:[] run "serverscript.sqs"

...

;Dedicaded server

?IS_DEDICADED:goto "skipVisual"

...

Where is skipVisual and what should I put there?

Is the IS_DEDICATED and IS_LOCAL acctually commands? Will this help me remove the "dummy player" on the ded server?

Also I don't recognize the way the first thing you want in INIT.SQS is set up. Is that the correct way to formulate the code?

Also should both these be includet to fix my problem? What should be in the serverscript?

Do you think you could explain a bit more how I could use your sollution and what it acctaully does?

Thank you for your time!

Share this post


Link to post
Share on other sites

My head isn't ready to think about local and global issues, but I'd like to know what you want to happen when a player connects.

Share this post


Link to post
Share on other sites

Sorry Flea.. I think I figured out what you ment.

In INIT a logic is created, that is then checked if it exists. If it does the client is server, since locigs are always local to the server. Then the IS_SERVER variable is true if there is no player on the client. And the only client that would happen on is the dedicated server.

I allready have a server logic, I need it to run some scripts I use.

All I really need to find out is how to update some variables on a connected client.

As for the "dummy player" I mentioned... It seems my Dedicated Server counts itself as a player. I have a trigger that will only run when the player is killed (Act: not alive player). This one is of course local. That trigger will fire instantly when the mission starts on a dedicated server. Never anywhere else... Weird uh?

Share this post


Link to post
Share on other sites
Quote[/b] ]in some init.sqs

Code Sample

_ex = "logic" createvehicle [0,0,0];

IS_SERVER = local _ex;

delete _ex;

IS_DEDICADED = IsNull player;

Be carefull Mr Flea,this is init SQF wink_o.gif

The semicolons can cause errors in sqs.

Ok,maybe a delay before the PV

Jip.sqs

?(local player):exit

~2

PublicVariable "to_dc"

exit

Pls let me know if u figured it out smile_o.gif

Share this post


Link to post
Share on other sites

If you want to load variables to the player when they start the map and assuming the variables are public every time they change, do this in init.sqs:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">?!local server : goto "skip"

variable1 = x

publicvariable "variable1"

variable2 = x

publicvariable "variable2"

variable2 = x

publicvariable "variable3"

#skip

variable1=variable1

variable2=variable2

variable3=variable3

x is the initial value you want to set with the server at the start of the game, be it a number or text. With that you avoid errors with initial players when they go through the variable checking process.

Share this post


Link to post
Share on other sites

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

?!local server : goto "skip"

variable1 = x

publicvariable "variable1"

variable2 = x

publicvariable "variable2"

variable2 = x

publicvariable "variable3"

#skip

variable1=variable1

variable2=variable2

variable3=variable3

If I have this in init, wouldn't that mean that it is only run the first time the map is started? That means that if a player JiP it will skip right to the #skip. Coming there it will set to_dc to to_dc. This will still happen locally it seems, so on the JiP client the to_dc = 0 when it starts and when running to_dc = to_dc it will still be 0 since it hasn't got any new value from the server. Or will the init.sqs run on all clients when someone connects? Otherwise I cannot see how this sollution could work.

I need the server to know that a new player has connected and the have server do publicVariable "to_dc". Since the value is the same on all connected clients it shouldn't matter that the other clients are updated. The variable will still be the same.

Every time to_dc is updated ingame it is first done locally on the client that has the killed player. Then this client will publicVariable it.

I hope you follow me...

Share this post


Link to post
Share on other sites

You could at least try it. According to my experience the process will establish the to_dc variable to the current value of to_dc that everyone else has, if the variable is set to public broadcast in other scripts or triggers so the client can detect it.

Init.sqs is run individually by each client when they start the game, so that's where you should cram all the stuff that should happen when a player starts the game. The server part is only run at the very start and that's where the initial values should be set.

If the value is the same for everyone in the game, it shouldn't bother anything if the variable is made public every time it's changed.

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  

×