I was working on a card game for just because i was bored and thought this might actually be interesting for a plugin So heres a little snippet of the code(in web development form) Could this work in a plugin as is? With the exception of changing echo to sendMessage Spoiler: Code PHP: <?phpclass cardGame{public $deck;public $faces;public $suits;public function cards(){ $suits = array( "spades","hearts","clovers","diamonds" ); $faces = array( "ace","one","two","three","four","five","six", "seven","eight","nine","ten","jack","queen", "king" );}public function Deck(){ $deck = array(); foreach($suits as $suit){ foreach($faces as $face){ $deck[] = array("face"=>$face, "suit"=>$suit); } }}public function Shuffle(){ shuffle($deck);}public function Draw(){ $draw = array_shift($deck); echo $draw['face'] . "of" . $draw['suit'];}} EDIT: So i went ahead and coded up what i believe would be the interpetation of this into OOP but in a lottery type of game instead of cards (bc obviously i cant have physical carda in mcpe) PHP: <?phpnamespace FlamingGenius\Lottery;use pocketmine\plugin\PluginBase;use pocketmine\utils\Config;use pocketmine\command\Command;use pocketmine\command\CommandSender;class Lottery extends PluginBase{public function onEnable(){ $this->saveDefaultConfig();}public function onCommand(CommandSender $sender, Command $command, $label, array $args){ $cmd = $this->command->getName(); $winT = $this->getConfig()->get("winning-number"); if(strtolower($cmd) == "lottery"){ $numbers = array( "4062","2332","1127","1975", "8458","9883","4762","3038", "8459","7111","3858","8814", ); $draw = array_rand($numbers); $ticket = $numbers[$draw]; $sender->sendMessage("Your ticket number is" . " " . $ticket); if($ticket == $winT){ $player = $this->getServer()->getPlayer()->getName(); $this->getServer()->broadcastMessage($player . " " . "Got a winning lottery ticket"); } else{ $sender->sendMessage("Sorry your ticket is not a winning number"); } }}}?>
First time i read this i thought you were telling me to learn php XD i was abt to say excuse me i know PHP XD
Hardcode winning numbers? Bad bad bad idea. This is as bad as this: Why not this? PHP: $winNumber = str_pad(mt_rand(0, 9999), 4, "0", STR_PAD_LEFT);
Let's simulate what will happen here. PHP: $numbers = array( "4062","2332","1127","1975", "8458","9883","4762","3038", "8459","7111","3858","8814", ); $draw = array_shift($numbers); $ticket = $numbers[$draw]; The second statement takes the first number from the array. so $draw is "4062" The third statement takes the #$draw (#4062) element from $numbers, which does not exist. End of story. Moreover, starting from the 3rd element ($numbers[2]) onwards, they aren't used at all. Remember that it is a local variable, and it gets redefined every time the function runs. Learn PHP.
I realized this after i ran my code and changed it to this PHP: $draw = array_rand($numbers);$ticket = $numbers[$draw]; And i removed the foreach... Part because it was unused coding but i appreciate ur thoughtful help
Your ignorance is quite baffling considering you have created so many plugins and seem to be well edcuated so this is what i want you to do for me since this is im guessing by your standards "wrong" heres the snippet in question i added echo $ticket; to the script i want you to run this code 5 times and then i want you to paste the results on here okay PHP: <?php$numbers = array( "4062","2332","1127","1975", "8458","9883","4762","3038", "8459","7111","3858","8814", ); $draw = array_rand($numbers); $ticket = $numbers[$draw]; echo $ticket; ?>
Armageddon... You will get the joke when he comes back on... Hehehe... Lol, this ain't the first time someones done something like this...
Ahhh so i see...well its obvious what is happenin in the code his comments were very ignorant(trying to be polite) because he did not use common sense Also he was online when i said this earlier and he said nothing back #win And i still not getting flame wars?