Author Topic: Stop Players from accessing pages when they are in the hopsital  (Read 1238 times)

Offline cdoyle

  • Level 11
  • *
  • Posts: 67
  • Reputation: +1/-0
    • View Profile
Hi,

Working on my ezRPG game, and want to stop players from accessing all pages but the inventory when they are in the medical ward.

When they are in the medical ward,  their ID is listed in the medical ward table.

table medical_ward
HOS_ID_PK
Time_Left

Is there a way to display a message on the screen saying 'you are in the medical ward for xx minutes, use some of your meds in your inventory to get out early'

So the only page, they can click on and see would be their inventory.

I'm hoping there is a way to do this, without having to add code to every single page within the game.  Since I know sooner or later, I'll forget to add it and that page will be accessible.

Is there a way to put something in the private header, to accomplish this?

Offline raestlyn

  • Level 29
  • **
  • Posts: 463
  • Reputation: +9/-5
    • View Profile
Re: Stop Players from accessing pages when they are in the hopsital
« Reply #1 on: June 18, 2008, 06:36:20 AM »
Just include a simple sql check that looks the time_left and if its >0 deny access to other pages. I would make you one right now, but I'm in a hurry..

I'll post one later if I find some time.


I can send you pics of my cocks if you want reference.


Offline mobeamer

  • Level 13
  • *
  • Posts: 93
  • Reputation: +0/-0
    • View Profile
    • Untouchable Games
Re: Stop Players from accessing pages when they are in the hopsital
« Reply #2 on: June 18, 2008, 10:49:53 AM »
I'm not familiar with the code base you are working with, but usually there is a master include file that gets included on all pages.

If you add something like the following to the end of it, that might work for you.

$player = mysql_execute("select time_left from table medical_ward where playerID = " . $playerID);

if($player->time_left > 0)
{
    print "XXXXX";
exit();
}


The exit function will kill any code that is supposed to run after it. So you may need to move this code around to get it to display where you want.


Time_Left

I build games
My Blog

Offline cdoyle

  • Level 11
  • *
  • Posts: 67
  • Reputation: +1/-0
    • View Profile
Re: Stop Players from accessing pages when they are in the hopsital
« Reply #3 on: June 18, 2008, 07:05:11 PM »
I'm not familiar with the code base you are working with, but usually there is a master include file that gets included on all pages.

If you add something like the following to the end of it, that might work for you.

$player = mysql_execute("select time_left from table medical_ward where playerID = " . $playerID);

if($player->time_left > 0)
{
    print "XXXXX";
exit();
}


The exit function will kill any code that is supposed to run after it. So you may need to move this code around to get it to display where you want.


Time_Left

Yes I've been looking at the includes for the pages. 
Each page has
include("templates/private_header.php");
and also
include("lib.php");

I've been wondering if there is a way to put something in the private header, but have never been able to get it to work.

Do you think the private header would be the right page to use?  Or should I try it somewhere else?

Offline cdoyle

  • Level 11
  • *
  • Posts: 67
  • Reputation: +1/-0
    • View Profile
Re: Stop Players from accessing pages when they are in the hopsital
« Reply #4 on: June 18, 2008, 07:56:41 PM »
OK, I was able to make it work using this in my private header

<?php
$playerdead = $db->execute("select `Time_Left` from `medical_ward` where `playerdead_ID` =" . $player->id);
$playerdead1= $playerdead->fetchrow();
echo $playerdead1[Time_Left];
if($playerdead1 [Time_Left] > 0)
{
    echo "You're in the Hospital";
exit();
}

So now how would I grant access to the inventory.php, so they can use the meds to get out of the hospital early?

Offline cdoyle

  • Level 11
  • *
  • Posts: 67
  • Reputation: +1/-0
    • View Profile
Re: Stop Players from accessing pages when they are in the hopsital
« Reply #5 on: June 18, 2008, 08:41:27 PM »
OK, I added to this a little.

It now says who put you in the hospital.
I still need to know tho, how to grant access to the inventory page?

I was also thinking, to really make people know they are dead, it would be cool to change the background color of the page, or put an image in the background of a skull and bones or something.   How would I do that with this? 

