Take a log when you chat Plugin I want work. But get an error... Code: 0:23:34] critical > Could not pass event 'pocketmine\event\player\PlayerChatEvent' to 'ChatLog v1': Call to a member function set() on null on CONSOLE\ChatLog\Main [00:23:34] critical > Error: "Call to a member function set() on null" (EXCEPTION) in "/plugins/ChatLog/src/CONSOLE/ChatLog/Main" at line 27 PHP: public function onChat(PlayerChatEvent $event){$p = $event->getPlayer();$ms = $event->getMessage();$user = $p->getName();$this->cl->set('$user', '$ms');} I don't know how to write config. Could you tell me?...
If you want to do it with a config u need to save it. PHP: public function onChat(PlayerChatEvent $event){$p = $event->getPlayer();$ms = $event->getMessage();$user = $p->getName();$conf = new Config($this->getDataFolder() . "config.yml", Config::YAML);$conf->set($user, $ms);$conf->save();} * And your error: Pls show us your public $cl And u have a server.log file on your server
No, way too laggy to call config in player chat event. Use global variables. Also... There is a difference between (') and (") in PHP. PHP: $number = 1020;$var = 'The number is $number.';//OUTPUT: The number is $number.$var = "The number is $number."//OUTPUT: The number is 1020. Assuming you are a beginner, stick with double quotes for now. For the chat logging... PHP: public $logs = [];public function onChat(PlayerChatEvent $event) { $player = $event->getPlayer()->getName(); $message = $event->getMessage(); $this->logs[$player] = $message;}public function onDisable() { $conf = new Config($this->getDataFolder() . "config.yml", Config::YAML); foreach ($this->logs as $player => $message) { $conf->set($player, $message); } $conf->save();}
Yea, I would recommend appending this to a log file PHP: #opening$handle = fopen("PATH/TO/FILE.log", 'a');if(!is_resource($handle)){ echo("Error: cannot open/create file! Does this process have proper perms?");}#writingif(fwrite($handle, $msg) === false){ echo("Failed to write \"".$msg."\" to file :(");}#closingif(fclose($handle) !== true){ echo("Huh?");}