Dedicated server callbacks?

Moderator: NADEO

User avatar
adder
Posts: 138
Joined: 06 May 2012, 17:34
Location: Belgium

Re: Dedicated server callbacks?

Post 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
        
)

    
An eye for an eye leaves the whole world monocular.
User avatar
adder
Posts: 138
Joined: 06 May 2012, 17:34
Location: Belgium

Re: Dedicated server callbacks?

Post 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);
		
An eye for an eye leaves the whole world monocular.
The_Big_Boo
Posts: 1026
Joined: 15 Jun 2010, 15:46

Re: Dedicated server callbacks?

Post 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);
;)
OS: Win 7 Pro x64
RAM: 2x4GB Corsair @ 1600MHz
CPU: Intel i5 760 @ 3.6GHz
Mobo: Asus P7P55D-E
GPU: NVidia GTX 760 2GB
HDD: WD Black 1TB
Sound: VIA VT1828S (onboard)
Peripherals: Razer DeathAdder - Razer DeathStalker - Logitech F310
farfa
Nadeo
Nadeo
Posts: 585
Joined: 14 Jun 2010, 16:15
Location: In front of your hood with one lap late

Re: Dedicated server callbacks?

Post by farfa »

GoTo is bad ;)
Image
Also known as: satanasdiabolo
User avatar
adder
Posts: 138
Joined: 06 May 2012, 17:34
Location: Belgium

Re: Dedicated server callbacks?

Post by adder »

ok, I changed it :D
thanks
An eye for an eye leaves the whole world monocular.
User avatar
adder
Posts: 138
Joined: 06 May 2012, 17:34
Location: Belgium

Re: Dedicated server callbacks?

Post 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.. :|
An eye for an eye leaves the whole world monocular.
User avatar
adder
Posts: 138
Joined: 06 May 2012, 17:34
Location: Belgium

Re: Dedicated server callbacks?

Post by adder »

I'm realizing this is getting more like a php related topic, I hope you guys don't mind?
An eye for an eye leaves the whole world monocular.
The_Big_Boo
Posts: 1026
Joined: 15 Jun 2010, 15:46

Re: Dedicated server callbacks?

Post 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]; });
OS: Win 7 Pro x64
RAM: 2x4GB Corsair @ 1600MHz
CPU: Intel i5 760 @ 3.6GHz
Mobo: Asus P7P55D-E
GPU: NVidia GTX 760 2GB
HDD: WD Black 1TB
Sound: VIA VT1828S (onboard)
Peripherals: Razer DeathAdder - Razer DeathStalker - Logitech F310
User avatar
adder
Posts: 138
Joined: 06 May 2012, 17:34
Location: Belgium

Re: Dedicated server callbacks?

Post 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;
				}
				
			}
An eye for an eye leaves the whole world monocular.
User avatar
adder
Posts: 138
Joined: 06 May 2012, 17:34
Location: Belgium

Re: Dedicated server callbacks?

Post 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); 
An eye for an eye leaves the whole world monocular.
Post Reply

Return to “Dedicated Server”

Who is online

Users browsing this forum: No registered users and 0 guests