Hey there! I have tried the following: PHP: $this->api->chat->broadcast($data." moved!"); When i debug that scene, my server crashes. What's the problem? I want to display the players name..
if it's an event, try using: $username = $data['player']->username; and then just $this->api->chat->broadcast($username." moved!");
Thank you! Do you know how i save the contents to a config file? For example: kevin: x=X y=Y z=X niki: x=X y=Y z=X I know how to get the data.
First create a config file in the init: PHP: $this->config = new Config($this->api->plugin->configPath($this)."config.yml", CONFIG_YAML, array()); Then write to the config wherever: PHP: $this->config->set($username, array("x" => $variable,"y" => $variable2,"z" => $variable3)); and then save: PHP: $this->config->save();
No problem This plugin may spam your players though if you make it broadcast something each time someone moves
I know. It was just to demonstrate you what i mean. I always try things like this to get to my final end-product which is completely different
I tried it, but it gives me this error: Code: # PocketMine-MP Error Dump Sun Nov 10 12:29:51 GMT 2013 Error: array ( 'type' => 1, 'message' => 'Cannot use object of type Entity as array', 'file' => 'C:\\Users\\Niklas_2\\Documents\\Programmierung\\PocketMine\\TestServer\\Hide and Seek\\PocketMine-MP\\src\\API\\PluginAPI.php(87) : eval()\'d code', 'line' => 115, ) The code that i have: PHP: case 'player.move': $username = $data['player']->username; $x = $data['player']->x; $y = $data['player']->y; $z = $data['player']->z; $this->config->set($username, array( "x" => $x, "y" => $y, "z" => $z, "hider" => true, "isBlock" => true )); $this->config->save();
Tried it. It no longer crashes with this code: PHP: $username = $data->username; $x = $data->x; $y = $data->y; $z = $data->z; $this->config->set($username, array( "x" => $x, "y" => $y, "z" => $z, "hider" => true, "isBlock" => true )); $this->config->save(); But the config output is this: Code: --- : x: '189.47663879395' y: 64 z: '120.70510864258' hider: true isBlock: true It doesn't show the player name... Also, how do i retrieve for example 'notch' data?
The config should look like this for example: Code: --- notch: x: '189.47663879395' y: 64 z: '120.70510864258' hider: true isBlock: true niki: x: '189.47663879395' y: 64 z: '120.70510864258' hider: true isBlock: true How do i get notch's x coordinate out of the config?
Code: if ($this->config->exists($data['username'])) { return $this->config->get($data['username'])['x']; } return false;
I was wondering something similar to this, but I didn't really get what happened up their. I am trying to swap 2 players position in my plugin (probably using config files), so how exactly would I save each of their positions to config files and then get Player1's position from the file and make it player2's position and vice versa? Thanks for any help.
You don't need a config for that. Here's a script that does it: PHP: //Getting all online players$all = $this->api->player->getAll();//Shuffle array with player objectsshuffle($all);$times = 0;$x;$y;$z;foreach($all as $player){$times++;if($times == 1){//Saving position of player 1$x = $player->x;$y = $player->y;$z = $player->z;}if($imes == 2){//Teleporting first player in $all to second playerConsoleAPI::run("tp ".$all[0]->username." ". $player->username);//Teleporting second player to set coordinates.ConsoleAPI::run("tp ".$player->username." ".$x." ".$y." ".$z);}} Hope it works. It's not tested.
Thanks for your help. Could you maybe explain how that script works. I want to learn how it works and why you used shuffle, where the second player teleport is, etc. Also, how can I make it loop after a random amount of time (run it once, wait a random time 30-120 seconds, and then run it again, over and over until 1 player dies). Thanks again!