Could someone provide a small example of adding a command that would trigger an if statement in PHP? I can't seem to get it to work. I know it goes in a while loop to keep it going, but not really sure what string fgets(STDIN, 1024) actually returns.
If you could, please just show something like a command "-test" echo out a center message.
I tried lookin' through Afros Project Freedom script, but I don't really see what I've done wrong. Thanks for any help.
PHP User Commands
Re: PHP User Commands
strstr don't seem to work when I include the "-", but if I just search for "test" it will work. Same stands for checking the ":". I've tried strstr, preg_match .. but not workin for some reason.
If that works, I don't see why this wouldn't ..
Code: Select all
$str = "Light: -test";
if (strstr($str, ': -test'))
{
echo 'hi';
}
Code: Select all
while (1)
{
$input = rtrim(fgets(STDIN, 1024));
if (strstr($input, ': -test'))
{
echo "console_message message\n";
}
}
- dukevin
- Round Winner
- Posts: 219
- Joined: Mon Aug 30, 2010 8:25 am
- Location: Southern California
- Contact:
Re: PHP User Commands
Try this:
When a player says "-test" it will center message "Test"
Code: Select all
<?php
while (1) {
$line = rtrim(fgets(STDIN, 1024));
if(preg_match("/^CHAT/", $line))
{
$stuff = explode(" " ,$line);
if($stuff[2] == '-test')
{
echo "center_message Test\n";
}
}
}
?>