Code: [Select]
<div id="content">
<?php
$playerdead 
$db->execute("SELECT p1.username as killedby, Time_Left FROM medical_ward m
INNER JOIN players p1 ON m.Killed_By_ID = p1.id
where playerdead_ID = 
$player->id");

$playerdead1$playerdead->fetchrow();

if(
$playerdead1 [Time_Left] > 0)
{
    echo 
"You were put in the hospital by " .$playerdead1[killedby] ."<p>";
echo "You have \n"  $playerdead1[Time_Left] . "\n Minutes remaining";
exit();
}


?>

« Last Edit: June 27, 2008, 06:48:36 PM by cdoyle »

Offline mobeamer

  • Level 13
  • *
  • Posts: 93
  • Reputation: +0/-0
    • View Profile
    • Untouchable Games
Re: Stop Players from accessing pages when they are in the hopsital
« Reply #6 on: June 18, 2008, 08:48:04 PM »
Why not pay me and then I can build it for you.... :D

jk

The simplest thing is to put a link to the medical page with a flag to skip the check so, your code might look like this...

$playerdead = $db->execute("select `Time_Left` from `medical_ward` where `playerdead_ID` =" . $player->id);
$playerdead1= $playerdead->fetchrow();
echo $playerdead1[Time_Left];
if($playerdead1 [Time_Left] > 0 && $_GET['skipDeathCheck'] != 'Y')
{
    echo "<a href='medical.php?skipDeathCheck=Y'>You're in the Hospital</a>";
exit();
}


Now this is not hack proof...which is why it's a good idea to store game stats in the database.

Alternatively you can look at the page name and decide not to show the death Check...this may depend on your version of PHP, but you can try it:

$playerdead = $db->execute("select `Time_Left` from `medical_ward` where `playerdead_ID` =" . $player->id);
$playerdead1= $playerdead->fetchrow();
echo $playerdead1[Time_Left];
if($playerdead1 [Time_Left] > 0 && $PHP_SELF != 'medical.php')
{
    echo "You're in the Hospital";
exit();
}

Since I'm helping you out with this do me a favor and create one post in another section of this forum. I like this forum and I want it to grow.


I build games
My Blog

Offline mobeamer

  • Level 13
  • *
  • Posts: 93
  • Reputation: +0/-0
    • View Profile
    • Untouchable Games
Re: Stop Players from accessing pages when they are in the hopsital
« Reply #7 on: June 18, 2008, 08:48:54 PM »
You'll have to use your imagination on the rest...there are enough clues now...no?

I welcome anyone else to help this young fella out.

I build games
My Blog

Offline cdoyle

  • Level 11
  • *
  • Posts: 67
  • Reputation: +1/-0
    • View Profile
Re: Stop Players from accessing pages when they are in the hopsital
« Reply #8 on: June 18, 2008, 09:54:27 PM »
Why not pay me and then I can build it for you.... :D

jk

The simplest thing is to put a link to the medical page with a flag to skip the check so, your code might look like this...

$playerdead = $db->execute("select `Time_Left` from `medical_ward` where `playerdead_ID` =" . $player->id);
$playerdead1= $playerdead->fetchrow();
echo $playerdead1[Time_Left];
if($playerdead1 [Time_Left] > 0 && $_GET['skipDeathCheck'] != 'Y')
{
    echo "<a href='medical.php?skipDeathCheck=Y'>You're in the Hospital</a>";
exit();
}


Now this is not hack proof...which is why it's a good idea to store game stats in the database.

Alternatively you can look at the page name and decide not to show the death Check...this may depend on your version of PHP, but you can try it:

$playerdead = $db->execute("select `Time_Left` from `medical_ward` where `playerdead_ID` =" . $player->id);
$playerdead1= $playerdead->fetchrow();
echo $playerdead1[Time_Left];
if($playerdead1 [Time_Left] > 0 && $PHP_SELF != 'medical.php')
{
    echo "You're in the Hospital";
exit();
}

Since I'm helping you out with this do me a favor and create one post in another section of this forum. I like this forum and I want it to grow.



Thanks for your help on this, believe me I've been learning a lot since I started this game.

I tried the first example, and it works.
but ya I see what you mean that it can be bypassed pretty easily.

The second one I tried, and the page loads just like it should, it gives the warning about being dead etc.
But when I try and open inventory.php it doesn't let me in.

My server uses php version 4.4.8, do you know if it would work on this version?

I'm not really familiar with $PHP_SELF;
so I googled it, and see a bunch of links saying to avoid it, is this correct? 
Or is it safe to use it, in the fashion I need?

I'm trying to figure out how this line works, if Time_Left is > then 0.  Does the $PHP_SELF tell it that inventory.php is OK to access?

if($playerdead1 [Time_Left] > 0 && $PHP_SELF != 'inventory.php')


Thanks again for your help, I'm learning a ton today!


Offline mobeamer

  • Level 13
  • *
  • Posts: 93
  • Reputation: +0/-0
    • View Profile
    • Untouchable Games
Re: Stop Players from accessing pages when they are in the hopsital
« Reply #9 on: June 19, 2008, 08:42:55 AM »
>>Does the $PHP_SELF tell it that inventory.php is OK to access?

$PHP_SELF holds a string of the url of the page you are currently on. You can check that to see if you are on the inventory page.

I'm not sure about the saftey of it. There may be another, newer way to access the current page you are on but the basic logic is to check that the page you are on is one that makes the deathCheck irrelavant.

>>if($playerdead1 [Time_Left] > 0 && $PHP_SELF != 'inventory.php')

In English...
If the player is supposed to be dead for some more time
AND the page is NOT the inventory page
Go ahead and display a warning message.

The && portion is the AND piece.





I build games
My Blog

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal