Weather[Resolved]
Weather[Resolved]
Hey, I've been searching around on the forum, but can't find anything about this. The thing is that I've got some pictures that I've made in photoshop(Weather pictures) Like clouds etc., Is it possible to add these picture to a folder(with php code) that randomly set a weather when I log in.
One time I log in it's sunny, the other time Cloads on the picture, (Got both pictures). Hope you understand what I mean
Thanks, Huezzer.
			
			
													One time I log in it's sunny, the other time Cloads on the picture, (Got both pictures). Hope you understand what I mean
Thanks, Huezzer.
					Last edited by Huezzer on Wed Mar 23, 2011 3:18 pm, edited 1 time in total.
									
			
						
										
						- 
				alexander19
- Posts: 180
- Joined: Fri Apr 02, 2010 1:05 pm
Re: Weather
Maybe you could do a random thing,which checks everytime you log in:
If you want to make sure that the weather image will be different than the previous time you logged in,you could create another tab in your players table and call it weather.
And then you could use something like this:
			
			
									
						
										
						Code: Select all
$chance = rand(0,100);
if($chance <=50)
//sunny weather
echo "<img src='images/weather/sunny_weather.jpg>";
elseif($chance <= 100)
//clouds
echo "<img src='images/weather/clouds_weather.jpg>";
.
.
. and so onAnd then you could use something like this:
Code: Select all
$playerinfo = mysql_fetch_assoc(mysql_query("SELECT name,weather from players where name='$player'"));
$pl_weather = $playerinfo['weather'];
$chance = rand(0,100);
//now we are checking  if the last weather image the player got,wasn't sunny:
if($chance <=50 && $pl_weather!='sunny'){
//sunny weather
echo "<img src='images/weather/sunny_weather.jpg>";
$weather ='sunny';
mysqli_query("UPDATE players set weather ='$weather' where name='$player'");
}
elseif($chance <= 100 && $pl_weather!='clouds'){
//clouds
echo "<img src='images/weather/clouds_weather.jpg>";
$weather ='clouds';
mysqli_query("UPDATE players set weather ='$weather' where name='$player'");
}
Re: Weather
Am I going to add this code: 
In a new php document or where?, Login.php?
Thanks, Huezzer.
			
			
									
						
										
						Code: Select all
$chance = rand(0,100);
if($chance <=50)
//sunny weather
echo "<img src='images/weather/sunny_weather.jpg>";
elseif($chance <= 100)
//clouds
echo "<img src='images/weather/clouds_weather.jpg>";Thanks, Huezzer.
- 
				alexander19
- Posts: 180
- Joined: Fri Apr 02, 2010 1:05 pm
Re: Weather
You can add it on any php page you want to show the weather images.
			
			
									
						
										
						Re: Weather
Doesn't it update all the time then?, Or is it possible to make it same weather until I re-log in?   
 
Thnaks, Huezzer.
			
			
									
						
										
						 
 Thnaks, Huezzer.
- 
				alexander19
- Posts: 180
- Joined: Fri Apr 02, 2010 1:05 pm
Re: Weather
If you want it to be the same all the time and change only when you login,you must save it inside a cookie/session or db.
If you want to go with the db:
Use this on your authenticate.php script:
And now,after you logged in you can get the weather from the db and echo the right image on every page:
But make sure you have a tab called "weather" inside your players table.
			
			
									
						
										
						If you want to go with the db:
Use this on your authenticate.php script:
Code: Select all
$chance = rand(0,100);
if($chance <=50 ){
//sunny weather
mysqli_query("UPDATE players set weather ='sunny'  where name='$player'");
}
elseif($chance <= 100){
//clouds
mysqli_query("UPDATE players set weather ='clouds' where name='$player'");
}Code: Select all
$playerinfo = mysql_fetch_assoc(mysql_query("SELECT name,weather from players where name='$player'"));
$pl_weather = $playerinfo['weather'];
if($pl_weather=='sunny')
//sunny weather
echo "<img src='images/weather/sunny_weather.jpg>";
elseif($pl_weather=='clouds')
//clouds
echo "<img src='images/weather/clouds_weather.jpg>";
Re: Weather
what is the "PhpMyAdmin" table information?, Like id?, or what do I have to add? and how do I link it, if I understand you right with the playerinfo update thing  second code
 second code 
Thanks, Huezzer.
			
			
									
						
										
						 second code
 second code 
Thanks, Huezzer.
Re: Weather
If you just want it random each time the player comes to the page, you can just use a session variable. So you put session_start(); in at the start of your php, and then use something like 
Then, changing the rand values to the range you want and using if statements, check the session value on the page and have it echo out the appropriate image.
This way you don't have to mess around with the database as yet. But if you haven't watched the first five tutorial videos yet, you should as they teach you this stuff in a realy easy to absorb manner.
			
			
									
						
							Code: Select all
if (!isset($_SESSION['currentweather'])) $_SESSION['currentweather']=rand(1,2);This way you don't have to mess around with the database as yet. But if you haven't watched the first five tutorial videos yet, you should as they teach you this stuff in a realy easy to absorb manner.
Fight Cycle : My latest Browser game WIP
Driftwurld : My Browser Game WIP
Philosopher Gamer : My Blog
			
						Driftwurld : My Browser Game WIP
Philosopher Gamer : My Blog
Re: Weather
Sorry, THe thing I want to do is to add the weather images in a square in the left corner that show the current weather in the game. And the thing is I want the code to make it randomly all the time,and it could be same weather twice like in the real world ^^, Also It will change every time you log in, 
Two different players can have same weather or different weather, ^^^Hope you know what I mean.
Thanks, Huezzer
			
			
									
						
										
						Two different players can have same weather or different weather, ^^^Hope you know what I mean.
Thanks, Huezzer
Re: Weather
Yep, I got you - that's why I'd just suggest using a $_SESSION variable as I noted. It's as easy as setting any normal variable (well, a bit more typing).
			
			
									
						
							Fight Cycle : My latest Browser game WIP
Driftwurld : My Browser Game WIP
Philosopher Gamer : My Blog
			
						Driftwurld : My Browser Game WIP
Philosopher Gamer : My Blog
