First of all CODE: Ok, I want to make an TPA Plugin. And I want to save the ISSUER and the AIM of the /tpa plugin in an array! I do understand arrays in C# and C++ and that code would work there. But I just don't understand why in every array there is still NULL? Is there an better way to do this? On /tpa accept i would have to search through the array AIM to search if he is aimed and then search at the Same REQUEST_RQ for his SENDER to teleport! But I don't think that will work in php
When the sender runs /tpa <name> you can add their name to the array like this: PHP: $this->REQUEST_ISSUER[$sender->getName()] = $sender->getName();
But i won't be able to get the "AIM" on /tpa accept then... I need an index PHP: //D O N O T L O O K A T T H I S (That code is messy) global $REQUEST_ISSUER; global $REQUEST_AIM; global $REQUEST_ID; var_dump($REQUEST_ISSUER); //DEBUG var_dump($REQUEST_AIM); //DEBUG var_dump($REQUEST_ID); //DEBUG $REQUEST_ISSUER[$REQUEST_ID] = $sender->getName(); $REQUEST_AIM[$REQUEST_ID] = $args[0]; $REQUEST_ID++; var_dump($REQUEST_ISSUER); //DEBUG var_dump($REQUEST_AIM); //DEBUG var_dump($REQUEST_ID); //DEBUG //N O W Y O U C A N L O O K A G A I N return true; Will try that...
When players join you need to add them to an array. When someone runs /tpa <playername> you have to set the players name to the object of the requester. Then when the player runs /tpaccept you can simply tp their value in the array to them. for example: PHP: class YourClass { public $players= []; //onJoin $this->players[$player->getName()] = null; //onCommand: tpa $target = $sever->getPlayer($args[1]); $this->players->[$target->getName()] = $sender->getName(); //onCommand: tpaccept $requester = $this->players[$sender->getName()]; if($requester !== null) { $requester->teleport($playerPos); }}
Ok that helps a lot But i need some time And one question: WHY ARE GLOBALS SAVED WITHIN AN RESTART AND WHERE? My globals where still there after an restart (there was still old data in them)
But on Server RESTART the process is being killed, RAM is freed up... But nevermind tomorrow i will try to finish that array thingy
No, they are not saved after server restart (not /reload). Just don't use them, ok? Only very few parts of PocketMine uses globals, and it's when using globals is necessary, which you aren't facing this case now. I don't know what you are trying to do, but I think you swapped $args[0] and $REQUEST_AIM[...]? Also, what is $REQUEST_RQ?
It appears that he simply doesn't know how to use them. But anyway, this kind of plugins that use globals needlessly would not get approved in the plugin repo. You simply need to delete the global $blah lines, and them change all occurrences of $globalVariable to $this->globalVariable, that works. But to make it more memory efficient, declare the properties by adding a line at the beginning of a class: private $globalVariable.
Thanks for the explanations REQUEST_RQ (now it is renamed to REQUEST_ID) is the number of the request. I will soon try to use $this->Bla! And @Hotshot_9930 I will listen, I am new to php and come from C# where much is different (as example you don't even need to define globals, every variable is ^global^)
PHP is more like C++ except that it is not typestrict and that all variables are automatically dereferenced when they are used (you can make a variable point to another variable's address, but you don't need to * it)
Try removing the $ sign for the class variables. So it's var_dump($this->REQUEST_ID) instead of var_dump($this->$REQUEST_ID).