Page 1 of 1

Last attacked list?

Posted: Mon Jul 19, 2010 3:34 am
by Rastan
I have been trying to pin down some code to display something and can't seem to get a good start at it so I thought I'd go ahead and ask and see if someone has an idea for me ^^.

I want my "guild" page to show the last 15 or so people who have attacked the members of that guild for more potential pvp targets to just grab for revenge. So far I haven't been able to find anything that would let me do such a thing or I haven't been creative enough with it lol. Basically what happens is I have a passive pvp system where a player can attack another player and pretty much stats or a bit of luck determine the winner then I simply want it to update a list on the guild page with the attackers name.

In the end I just want those last 15 attackers to display to the guild members when they look at their guild page and I'm not sure how to firstly, store the information and secondly, call that up and display it(The second one is likely because I can't think of a good system to have it store someplace).

Is there a way I can generate a list somehow and then have it update once it fills to a capacity and bump the first entry and write in another at the top?

Any suggestion would be appreciated. Thanks!

Re: Last attacked list?

Posted: Mon Jul 19, 2010 5:22 am
by Callan S.
Do guilds have some place in the database where they are stored? Or are they sort of an adendum to player stats?

The latter is tricky. With the former for myself I'd have a long string added to the guild, long enough to take 15 character names plus 15 characters. When a player is attacked it checks their guild for this string and uses the explode function on it, breaking it into 15 strings. Shift all strings up one position, then put the new attacker in at number one place. Turn it back into one long string and put it back in the guild list.

With the latter, jeez, I'd kind of do the same but each player has a space added in its entry for one name, the last guy who fought him and a flag. At the guild page have it search the database selectively for guildmembers and those who have a name with the flag down - show them and put the flag up - show the ones you put the flag up on first, and any others to fill out the...

Gah, that second one isn't so great. It is indeed fiddley!

Re: Last attacked list?

Posted: Mon Jul 19, 2010 5:55 am
by Rastan
each guild does have it's own table. I was looking at explode. I think I'm gonna have to learn a bit more about how to do that whole thing. Kinda confuses me.

Re: Last attacked list?

Posted: Mon Jul 19, 2010 6:32 am
by Callan S.
I used some code like this in my game

Code: Select all

    // Using tilde '`' to seperate each sentence in the paragra
    $sentences = explode("`", $paragraphall);
    // putting in a minus one, because it counts from 1 the number of paragraphs, rather than starting with zero
    // when the explode function uses array[0] to store one of the paragraphs
    $numberofsentences = count($sentences)-1;
    // an example of showing the $sentences, now it's a bunch of arrays
    echo $sentences[$counter];

Re: Last attacked list?

Posted: Thu Jul 22, 2010 8:28 pm
by hallsofvallhalla
this is actually easier than you think.

Have a ID in the player field that corresponds with the players guild...so say it is named GID, so Guild Stronghold would be 1, The killers guild would be 2 and so on. if a player is not part of a guild yet then that value is 0.

now have a table called guildattacks. in there have GID, attackername, date, and whatever else you wanted.

when a player is attacked

if attacked player GID != 0

query guildattacks where GUI = attacked players GID
while
{
$count = $count + 1
}
if ($count >= 15)
{
delete from guildattacks where date is earliest and GID = attacked players GID
}
insert into guildattacks GID = attacked players GID, attacker = attacking players name, data = now, ect...

then you just query the same table to see the people who have attacked

query guildattacks where GID = players GID

Re: Last attacked list?

Posted: Fri Jul 23, 2010 2:22 am
by Rastan


if ($count >= 15)
{
delete from guildattacks where date is earliest and GID = attacked players GID
}
This I think is the part I can't get figured out. Would you happen to be able to give me a line of code that deletes by that criteria or does "earliest" work?

I was working something similar because my player table already has this field for some other easy to call purposes. Then I have made a table similar to what you just described trying to make something like this work. I was going to just delete based off a static time but I like this alot better and the other way I think will make this table HUGE. I just can't seem to totally be able to work with time so well yet.

Thanks for looking into this for me. I really appreciate it.