Who's in jail?

General Chat, Comments
Post Reply
njfrlng
Posts: 53
Joined: Tue Feb 04, 2014 9:51 pm

Who's in jail?

Post by njfrlng »

Im trying to wrap my head around how to make a module.

Im trying to make a module that shows who is in jail.

Im copying the users online module, but it looks like it pulls that information directly from the users table. (Via the online column)

I don't see anywhere in the databases a spot where jail time is stored.... If im understanding correctly, jail is a variable?

How would I pull that info?
njfrlng
Posts: 53
Joined: Tue Feb 04, 2014 9:51 pm

Re: Who's in jail?

Post by njfrlng »

my understanding, which is probably wrong is that I could simply change the FROM table to whatever table stores jail info.

$selectOnlineUsers = $db->Execute("SELECT * FROM `users` WHERE online='yes'");
User avatar
a_bertrand
Posts: 1536
Joined: Mon Feb 25, 2013 1:46 pm

Re: Who's in jail?

Post by a_bertrand »

The jail "flag" is not in the user table. It is stored in a so called "UserVariable" which uses the user_variables table.
Creator of Dot World Maker
Mad programmer and annoying composer
njfrlng
Posts: 53
Joined: Tue Feb 04, 2014 9:51 pm

Re: Who's in jail?

Post by njfrlng »

ive been through the user_vars but have no idea which var_id is the jail "flag".

When i go to the variables table (Which I'm assuming would define the var and its var_id) it says its empty.

http://prntscr.com/2rtgap
User avatar
a_bertrand
Posts: 1536
Joined: Mon Feb 25, 2013 1:46 pm

Re: Who's in jail?

Post by a_bertrand »

it's an auto defined "define" keyword... so use jail ;)
BTW check out the jail module, the lib.php file, and it should be pretty clear.
Creator of Dot World Maker
Mad programmer and annoying composer
njfrlng
Posts: 53
Joined: Tue Feb 04, 2014 9:51 pm

Re: Who's in jail?

Post by njfrlng »

I shall give that a shot!
njfrlng
Posts: 53
Joined: Tue Feb 04, 2014 9:51 pm

Re: Who's in jail?

Post by njfrlng »

I take it this is incorrect:

echo "<table class='plainTable'>";
echo "<tr valign='top'><td width='1%'><img src='{$webBaseDir}modules/jail/images/jail.jpg'></td>";
echo "<td><img src='{$webBaseDir}images/separator.gif' width='10'></td><td>";

if (! IsInJail())
{
TableHeader("Visiting the jail");
echo Translate("You will end up here if you commit some crime. Therefore think twice!");
TableFooter();
}
else
{
TableHeader("Jail Time");
echo Translate("Did something bad? Well you will have to wait %s in jail.", TimeInterval(time(), intval(GetUserVariable(jail))));
TableFooter();
}

TableHeader("Jailed Users");

echo "<table class='plainTable'>";

echo '<th>Username</th>';
echo '<th>Time Left</th>';

$selectJailedUsers = $db->Execute("SELECT * FROM `user_variables` WHERE value='jail'");

if($selectJailedUsers->EOF){
ErrorMessage("No users in jail currently!");
} else {
foreach ($selectJailedUsers as $results) {

echo '<tr><td>';
echo '['.trim($results[0].']'.$results[1]);
echo '</td><td>';
echo date('d/m/Y g:i:s A', strtotime(trim($results[5])));
echo '</td><td>';
}
}

echo "</td></tr></table>";
njfrlng
Posts: 53
Joined: Tue Feb 04, 2014 9:51 pm

Re: Who's in jail?

Post by njfrlng »

it works if i use the users table and select something from there.

I'm not getting my head around this variable stuff.

Do I not even need to pull from the user_variables table to show jailed users?
User avatar
a_bertrand
Posts: 1536
Joined: Mon Feb 25, 2013 1:46 pm

Re: Who's in jail?

Post by a_bertrand »

Maybe so ? ;)

Code: Select all

$selectJailedUsers = $db->Execute("SELECT * FROM `user_variables` WHERE variable_id=?",jail);
Creator of Dot World Maker
Mad programmer and annoying composer
njfrlng
Posts: 53
Joined: Tue Feb 04, 2014 9:51 pm

Re: Who's in jail?

Post by njfrlng »

Not sure if that works, might try later. But I ended up getting it to work this way:

Code: Select all

$result = $db->Execute("select users.username, user_variables.value
        from users left join user_variables on user_variables.user_id = users.id
        where user_variables.variable_id = ? and user_variables.value > ?", jail, time());

if (! $result->EOF)
{
    TableHeader("Who's in Jail?");
    echo "<table class='plainTable'>";
echo '<th>Username</th>';
echo '<th>Time Left</th>';

    $row = 0;
    while (! $result->EOF)
    {
        if ($row % 2 == 0)
            echo "<tr class='evenLine'>";
        else
            echo "<tr class='oddLine'>";
        echo "<td>{$result->fields[0]}</td>";
        echo "<td>" . TimeInterval(time(), intval($result->fields[1])) . "</td>";
        echo "</tr>";
        $result->MoveNext();
        $row ++;
    }
  
}
$result->Close();

  echo "</table>";
http://prntscr.com/2ruzbj

Now i just need to add a way to bust people out
Post Reply

Return to “General”