KeyCat 131 Posted August 3, 2004 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
benu 1 Posted August 3, 2004 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
KeyCat 131 Posted August 3, 2004 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
killswitch 19 Posted August 3, 2004 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
KeyCat 131 Posted August 3, 2004 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
KeyCat 131 Posted August 4, 2004 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