Loading screen help

I am completely stumped on how to do this, i can’t work out how to make it change loading screen depending on the map. I a made a Battlefield like gamemode and i would like there to be a specific loading screen for each map… I don’t know if i should use PHP or ingame LUA… Please help if you can!!!

Server: 37.187.73.200:27055

You can use PHP as far as I know of. Was that the answer you were looking for?

The map name (excluding the .bsp extension) can be passed on through URL so that you can access it with PHP’s superglobal $_GET[ ‘variable’ ]. For example, if you were to have to LoadingURL “http://mydomain.com/loading.php?steamid=%s&map=%s” then you could get the name of the map using


$map = $_GET[ 'map' ]

Then you could use JavaScript or PHP itself to set the background image or the image of a specific part of the page.

[editline]8th May 2014[/editline]

For more information, consult the wiki: http://wiki.garrysmod.com/page/Loading_URL

i’d do something like


$_GET['map'] if(isset blahblah blah include_once(map1.php) else include_once(map2)

I’m rusty with php, actually more or less a noob :stuck_out_tongue:

Same, i don’t know much PHP and no Javascript… So if anyone can help me further please do!

Something along those lines. For the sake of efficiency and neatness I suggest you use arrays and keys to decide what file to include:


<?php
$maps = array( 

	"map_1" => "map1.php",
	"map_2" => "map2.php",

);

$map = $_GET[ "map" ];
if ( isset( $map ) ) {

	include( $maps[ $map ] )

}


Otherwise you could just name the file the same name as the map and just include( $map.".php" ).

This is just really insecure core. Use the following:



if(isset($_GET['map']) && in_array($_GET['map'], $maps)) {
	include $maps[$_GET['map']];
}


If you don’t check if the map is actually in the maps array, people could possibly inject code in your server.

Like i said… i’m a noob with PHP where do i put the code???

Wrap it in <?php ?> tags in the loadingpage.php file that your server links to. Cyber is 100% correct; check that it exists in the array, otherwise there’ll be an issue with cross-site injection. Additionally, I’d recommend setting the string to all lower-case for the map-name. Some maps use DemENtEdCAmeLCaSe

PHP is a serverside language for websites. Just make a .php on your web server.


<?php
$maps = array( 

	"map_1" => "map1.php",
	"map_2" => "map2.php",

);

if( isset( $_GET[ 'map' ] ) && in_array( strtolower( $_GET[ 'map' ] ), $maps ) )
{
	// Include map_name.php
	include( $maps[ strtolower( $_GET[ 'map' ] ) ] . ".php" );
}
?>

$map = strtolower( $map ); for lower - do it for the include too.

No No… I really don’t understand PHP at all


 <?php
$maps = array( 

	"bf_skyscrapers" => "rooftops.php",
	"bf_scrapmetal" => "scrapmetal.php",

);

$map = $_GET[ "map" ];
if(isset($_GET['map']) && in_array($_GET['map'], $maps)) {
	include $maps[$_GET['map']];
}
?>


Thats what i have and i have the extent ion on the end of the loading screen url… what do i change?

[editline]8th May 2014[/editline]

I know :3, i do know how to code Lua, i just never got round to PHP or web based code.

So that code is essentially all you need. Use the one I posted with the string to lower…

Here’s your version “fixed”. PHP is a language where double quotes and single-quotes actually mean something unless they’ve changed it. But, back in 4 and 5 days, double quotes actually got “parsed” whereas single-quotes are literal, therefore faster.

What this simple script does is it gets passed the map by gmod ( or anyone wanting to try x-site scripting/injection ), the script then defines the maps array, defines map as the getter from the URL ( you know those things you see in the url like ?xxx=123 and &xyz=321 ); ? is the FIRST argument whereas & represents > 1, so “unlimited” arguments can be passed using ? as first, then & for each variable thereafter. so ?xxx=123 is a _GET[ ‘xxx’ ] and its value is 123, so the same thing occurs with map.

you’re just assigning it to a variable because it gets repeated… I changed it a bit so it checks the isset first; important. Then it defines it as we need it. Then it checks if it is in the array ( if you’re really craving nano-seconds you can put the maps array inside the isset… ), if it is in the array then include that php file…

So, make sure you create a rooftops.php and scrapmetal.php in the same directory as this, or you can have it include from a sub-directory… use a single . to concatenate scripts, use ’ 's.

php is essentially a pre-processor for html that allows more flexibility and dynamic content. It can even be used with ajax to have a seamless and quite nice integration. So a php file can contain nothing but HTML; so for your two php files make an html page.

[lua]<?php
$maps = array(

'bf_skyscrapers' =&gt; 'rooftops.php',
'bf_scrapmetal' =&gt; 'scrapmetal.php',

);

if( isset( $_GET[ ‘map’ ] ) )
{
map = strtolower( _GET[ ‘map’ ] );
if ( in_array( $map, $maps ) )
{
include( maps[ _GET[ ‘map’ ] ] );
};
};
?>[/lua]

If you want to start going a little more in depth. Make this the default content for your loading pages:


<?php
include( 'header.php' );
?>


HTML CONTENT


<?php
include( 'footer.php' );
?>

That’s your very first very BASIC template system. A header and footer is all you really need; the content can be added in the center… With divs you have more freedom too. You can even get more complicated like phpBB, vBulletin, ACMS ( mine ) and others have done by creating plain-text variables that get replaces. It could be something like:

{TEMPLATE_HEADER}{TEMPLATE_CONTENT}{TEMPLATE_FOOTER}

Which then opens 3 files based on whatever. Header could have more of those, content too, footer too.

PHP is a fun language, I recommend it.

Also, if you can’t figure out how to fix your problem, i invite you tu use http://gloading.com/ where you can simply use <span id=“mapname”>unknown</span> into your loading page’s html code to show the current map name when someone will join your server.
See the base template at http://gloading.com/loading/base/index.html

If any question on how to use gloading, pm me.