Page 3 of 4
Re: Dedicated server callbacks?
Posted: 21 May 2012, 11:38
by Leigham
Not sure if I'm understanding, but the easiest way I can see is to make a new array with all the logins but the one you want. So something like
Code: Select all
foreach ($array as $login) {
if ($login != $targetlogin) {
$newarray[] = $login;
}
}
$array = $newarray;
Apologies for the awful formatting. Typed it straight into the message box

Re: Dedicated server callbacks?
Posted: 21 May 2012, 19:15
by svens
Manually copying an array in PHP is a bad idea. It's better to just unset() the right entry.
Something like this will get the job done:
Code: Select all
if (($index = array_search($login, $array)) !== false) {
unset($array[$index]);
}
Note that after this operation there will be a "hole" in the array indexes. For example if your array is
Code: Select all
[0] => "Login A",
[1] => "Login B",
[2] => "Login C"
After you remove "Login B" from it, it will look like this:
Code: Select all
[0] => "Login A",
[2] => "Login C"
To "fix" this one could use array_values() afterwards:
Re: Dedicated server callbacks?
Posted: 21 May 2012, 20:40
by adder
works now
thanks svens & Leigham
Re: Dedicated server callbacks?
Posted: 22 May 2012, 20:07
by adder
I have yet another question
i have this code
Code: Select all
<?php
// Trackrating.plugin
// date: 20/05/12
// version 0.5
$connect->query('GetCurrentMapInfo');
$mapinfocb = $connect->getResponse();
if ($donewithfunctiontrim != TRUE) {
function trim_value(&$value) { //remove unwanted \r\n from admins.list
$value = trim($value);
}
$donewithfunctiontrim = TRUE;
}
//check if the vote file's exist
$plusvotefile="inc\Lists\gvote\\".$mapinfocb['UId'].".plus.list";
$minvotefile="inc\Lists\gvote\\".$mapinfocb['UId'].".min.list";
$votedatafile="inc\Lists\gvote\\".$mapinfocb['UId'].".vote";
if (!file_exists($plusvotefile)) {
$ourFileHandle = fopen($plusvotefile, 'w') or die("can't open file");
fclose($ourFileHandle);
}
if (!file_exists($votedatafile)) {
$ourFileHandle = fopen($votedatafile, 'w') or die("can't open file");
$stringData1 = 0;
$stringData2 = 0;
fwrite($ourFileHandle, $stringData1."\r\n".$stringData2);
fclose($ourFileHandle);
}
if (!file_exists($minvotefile)) {
$ourFileHandle = fopen($minvotefile, 'w') or die("can't open file");
fclose($ourFileHandle);
}
//plugin starts
$alreadyvoteplus = file("inc\Lists\gvote\\".$mapinfocb['UId'].".plus.list");
array_walk($alreadyvoteplus, 'trim_value'); // use function: trim_value to "clean" the file
$alreadyvotemin = file("inc\Lists\gvote\\".$mapinfocb['UId'].".min.list");
array_walk($alreadyvotemin, 'trim_value'); // use function: trim_value to "clean" the file
$filenamecurrtrack = file("inc\Lists\gvote\\".$mapinfocb['UId'].".vote");
array_walk($filenamecurrtrack, 'trim_value'); // use function: trim_value to "clean" the file
//++
if ($chatcommand[0] == "/++") {
if (!in_array($playerchat['login'], $alreadyvoteplus, true)) {
//update vote login list
$fh = fopen($plusvotefile, 'a') or die("can't open file");
$stringData = $playerchat['login'];
fwrite($fh, $stringData."\r\n");
fclose($fh);
$votesplus = $filenamecurrtrack[0];
$votesmin = $filenamecurrtrack[1];
$newvotemin = $votesmin;
//if player voted -- update vote list
if (in_array($playerchat['login'], $alreadyvotemin, true)) {
if (($index = array_search($playerchat['login'], $alreadyvotemin)) !== false) {
unset($alreadyvotemin[$index]);
$newvotemin = $newvotemin - 1;
$fp = fopen($minvotefile,'w');
foreach($alreadyvotemin as $key => $value){
fwrite($fp,$value."\r\n");
}
fclose($fp);
}
}
//update voting stats
$newvoteplus = $votesplus + 1;
$fg = fopen($votedatafile, 'w') or die("can't open file");
$stringData1 = $newvoteplus;
$stringData2 = $newvotemin;
fwrite($fg, $stringData1."\r\n".$stringData2);
fclose($fg);
$connect->query('SendNoticeToLogin','$adminlogin','$z>>$fffVote succesfull!','',0);
}
else $connect->query('SendNoticeToLogin','$adminlogin','$z>>$fffYou already voted!','',0);
}
//--
if ($chatcommand[0] == "/--") {
if (!in_array($playerchat['login'], $alreadyvotemin, true)) {
//update vote login list
$fh = fopen($minvotefile, 'a') or die("can't open file");
$stringData = $playerchat['login'];
fwrite($fh, $stringData."\r\n");
fclose($fh);
$votesplus = $filenamecurrtrack[0];
$votesmin = $filenamecurrtrack[1];
$newvoteplus = $votesplus;
//if player voted -- update vote list
if (in_array($playerchat['login'], $alreadyvoteplus, true)) {
if (($index = array_search($playerchat['login'], $alreadyvoteplus)) !== false) {
unset($alreadyvoteplus[$index]);
$newvoteplus = $newvoteplus - 1;
}
}
//update voting stats
$newvotemin = $votesmin + 1;
$fg = fopen($votedatafile, 'w') or die("can't open file");
$stringData1 = $newvoteplus;
$stringData2 = $newvotemin;
fwrite($fg, $stringData1."\r\n".$stringData2);
fclose($fg);
$connect->query('SendNoticeToLogin','$adminlogin','$z>>$fffVote succesfull!','',0);
}
else $connect->query('SendNoticeToLogin','$adminlogin','$z>>$fffYou already voted!','',0);
}
but for some reason the:
$connect->query('SendNoticeToLogin','$adminlogin','$z>>$fffVote succesfull!','',0);
doesn't work. I can't figure it out, even if i change '$adminlogin' into 'adder' (my login)
i still doesn't work.
$adminlogin is the players login
GreetZ
Re: Dedicated server callbacks?
Posted: 22 May 2012, 20:50
by TheM
May I ask you why you want to use a notice (this is an message at the left top of the screen
(please let me know if I'm wrong))?
I would suggest to use SendServerMessageToLogin

Furthermore, you'll have to use
Code: Select all
$connect->query('*****', $adminlogin, '$z>>$fffVote succesfull!', '', 0);
If you use '$adminlogin', it'll send the message to the login called $adminlogin (which isn't on your server, since $ can't be used in your login).
Re: Dedicated server callbacks?
Posted: 22 May 2012, 21:41
by adder
in some other code, I have this
Code: Select all
$connect->query('SendNoticeToLogin','$adminlogin','$z>>$fffYou banned$f00 '.$chatcommand[1].'$z$fff!','',0);
and it send a chat message, but only to a specific login.
Also the '$admindlogin' works just fine
I've got no time to try it out atm,
but I'll do it tomorrow

Re: Dedicated server callbacks?
Posted: 23 May 2012, 19:10
by adder
Code: Select all
else $connect->query('SendServerMessageToLogin',$adminlogin,'$z>>$fffYou already voted!');
this does nothing
Fixed:
Code: Select all
$connect->query('ChatSendServerMessageToLogin','$z>>$fffYou added$f00 '.$chatcommand[1].'$z$ As adminfff!',"$adminlogin");
It needs chat in front, and the login to receive at last
Re: Dedicated server callbacks?
Posted: 28 May 2012, 16:24
by adder
Hello
I want to write a array into a file like show on the picture:
picture
I have this as code (its far from finished, i does like nothing atm)
Code: Select all
<?php
/*****************************
Localrecords.plugin
version: 0.1b
date: 26/05/12
Author: adder
*****************************/
$connect->query('GetCurrentMapInfo');
$mapinfocb = $connect->getResponse();
$amountofrecs = $setting['amountofrecs'];
$count = 0;
$recordsfile="inc\Lists\localrecords\\".$mapinfocb['UId'].".record.list";
if (!file_exists($recordsfile)) {
$ourFileHandle = fopen($recordsfile, 'w') or die("can't open file");
$datatoputinform = "9999999999|login";
while ($count <= $amountofrecs) {
fwrite($ourFileHandle,$datatoputinform."\r\n");
$count++;
}
fclose($ourFileHandle);
}
if ($donewithfunctiontrim != TRUE) {
function trim_value(&$value) { //remove unwanted \r\n from admins.list
$value = trim($value);
}
$donewithfunctiontrim = TRUE;
}
//plugin start
$playerfinish['uid'] = $cb[1][0];
$playerfinish['login'] = $cb[1][1];
$playerfinish['timee'] = $cb[1][2];
$connect->query('GetPlayerInfo', $playerfinish['login']);
$playerdata = $connect->getResponse();
$playerfinish['nickname'] = $playerdata['NickName'];
$seconds = $playerfinish['timee'] / 1000;
$minutes = floor($playerfinish['timee'] / (1000 * 60));
$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++;
}
$arraybanaan = array(array("0" => $cb[1][2], "1" => $cb[1][1]));
$arraykiwi = array("0" => $cb[1][2], "1" => $cb[1][1]);
$result = array_merge($record, $arraybanaan);
sort($result);
$recordnumber = array_search($arraykiwi, $result);
$connect->query('ChatSendServerMessage', "you drove".$recordnumber);
$count = $amountofrecs;
while ($count != 0) {
implode(",", $result["$count"]);
$count = $count - 1;
}
print_r($result);
$fp = fopen($recordsfile,"w+");
foreach($result as $key => $value){
fwrite($fp,$value."\r\n");
}
fclose($fp);
?>
but this returns:
Code: Select all
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
inside my file
GrtZ
Re: Dedicated server callbacks?
Posted: 29 May 2012, 19:56
by lambda
Try to use this function:
Code: Select all
// function print array data to file
function print_to_file ($data){
ob_start();
print_r ($data);
$done = ob_get_flush ();
$txt = fopen ('print_to_file.txt', 'w');
fwrite ($txt, $done);
fclose ($txt);
}
instead:
use this:
Re: Dedicated server callbacks?
Posted: 29 May 2012, 20:02
by The_Big_Boo
lambda wrote:Code: Select all
ob_start();
print_r ($data);
$done = ob_get_flush ();
Tip: this can be done with a single call to print_r