Jump to content
Sign in to follow this  
KeyCat

Check for dedicated server?

Recommended Posts

Hi,

Is there a way to check if a script is running on a dedicated server?

I'm aware about putting a GL named "Server" but that doesn't tell if it's a dedicated server or if the script is running on a hosted server.

/Christer (a.k.a KeyCat)

Share this post


Link to post
Share on other sites

Uh, just guessing here, but there was something about the "player" on dedicated servers, it did not have one or it was named something special iirc.

Share this post


Link to post
Share on other sites

Yea, I also have a very dim memory of a dedicated server not recognizing "player"... Anybody knows the details?

/Christer (a.k.a KeyCat)

Share this post


Link to post
Share on other sites

Indeed, "player" is undefined on a dedicated server. The problem: the same is true for SP missions in both intros or outros. So, the correct and working heuristics for determining if a script is running on a dedicated server consists of no fewer than two (2) steps.

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

1) Determine if we're in SP or MP mode

2) If we're in MP mode and player is undefined -> script is on a deddy

Here's the code to do so:

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

_mpmode = false

_dedicated = false

;

; 1) determine wether the mission is running in MP or SP mode

;

; In SP mode, the missionStart command returns [0,0,0,0,0,0].

; In MP mode, the result is *not* [0,0,0,0,0,0]

_mpmode = ({_x > 0} count missionStart) > 0

;

; 2) Deddy or not?

;

_dedicated = _mpmode && isNull player

;

; Now we can use the boolean variable _dedicated to decide what to do

;

?! _dedicated: hint "Server is not dedicated, exiting"; exit

; Code that should run on dedicated server only follows

; ...

There is another method to detect SP/MP mode. This uses the playersNumber command. Like so:

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

;

; 1a) Alternative to step one above:

;

; playersNumber <side> returns 0 for all sides in SP

;

...

_mpmode = (playersNumber east + playersNumber west + playersNumber resistance + playersNumber civilian) > 0

...

Disclaimer: I am writing this from memory. Code is untested. Comments and corrections welcome.

Share this post


Link to post
Share on other sites

Killswitch, thanks for the code snippets will try it out later and let you know!

/Christer (a.k.a  KeyCat)

Share this post


Link to post
Share on other sites

FYI...

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

if (isNull player) then {goto "dedicated_server"}

Worked as a charm for me!

Thanks again!

/Christer (a.k.a KeyCat)

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  

×