Page 4 of 4

Re: Dedicated server callbacks?

Posted: 29 May 2012, 21:11
by adder
thank you very much !

but I still have a problem

the file looks like this:

Code: Select all

Array
(
  
  
[0] => Array
        
(
            
[0] => 25510
            
[1] => adder
        
)


    
[1] => Array
        
(
            
[0] => 9999999999
            
[1] => login
        
)

 
   
[2] => Array
        
(
            
[0] => 9999999999
            
[1] => login
        
)

    

Re: Dedicated server callbacks?

Posted: 30 May 2012, 14:50
by adder
works now :D

Code: Select all

$array = $result;

		//thanks to Lambda & The_Big_Boo (Nadeo) for this!
		$ccc = 0;
		$txt = fopen($recordsfile, 'w+'); 
		foreach($array as $key => $value){
			foreach($value as $key => $value2){
				if ($ccc === 0) {
				fwrite($txt,$value2."|");
				$ccc = 1;
				goto nextkey;
				}
				if ($ccc === 1) {
				fwrite($txt,$value2."\r\n");
				$ccc = 0;
				goto nextkey;
				}
				nextkey:
			}
		} 
		fclose($txt);
		

Re: Dedicated server callbacks?

Posted: 30 May 2012, 15:03
by The_Big_Boo
Using goto is a bad programming practice. Anyway your code can be heavily simplified so it doesn't even use an "if".

Code: Select all

$array = $result;
$txt = fopen($recordsfile, 'w+'); 
foreach($array as $value)
	fprintf($txt, "%s|%s\n", $value[0], $value[1]);
fclose($txt);
;)

Re: Dedicated server callbacks?

Posted: 30 May 2012, 15:09
by farfa
GoTo is bad ;)
Image

Re: Dedicated server callbacks?

Posted: 30 May 2012, 17:34
by adder
ok, I changed it :D
thanks

Re: Dedicated server callbacks?

Posted: 03 Jun 2012, 20:01
by adder
After I made some changes on my records system,
I'm having some problems, this is the code:

Code: Select all

while ($count != 0) {
			if ($playerfinish['login'] == $record["$count"][1]) {
				if ($playerfinish['timee'] < $record["$count"][0]) {
					$record["$count"][0] = $playerfinish['timee'];
					$result = $record;
				}
			}
			$count-- ;
			if ($count === 0) {
				$arraybanaan = array(array("0" => $cb[1][2], "1" => $cb[1][1]));
				$result = array_merge($record, $arraybanaan);
				break;
			}
		}
		print_r($result);
		$arraykiwi = array("0" => $cb[1][2], "1" => $cb[1][1]);
		sort($result);
		$recordnumber = array_search($arraykiwi, $result);
		$recordnumber++;
print_r returns an array (just to make sure, it'll be remove once this stuff works again)
but sort($result) returns a warning that $result is not an array
array_search($result) works fine and returns the correct key
I'm not getting the problem. On some line's $result is an array, on others it isn't.. :|

Re: Dedicated server callbacks?

Posted: 03 Jun 2012, 21:30
by adder
I'm realizing this is getting more like a php related topic, I hope you guys don't mind?

Re: Dedicated server callbacks?

Posted: 03 Jun 2012, 21:54
by The_Big_Boo
I guess the warning raised by sort() is the fact that PHP doesn't know how to compare arrays. Indeed, it's not just an array but an array of arrays you're giving to sort.

I'm also guessing you want to sort your array using player times, so instead of just sort($result) you may want to do this:

Code: Select all

usort($result, function ($p1, $p2) { return $p1[0] - $p2[0]; });

Re: Dedicated server callbacks?

Posted: 04 Jun 2012, 20:13
by adder
thx, but still doesn't work :(

it has to do something with these lines:

Code: Select all

if ($playerfinish['login'] == $record["$count"][1]) {
				if ($playerfinish['timee'] < $record["$count"][0]) {
					$record["$count"][0] = $playerfinish['timee'];
					$result = $record;
				}
				
			}

Re: Dedicated server callbacks?

Posted: 06 Jun 2012, 13:10
by adder
Works now! :yes:

Code: Select all

$currentrecords = file("inc\Lists\localrecords\\".$mapinfocb['UId'].".record.list");
		array_walk($currentrecords, 'trim_value'); // use function: trim_value to "clean" the file

		$count = 0;
		while ($count <= $amountofrecs) {
			$record["$count"] = explode("|", $currentrecords["$count"]);
			$count++;
		}
		while ($count >= 0) {
			if ($playerfinish['login'] == $record["$count"][1]) {
				if ($playerfinish['timee'] < $record["$count"][0]) {
					$record["$count"][0] = $playerfinish['timee'];
					$result = $record;
					break;
				}
				else goto end;
			}
			if ($count === 0) {
				$arraymerge = array(array("0" => $cb[1][2], "1" => $cb[1][1]));
				$result = array_merge($record, $arraymerge);
				
			}
			$count--;
		}
		print_r($result);
		$arraycheck = array("0" => $cb[1][2], "1" => $cb[1][1]);
		sort($result);
		$recordnumber = array_search($arraycheck, $result);
		$recordnumber++;
		$connect->query('ChatSendServerMessage', '$z>>$f00'.$playerdata['NickName'].'$fff Drove record $f00'.$recordnumber.'$fff ($f00'.$time.'$fff)');
		$count = $amountofrecs;
		//thanks to Lambda & The_Big_Boo (Nadeo) & Farfa (Nadeo) for this!
		$txt = fopen($recordsfile, 'w+'); 
		foreach($result as $value) {
			fprintf($txt, "%s|%s\n", $value[0], $value[1]);
		}
		fclose($txt);