Loading script problem.

Post here if you need help setting up your server, etc.
Moofie
Core Dumper
Posts: 125
Joined: Fri Jan 27, 2012 1:36 am
Location: Ohio
Contact:

Re: Loading script problem.

Post by Moofie »

Alright, i'll check that out. One thing, I made a simple script, and by simple I mean like total beginner script, only made it during a few tutorials I read.

Code: Select all

#!/usr/bin/php
<?php
$sui = DEATH_SUICIDE
IF ($sui = DEATH_SUICIDE){
"SPAWN_ZONE death 10 10 4 1 5 5 true 15 15 2 3"
}
php?>


How's it look? I have no experience in php, but i'm trying to learn it.
User avatar
AI-team
Shutout Match Winner
Posts: 1020
Joined: Tue Jun 23, 2009 6:17 pm
Location: Germany/Munich
Contact:

Re: Loading script problem.

Post by AI-team »

not sure what you tried to do, but you're not gonna accomplish it :P
you've done basically every wrong what you could have done wrong :D

here's what I guess you wanted to do, written in proper PHP

Code: Select all

#!usr/bin/php
<?php
while (true)
{
    //read the input
    $line = rtrim(fgets(STDIN, 1024));
    
    //check if line starts with DEATH_SUICIDE
    if(preg_match("/^DEATH_SUICIDE/",$line)) {
        //it does, so spawn a zone
        echo "SPAWN_ZONE death 10 10 4 1 5 5 true 15 15 2 3\n";  // don't forget the \n at the end of every line!
        
    }
    
    //sleep one second and continue reading
    sleep(1000);
}
?>
  
 
"95% of people believe in every quote you post on the internet" ~ Abraham Lincoln
 
 
Moofie
Core Dumper
Posts: 125
Joined: Fri Jan 27, 2012 1:36 am
Location: Ohio
Contact:

Re: Loading script problem.

Post by Moofie »

Oh.. lol oops. I just figured i'd have it spawn a death zone if you commit suicide, its the only thing I could think of to test lol. Hm, guess I got some more learning to do :P
User avatar
dlh
Formerly That OS X Guy
Posts: 2035
Joined: Fri Jan 02, 2004 12:05 am
Contact:

Re: Loading script problem.

Post by dlh »

AI-team wrote:here's what I guess you wanted to do, written in proper PHP […]
A few issues with your code: (1) fgets is a blocking call, so the sleep at the end of the loop is unnecessary. (2) You aren't checking for EOF (the script will never terminate if killed by KILL_SCRIPT). (3) Not really an issue, but the length parameter for fgets is optional. Here's a corrected version:

Code: Select all

#!usr/bin/php
<?php

while (true)
{
    //read the input
    $line = rtrim(fgets(STDIN));

    if (feof(STDIN))
        break;
    
    //check if line starts with DEATH_SUICIDE
    if(preg_match("/^DEATH_SUICIDE/",$line)) {
        //it does, so spawn a zone
        echo "SPAWN_ZONE death 10 10 4 1 5 5 true 15 15 2 3\n";  // don't forget the \n at the end of every line!
        
    }
}
?>
User avatar
AI-team
Shutout Match Winner
Posts: 1020
Joined: Tue Jun 23, 2009 6:17 pm
Location: Germany/Munich
Contact:

Re: Loading script problem.

Post by AI-team »

well I copycated this from the ct wiki so I thought it would be ok :P
  
 
"95% of people believe in every quote you post on the internet" ~ Abraham Lincoln
 
 
User avatar
dukevin
Round Winner
Posts: 219
Joined: Mon Aug 30, 2010 8:25 am
Location: Southern California
Contact:

Re: Loading script problem.

Post by dukevin »

Never understood why it was necessary to sleep at the end.
Image
Moofie
Core Dumper
Posts: 125
Joined: Fri Jan 27, 2012 1:36 am
Location: Ohio
Contact:

Re: Loading script problem.

Post by Moofie »

lol you guys don't need to put an effort into correcting, it was just my noob learning test script :P
Post Reply