PHP User Commands

What do you want to see in Armagetron soon? Any new feature ideas? Let's ponder these ground breaking ideas...
Post Reply
User avatar
Light
Reverse Outside Corner Grinder
Posts: 1667
Joined: Thu Oct 20, 2011 2:11 pm

PHP User Commands

Post by Light »

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.
User avatar
Light
Reverse Outside Corner Grinder
Posts: 1667
Joined: Thu Oct 20, 2011 2:11 pm

Re: PHP User Commands

Post by Light »

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.

Code: Select all

$str = "Light: -test";

if (strstr($str, ': -test'))
{
	echo 'hi';
}
If that works, I don't see why this wouldn't ..

Code: Select all

while (1)
{
    $input = rtrim(fgets(STDIN, 1024));
    
    if (strstr($input, ': -test'))
    {
        echo "console_message message\n";
    }
}
User avatar
dukevin
Round Winner
Posts: 219
Joined: Mon Aug 30, 2010 8:25 am
Location: Southern California
Contact:

Re: PHP User Commands

Post by dukevin »

Try this:

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";
	}
}
}
?>
When a player says "-test" it will center message "Test"
Image
User avatar
Light
Reverse Outside Corner Grinder
Posts: 1667
Joined: Thu Oct 20, 2011 2:11 pm

Re: PHP User Commands

Post by Light »

Perfect! Thank you. :)
Post Reply