Check if player in game in php file
#1

Hi,

How in php file, check if speficic player is joined to my server?
Reply
#2

https://sampforum.blast.hk/showthread.php?tid=104299

****** is such a nice thing right!
Reply
#3

Quote:
Originally Posted by MerryDeer
Посмотреть сообщение
Hi,

How in php file, check if speficic player is joined to my server?
i can give you an example,
note: i did this in 2011 (dont judge! pls ppls)
PHP код:
<?php
$sIP 
"localhost";//server IP
$sPORT 7777;//server Port
require "SampQueryAPIxx.php";
$query = new SampQueryAPI($sIP$sPORT);
$sInfo $query->getInfo();
if(!
$query->isOnline()) { echo "Server Offline"; exit; }
echo 
'<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />';
$aPlayers $query->getDetailedPlayers();
if(!
is_array($aPlayers) || count($aPlayers) == 0)
{
echo 
"<br /><i>well, either something went wrong or there are no players</i>";
}
else
{
?>
<style type="text/css">
thead
{
    background-image: url("head.jpg");
}
table
{
    margin:35;
    border:1px solid #CCC;
    border-collapse:collapse;
}
tr.bottom
{
    background-image: url("head.jpg");
}
font
{
    opacity: 0.0;
    font-family:Roman;
    color:#cccccc;
}
font.exception
{
    opacity: 100.0;
}
p
{
    font-family:Arial;
}
td
{
    font-family:Verdana;
}
.highlight
{
background-image: url("row.png");
}
.normal
{
background-image: none;
}
.unselectable
{
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: -moz-none;
  -ms-user-select: none;
  user-select: none;
}
</style>
<center>
<p><?= $sInfo['hostname']; ?></p>
<table width="300" name="board" class="unselectable">
<thead class="head">
<td><b>ID</b></td>
<td align=middle><b>Name</b></td>
<td><b>Score</b></td>
<td><b>Ping</b></td>
</thead>
<?php
foreach($aPlayers as $sValue)
{
?>
<tr OnMouseOver="this.className='highlight'" OnMouseOut="this.className='normal'">
<td><?= $sValue['playerid'?></td>
<td><?= htmlentities($sValue['nickname']) ?></td>
<td><?= $sValue['score'?></td>
<td align=right><?= $sValue['ping'?></td>
</tr>
<?php
}
echo 
'<tr class="bottom"><td><font>.</font></td><td align=right><font class="exception">Autor: East_Crips</font></td><td><font>.</font></td><td><font>.</font></td></tr>';
echo 
'</table></center>';
}
?>
<!--
East_Crips 2011
!-->
looks like this: http://pasteboard.co/cwr4IPFQ6.png
(i jsut put in some random server to demonstrate)
on top is server name and below a table with player ifos

//EDIT: oh and most importantly, get the query API from https://sampforum.blast.hk/showthread.php?tid=104299
Reply
#4

He asked about a SPECIFIC player if online, not ALL the players.
Reply
#5

Quote:
Originally Posted by oMa37
Посмотреть сообщение
He asked about a SPECIFIC player if online, not ALL the players.
whoa whoa c'mon don't be so hostile
i was merely giving an example, i mean it's easy enough to pick and choose what you need...

i put this together just now
PHP код:
<?php
echo '<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />';
$sIP "127.0.0.1";//server IP
$sPORT 7777;//server Port
require "SampQueryAPIxx.php";
$query = new SampQueryAPI($sIP$sPORT);
if(!
$query->isOnline()) { echo "Server Offline"; exit; }
$aPlayers $query->getDetailedPlayers();
$idx array_search($_GET['target'],array_column($aPlayers,'nickname'));
if(
$idx !== false)
    echo 
$aPlayers[$idx]['nickname']." is online.";
else 
    echo 
$_GET['target']." is offline!";
?>
<!--
East_Crips 2016
!-->
simply provide the name per GET variable 'target' and thats it.
calling it like: localhost/ison.php?target=East_Crips
you'll receive a simple string saying either:

East_crips is online.
or
East_Crips is offline!

@op could even call this from a pawn script using HTTP()
but then again, that wouldn't make sense i mean if he's already on, he could check ingame anyways
Reply
#6

How in php file send response to sa-mp server?
Reply
#7

Quote:
Originally Posted by MerryDeer
Посмотреть сообщение
How in php file send response to sa-mp server?
so you are saying that you want to send the response to the server?
and by that im also assuming you want to call the php script from within the server while in-game?

but that would not make sense, i mean you want to see if a certain player is online,
why do it like this when you could just check the tab when youre in-game anyways

is that really what you wanted to do or did i get you wrong?


anyways, that's how it could be done, i put togethat a quick gm using a modified version
of that php in my previous post, im also be using y_commands here.
and again, really, this is only an example, not copy-paste material:

online.pwn
PHP код:
#include <a_samp>
#include <a_http>
#include <YSI\y_commands>
main(){}
forward isPlayerOnline(pIdresponsecontent[]);
YCMD:online(playeridparams[], help)
{
    if(
help) return SendClientMessage(playerid, -1"USAGE: /online [Player-Name]");
    if(
isnull(params)) return SendClientMessage(playerid, -1"/online [Player-Name] MISSING Player-Name");
    
printf("its %s",params[0]);
    new 
target[24+7];
    
format(targetsizeof target"target=%s",params[0]);
    
HTTP(playeridHTTP_POST"localhost/php/samp/Pdisplay/ison.php"target"isPlayerOnline");
    return 
1;
}
public 
isPlayerOnline(pIdresponsecontent[])
{
    new 
buff[128];
    if(
response == 200)//OK
    
{
        if(
content[0] == '1')
            
SendClientMessage(pId, -1"that player is online.");
        else
            
SendClientMessage(pId, -1"that player it offline!");
    }
    else
//anything else not OK
    
{
        
format(buffsizeof buff,"ERROR %d",response);
        
SendClientMessage(pId, -1buff);
    }

ison.php
PHP код:
<?php
$sIP 
"127.0.0.1";//server IP
$sPORT 7777;//server Port
require "SampQueryAPIxx.php";
$query = new SampQueryAPI($sIP$sPORT);
if(!
$query->isOnline()) { echo "Server Offline"; exit; }
$aPlayers $query->getDetailedPlayers();
$idx array_search($_POST['target'],array_column($aPlayers,'nickname'));
echo (
$idx === false)?0:1;
?>
Reply
#8

No i want make call from php file, to sa-mp server, like in application player do response, i want to get response to sa-mp server
Reply
#9

Not the best way but make a row in your MySQL table called "IsOnline" and set it to true when a player logs in, then set to false when a player logs off.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)