Mcfarlin Posted December 25, 2015 Posted December 25, 2015 Probably a lot is the answer there i think. Okay i have installed a humans vs zombies mod from the forum, did not work, thanks to NonStopCoding it is now working. we were talking about adding to the mod and having it stop on its own when there was only one human left. We did not get that to work. I have been playing around with this idea today and here is what i have. But im not getting very far with it. I am sure i am going about this all wrong. Could anyone point me in the right direction or point out what i am doing wrong please. I have noted to indicate what i was trying to do at each step. I have tested the queries by themselves and they are all working fine. But together in the game is another story. //check to see how many humans are left $humansalive=$db->query("SELECT COUNT(`userid`) AS humansalive FROM `users` WHERE `humanorzombie` = 0"); //if there is only one left then find find out and set who the winners are if ($humansalive == 1){ //set the last user as a human as the last man alive $db->query("UDATE `users` SET `lma` = 1 WHERE `humanorzombie` = 0"); // pick out the player with the most kills as a zombie $z1=$db->fetch_row($db->query("SELECT `userid`,`username`,`zombiekills` FROM `users` WHERE `zombiekills` > 0 AND `humanorzombie` = 1 ORDER BY `zombiekills` DESC Limit 1")); //set the user who killed the most humans as a zombie $db->query("UDATE `users` SET `mostzkills` = 1 WHERE `userid` = {$z1}"); //define who they are $lma=$db->query("SELECT `userid` FROM `users` WHERE `lma` = 1"); $mzk=$db->query("SELECT `userid` FROM `users` WHERE `mostzkills` = 1"); //start giving out prizes and telling them they have won the event $db->query("UPDATE `users` SET `money` = `money` = 10000, `exp` = `exp` + 10000, `crystals` = `crystals` + 5000 WHERE `lma` = 1"); event_add($lma,"You were the last human alive. You have won $10,000 in cash, 10,000 Experience and 5,000 Gold Coins."); $db->query("UPDATE `users` SET `money` = `money` = 10000, `exp` = `exp` + 10000, `crystals` = `crystals` + 5000 WHERE `mostzkills` = 1"); event_add($mzk,"You killed the most humans. You have won $10,000 in cash, 10,000 Experience and 5,000 Gold Coins."); //tell everyone $db->query("INSERT INTO `announcements` VALUES('The Zombie invasion has ended. The last man alive was {$lma[`username`]}. As the last man alive {$lma[`username`]} recieved $10000, 10000 EXP and 5000 Gold Coins. The top Zombies was {$z1[`username`]}. {$z1[`username`]} has been awarded $7500, 7500 EXP and 3500 Gold Coins for gettign the most kills as a zombie. {$z2[`username`]} in First place. {$z2[`username`]} has been awarded $5000, 5000 EXP and 2000 Gold Coins.')"); $db->query("UPDATE `users` SET `new_announcements` = `new_announcements` + 1"); //reset event back to zero $db->query("UPDATE `hvzstats` SET `hvz`= 0, `totzombies` = 0"); $db->query("UPDATE `users` SET `humanorzombie` = 0 , `zombiekills` = 0"); } Quote
jcvenom Posted December 26, 2015 Posted December 26, 2015 Probably a lot is the answer there i think. Okay i have installed a humans vs zombies mod from the forum, did not work, thanks to NonStopCoding it is now working. we were talking about adding to the mod and having it stop on its own when there was only one human left. We did not get that to work. I have been playing around with this idea today and here is what i have. But im not getting very far with it. I am sure i am going about this all wrong. Could anyone point me in the right direction or point out what i am doing wrong please. I have noted to indicate what i was trying to do at each step. I have tested the queries by themselves and they are all working fine. But together in the game is another story. //check to see how many humans are left $humansalive=$db->query("SELECT COUNT(`userid`) AS humansalive FROM `users` WHERE `humanorzombie` = 0"); //if there is only one left then find find out and set who the winners are if ($humansalive == 1){ //set the last user as a human as the last man alive $db->query("UDATE `users` SET `lma` = 1 WHERE `humanorzombie` = 0"); // pick out the player with the most kills as a zombie $z1=$db->fetch_row($db->query("SELECT `userid`,`username`,`zombiekills` FROM `users` WHERE `zombiekills` > 0 AND `humanorzombie` = 1 ORDER BY `zombiekills` DESC Limit 1")); //set the user who killed the most humans as a zombie $db->query("UDATE `users` SET `mostzkills` = 1 WHERE `userid` = {$z1}"); //define who they are $lma=$db->query("SELECT `userid` FROM `users` WHERE `lma` = 1"); $mzk=$db->query("SELECT `userid` FROM `users` WHERE `mostzkills` = 1"); //start giving out prizes and telling them they have won the event $db->query("UPDATE `users` SET `money` = `money` = 10000, `exp` = `exp` + 10000, `crystals` = `crystals` + 5000 WHERE `lma` = 1"); event_add($lma,"You were the last human alive. You have won $10,000 in cash, 10,000 Experience and 5,000 Gold Coins."); $db->query("UPDATE `users` SET `money` = `money` = 10000, `exp` = `exp` + 10000, `crystals` = `crystals` + 5000 WHERE `mostzkills` = 1"); event_add($mzk,"You killed the most humans. You have won $10,000 in cash, 10,000 Experience and 5,000 Gold Coins."); //tell everyone $db->query("INSERT INTO `announcements` VALUES('The Zombie invasion has ended. The last man alive was {$lma[`username`]}. As the last man alive {$lma[`username`]} recieved $10000, 10000 EXP and 5000 Gold Coins. The top Zombies was {$z1[`username`]}. {$z1[`username`]} has been awarded $7500, 7500 EXP and 3500 Gold Coins for gettign the most kills as a zombie. {$z2[`username`]} in First place. {$z2[`username`]} has been awarded $5000, 5000 EXP and 2000 Gold Coins.')"); $db->query("UPDATE `users` SET `new_announcements` = `new_announcements` + 1"); //reset event back to zero $db->query("UPDATE `hvzstats` SET `hvz`= 0, `totzombies` = 0"); $db->query("UPDATE `users` SET `humanorzombie` = 0 , `zombiekills` = 0"); } There's actually quite a few errors I see like $z1=$db->fetch_row($db->query("SELECT `userid`,`username`,`zombiekills` FROM `users` WHERE `zombiekills` > 0 AND `humanorzombie` = 1 ORDER BY `zombiekills` DESC Limit 1")); //set the user who killed the most humans as a zombie $db->query("UDATE `users` SET `mostzkills` = 1 WHERE `userid` = {$z1}"); This line $db->query("UDATE `users` SET `mostzkills` = 1 WHERE `userid` = {$z1}"); Should actually be $db->query("UDATE `users` SET `mostzkills` = 1 WHERE `userid` = {$z1['userid']}"); I'll have a look at this for you and post a fix based on what I have here :) Quote
jcvenom Posted December 26, 2015 Posted December 26, 2015 Correct my work if needed, I corrected what I could understand from the code above so i'm not 100% sure how it's meant to work btw it's untested //check to see how many humans are left $humans_alive_query = $db->query("SELECT COUNT(`userid`) AS `humansalive` FROM `users` WHERE `humanorzombie` = 0"); $haq = $db->fetch_row($humans_alive_query); $humansalive = (int) $haq['humansalive']; //Human //if there is only one human then select the user and credit them with there awards if ($humansalive == 1) { //Fetch the Last user that is a human (Winner in this case) $last_man = $db->fetch_row($db->query("SELECT `userid`,`username` FROM `users` WHERE `humanorzombie` = '0' ORDER BY `userid` DESC LIMIT 1")); //Set the last user as a human as the last man alive $db->query("UPDATE `users` SET `lma` = 1 WHERE `humanorzombie` = 0 AND `userid` = '{$last_man['userid']}'"); //Zombie //Select the user with the most kills as a Zombie $z1 = $db->fetch_row($db->query("SELECT `userid`,`username`,`zombiekills` FROM `users` WHERE `zombiekills` > 0 AND `humanorzombie` = 1 ORDER BY `zombiekills` DESC Limit 1")); //set the user who killed the most humans as a zombie //No need to set the user as a zombie, because we've already selected the user who is a zombie with the most kills //$db->query("UPDATE `users` SET `humanorzombie` = 1 WHERE `userid` = {$z1['userid']}"); //Last man alive winner(Human) $last_man_alive_winner = $db->query("SELECT `userid` FROM `users` WHERE `lma` = 1 AND `humanorzombie` = '0' ORDER BY `userid` DESC LIMIT 1"); /*Jcvenom(Really don't understand what your trying to do here) *More info needed about the zombie kills as a human */ //Most zombie kills as a human winner $most_zombie_kills_winner = $db->query("SELECT `userid` FROM `users` WHERE `humanorzombie` = '0' ORDER BY `zombiekills` DESC LIMIT 1"); $mzkw = $db->fetch_row($most_zombie_kills_winner); //Most human kills as a zombie winner $most_human_kills_winner = $db->query("SELECT `userid` FROM `users` WHERE `humanorzombie` = '1' ORDER BY `mostzkills` DESC LIMIT 1"); $mhkw = $db->fetch_row($most_human_kills_winner); //Credit users with prizes based on above and send event and announcement //Last man alive $db->query("UPDATE `users` SET `money` = `money` + 10000, `exp` = `exp` + 10000, `crystals` = `crystals` + 5000 WHERE `lma` = 1 AND `humanorzombie` = '0' AND `userid` = '{$mzkw['userid']}'"); event_add($mzkw['userid'],"You were the last human alive. You have won $10,000 in cash, 10,000 Experience and 5,000 Gold Coins."); //Most human kills(Zombie in this case) $db->query("UPDATE `users` SET `money` = `money` + 10000, `exp` = `exp` + 10000, `crystals` = `crystals` + 5000 WHERE `userid` = '{$mhkw['userid']}'"); event_add($mhkw['userid'],"You killed the most humans. You have won $10,000 in cash, 10,000 Experience and 5,000 Gold Coins."); //Announcement $db->query("INSERT INTO `announcements` VALUES('The Zombie invasion has ended. The last man alive was {$last_man[`username`]}. As the last man alive {$last_man[`username`]} recieved $10000, 10000 EXP and 5000 Gold Coins. The top Zombies was {$z1[`username`]}. {$z1[`username`]} has been awarded $7500, 7500 EXP and 3500 Gold Coins for getting the most kills as a zombie. {$z1[`username`]} in First place. {$z1[`username`]} has been awarded $5000, 5000 EXP and 2000 Gold Coins.')"); $db->query("UPDATE `users` SET `new_announcements` = `new_announcements` + 1"); //reset event back to zero $db->query("UPDATE `hvzstats` SET `hvz`= 0, `totzombies` = 0"); $db->query("UPDATE `users` SET `humanorzombie` = 0 , `zombiekills` = 0"); } else { //More than one human left therefore the above code won't run } I'll make any corrections if you want :) Quote
Mcfarlin Posted December 26, 2015 Author Posted December 26, 2015 Thank you jcvenom. while you were doing that i got it to work by using the following thanks to you pointing out a silly error. I also had UDATE in place of UPDATE. in two places. tisk tisk. The announcement INSERT was wrong as well. But either way its all working now except for getting the usernames of the winners in the announcement. $humansalive=$db->query("SELECT COUNT(`userid`) AS humansalive FROM `users` WHERE `humanorzombie` = 0"); if ($humansalive = 1) { $db->query("UPDATE `users` SET `lma` = 1 WHERE `humanorzombie` = 0"); $z1=$db->fetch_row($db->query("SELECT `userid`,`username`,`zombiekills` FROM `users` WHERE `zombiekills` > 0 AND `humanorzombie` = 1 ORDER BY `zombiekills` DESC Limit 1")); $db->query("UPDATE `users` SET `mostzkills` = 1 WHERE `userid` = {$z1['userid']}"); $lma=$db->query("SELECT `userid` FROM `users` WHERE `lma` = 1"); $mzk=$db->query("SELECT `userid` FROM `users` WHERE `mostzkills` = 1"); $db->query("UPDATE `users` SET `money` = `money` = 10000, `exp` = `exp` + 10000, `crystals` = `crystals` + 5000 WHERE `lma` = 1"); $db->query("UPDATE `users` SET `money` = `money` = 10000, `exp` = `exp` + 10000, `crystals` = `crystals` + 5000 WHERE `mostzkills` = 1"); $db->query("INSERT INTO `announcements` (`a_text`, `a_time`) VALUES ('The Zombie invasion has ended The last man alive and the Zombie with the most kills have won 10000 in cash 10000 EXP and 5000 Gold Coins', '0')"); $db->query("UPDATE `users` SET `new_announcements` = `new_announcements` + 1"); $db->query("UPDATE `hvzstats` SET `hvz`= 0, `totzombies` = 0"); $db->query("UPDATE `users` SET `humanorzombie` = 0 , `zombiekills` = 0"); } Now all i have to do keep bots and staff from being counted in it. That is easy when event is started. again thx 1 Quote
jcvenom Posted December 26, 2015 Posted December 26, 2015 Thank you jcvenom. while you were doing that i got it to work by using the following thanks to you pointing out a silly error. I also had UDATE in place of UPDATE. in two places. tisk tisk. The announcement INSERT was wrong as well. But either way its all working now except for getting the usernames of the winners in the announcement. $humansalive=$db->query("SELECT COUNT(`userid`) AS humansalive FROM `users` WHERE `humanorzombie` = 0"); if ($humansalive = 1) { $db->query("UPDATE `users` SET `lma` = 1 WHERE `humanorzombie` = 0"); $z1=$db->fetch_row($db->query("SELECT `userid`,`username`,`zombiekills` FROM `users` WHERE `zombiekills` > 0 AND `humanorzombie` = 1 ORDER BY `zombiekills` DESC Limit 1")); $db->query("UPDATE `users` SET `mostzkills` = 1 WHERE `userid` = {$z1['userid']}"); $lma=$db->query("SELECT `userid` FROM `users` WHERE `lma` = 1"); $mzk=$db->query("SELECT `userid` FROM `users` WHERE `mostzkills` = 1"); $db->query("UPDATE `users` SET `money` = `money` = 10000, `exp` = `exp` + 10000, `crystals` = `crystals` + 5000 WHERE `lma` = 1"); $db->query("UPDATE `users` SET `money` = `money` = 10000, `exp` = `exp` + 10000, `crystals` = `crystals` + 5000 WHERE `mostzkills` = 1"); $db->query("INSERT INTO `announcements` (`a_text`, `a_time`) VALUES ('The Zombie invasion has ended The last man alive and the Zombie with the most kills have won 10000 in cash 10000 EXP and 5000 Gold Coins', '0')"); $db->query("UPDATE `users` SET `new_announcements` = `new_announcements` + 1"); $db->query("UPDATE `hvzstats` SET `hvz`= 0, `totzombies` = 0"); $db->query("UPDATE `users` SET `humanorzombie` = 0 , `zombiekills` = 0"); } Now all i have to do keep bots and staff from being counted in it. That is easy when event is started. again thx No problem i'm glad I could help. Also you might want to change this $db->query("UPDATE `users` SET `money` = `money` = 10000, `exp` = `exp` + 10000, `crystals` = `crystals` + 5000 WHERE `lma` = 1"); $db->query("UPDATE `users` SET `money` = `money` = 10000, `exp` = `exp` + 10000, `crystals` = `crystals` + 5000 WHERE `mostzkills` = 1"); to this Explanation: you were making the users money = $10,000 rather than adding $10,000 just apply the code below to your current as you say fixed version and your done :) anymore issues feel free to post $db->query("UPDATE `users` SET `money` = `money` + 10000, `exp` = `exp` + 10000, `crystals` = `crystals` + 5000 WHERE `lma` = 1"); $db->query("UPDATE `users` SET `money` = `money` + 10000, `exp` = `exp` + 10000, `crystals` = `crystals` + 5000 WHERE `mostzkills` = 1") Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.