Page 1 of 1

Disabling Characters After Winning

Posted: Thu Nov 06, 2014 9:19 pm
by Epiales
Okay, I'm a bit further now, but running into a problem. Here is what I currently have using js to open the popup and then php to display the content. Once I set up the battle mechanics, I don't have any clue how to disable the characters after someone beats them. I can't remove them from the database when they do, because everyone will be hitting them. Any good place to start? Thanks!!

Current:

Image

So when they attack no 1 Anthony, and win, it needs to be disabled so they cannot be hit again by the same person. Then when they beat number 1, number 2 becomes available to attack, and when they beat number 2, 3 becomes available and so on.

Re: Disabling Characters After Winning

Posted: Fri Nov 07, 2014 12:40 am
by Sim
Start with a new table?

Re: Disabling Characters After Winning

Posted: Fri Nov 07, 2014 1:49 am
by Epiales
Sim wrote:Start with a new table?
Not sure! I can only think of adding a row to the database for when the user beats that particular NPC, and when they do, make it 1 or yes. And then define the select statement accordingly. Only problem with that is that it would only show CERTAIN rows while I want it to show them ALL, being that all players have to defeat the NPC, not just one player. I'll sleep a bit and think further later :) Thx!

Re: Disabling Characters After Winning

Posted: Fri Nov 07, 2014 4:35 am
by Callan S.
How many people can be in the arena? If all players have to beat him before they go off the list, that's a lot of players!

For every player that is in the arena, you'd need a record for every other player. That'd be a lot of records!

Do they have to be able to choose who they can fight? If not then each player could just have a value for who they fight in the arena that goes up - ie, they fight player #1 in the arena, then player #2, then player #3, etc. They can't fight anyone lower on the list than this number.

Re: Disabling Characters After Winning

Posted: Fri Nov 07, 2014 4:46 am
by KyleMassacre
I will have to agree with sim on this one here. Create a new table like attacks_won or something like that to suit your needs Then you can have some columns like attacker_id, attacked_id, and time Then you would want to query your table and check to see if a row exists and if it does don't let them attack and if it doesn't then you can let them attack. For the time column you can use that to help filter/delete entries along the way

Also may I add a suggestion too? I will anyway ;). I wouldn't show the NPC stats to players otherwise they will know if they can beat them and that takes the fun out of it. I don't know if you have some sort of leveling system or not but if you do then you can maybe set their stats at what a reasonable stat would be for a level and just show the players their level.

Re: Disabling Characters After Winning

Posted: Fri Nov 07, 2014 9:54 am
by Epiales
Okay, so I'm looking at creating a new table in the database for storing if each NPC has been defeated or not by each player.... What's the best way to do that? In my mind I see two ways to do it, but seems like it will store way too much info.... Maybe there's a third way? Here's what I"m thinking anyway.

1. When user joins, have the signup put their ID/NAME in an arena log and then put every NPC ID/NAME into that row by each user id. When they attack the NPC and defeat them, then it will put it at a 1, as default would be 0. 1 would be they beat them. Then I would write TWO tables for displaying the information, with an IF statement. One would be ordered by ID only for new players and one would be ordered by the DEFEATED, ID ASC..... By doing it this way it would push the defeated ones down to the bottom and leave the new ones up top to be defeated, and allow me to remove the row for "attack" on that display so that they wouldn't be able to attack again.

2. Have an arena log with a userid, arenaid, defeated(0,1)... but this would require that every player would have a list of ALL arena fights put into that arena log when they lose and when they defeat for EACH attack (could be minimized by an if statement not allowing it to put into db if they lose), but let's say 20 rows to display 20 wins...that's a lot of rows in the table for every single player....

Is there another option to help tidy it up a little? I'm thinking I go with the first option....

*****EDITED*****

P.S.... It's still showing row lines and I have put the border to 0, so why?

P.S.2.... Also, I was thinking of making their atk/def a random between what it displayed on the stats, so while one may know their stats, it doesn't necessarily mean they can win until they are much stronger.

P.S.3.... After working on fix one, I'm not sure it will work....grrrr

Re: Disabling Characters After Winning

Posted: Fri Nov 07, 2014 12:05 pm
by KyleMassacre
Ok this man sound a bit ghetto but it is the easiest way I can think of off the top of my head and to account for breaks in some sort of id field for your NPC table. You can create a new column called next_npc or something and and when they win store the next NPCs id in that column so that way their next battle has to be with that one

Re: Disabling Characters After Winning

Posted: Fri Nov 07, 2014 12:10 pm
by Epiales
KyleMassacre wrote:Ok this man sound a bit ghetto but it is the easiest way I can think of off the top of my head and to account for breaks in some sort of id field for your NPC table. You can create a new column called next_npc or something and and when they win store the next NPCs id in that column so that way their next battle has to be with that one
That might work. I could throw a new row in the users table called NPC and when they first go to the npc arena part, have it put the first name/id in the NPC row of their users table....When they defeat two, then it would put 2nd and so forth.... but the issue still remains is how would I call the NPC names but still show those that they defeated at the bottom?

Re: Disabling Characters After Winning

Posted: Fri Nov 07, 2014 12:38 pm
by KyleMassacre
I think you are getting confused on what I am saying, or maybe I am confusing here lol. You won't need anything in the users table at all, thats how clutter begins. Instead create a new table, this table will hold all the info for beaten NPCs. You will basically have 2 queries here, 1 for the NPC table and one for the beaten NPC table. If there is a result for the NPC id and the userid then obviously they can't attack them then so render that link useless. Now what you can do is filter out the NPCs and select the minimum id of the NPCs that have not been beaten and that would be your next challenge as a player

Re: Disabling Characters After Winning

Posted: Fri Nov 07, 2014 2:13 pm
by Epiales
Well I guess I'm majorly confused, I can't figure this out.

I've tried it this way too:

Code: Select all

<?php
$sql = "SELECT * FROM arenalogs WHERE userid = '$_SESSION[userid]'";
$user_query2 = mysqli_query($db_conx, $sql);
$numrows = mysqli_num_rows($user_query2);
$row = mysqli_fetch_array($user_query2, MYSQLI_ASSOC);

$arena_charid = $row['charid'];

$sql = "SELECT * FROM characters where id !='$arena_charid' ORDER BY id ASC"; 
$user_query = mysqli_query($db_conx, $sql);
$numrows = mysqli_num_rows($user_query);
?>
This is only working for the first character ID... So the 1st one doesn't show in the output... But if I put another character ID in the arenalongs, then it doesn't matter...doesn't do anything.

Example of arenalogs....

id = autocrement
userid
charid

So when I add a row that had 1 as the userid and 1 as the charid, the list only shows 16 entries instead of the 1st one like it should..... it goes from 2-17... but if I add another row with userid of 1 and charid of 2, it doesn't affect the outcome for some reason.