Help required for creating a php message feed for GMOD loading screens
2 replies, posted
So this question is probably easy to answer, but I need some help nonetheless.
I want to have a feed for my loading screen where I can display some text that changes every few seconds as the player is connecting.
I know it is probably a simple job, but being a bit of a noob, I am afraid that if I have a loop that echo's a random array entry every 3 seconds, then echos a new one, waits 3 seconds, so on so forth... I'm afraid the page wont "finish loading" at any point, which is something I do not want.
Optimally, I would like this to read from a database. I have code that can read from a database of my choosing, thats no issue, and it can return the database information as PHP (and maybe also JSON but i dont like that method), so uh, yeah... could I get a hand here?
If you are still unsure what I'm talking about... its like those servers that when connecting, read stuff like:
"Stealing your PayPal." then 3 seconds later, "Banning your account." etc...
[QUOTE=Scorn1;42003431]I am afraid that if I have a loop that echo's a random array entry every 3 seconds, then echos a new one, waits 3 seconds, so on so forth... I'm afraid the page wont "finish loading" at any point
.....
If you are still unsure what I'm talking about... its like those servers that when connecting, read stuff like:
"Stealing your PayPal." then 3 seconds later, "Banning your account." etc...[/QUOTE]
The changing text is done using javascript, it executes after your page has 'loaded', you don't need to keep echoing stuff from PHP.
In the javascript you have an array of words/sentences. In the page HTML you have an element with a unique id. The javascript finds the element using its id and replaces the content of it (then starts a timer to repeat a few seconds later).
[code]<html>
<body>
<div id="loadingtext">This gets replaced</div>
<script type="text/javascript">
var keywords =
[
"Unleashing T-virus",
"Herping the derp",
"Emptying c:\\windows\\system32",
"Killing zombies",
"Firing ion cannon",
"Trolling 12 year olds",
"Smoking a bowl",
"Watching files load",
"Burning ants with a magnifying glass",
"Crashing hl2.exe",
"Taking the red pill",
"Taking the blue pill",
"Cleaning chainsaw",
"Disposing of the bodies",
"Experimenting with cannibalism",
"Enlarging e-penis",
"Making cheese",
"\"Liberty Prime online. Defense systems active. Protect the president!\"",
"Growing watermelons",
"Changing the language on your phone to Phillipino",
"Hacking teh LUA's"
];
var bCanChangeStatus = true;
function ChangeText ( ) {
if ( bCanChangeStatus )
{
var keyword = keywords[ Math.floor( Math.random() * keywords.length ) ] /* get a random entry from the keywords array */
document.getElementById( "loadingtext" ).innerHTML = keyword;
}
setTimeout( "ChangeText()", 2500 ); /* set timer to call this function again in 2.5 seconds */
}
ChangeText(); /* call the function the first time, after this it uses the timer to keep firing */
</script>
</body>
</html>[/code]
thanks wh1t3rabbit, that helped alot.
Sorry, you need to Log In to post a reply to this thread.