Page 1 of 1
the quickest, most resourceful, easy way to do this?
Posted: Fri Jan 23, 2004 2:25 pm
by lizlazloz
ok, i'm making a little online game, just for fun, and in it you can 'attack' people. what i want to do is make it so u can only attack a particular person once a day.
how would i do this??? cookies wouldnt work as the user could just delete them, and neither sessions cuz the suer could just close the browser. all i can think of is an absolutely massive MySQL database, sure theres a better way?
Posted: Fri Jan 23, 2004 3:14 pm
by Sevengraff
It won't be that massive if all you have to keep track of is when the user last did an attack.
When a user attacks, store the time in mysql. Then when he tries to attack again, see if the recorded time is older than a day. It will take 2 querys, get the time & check, then update the time.
Posted: Sat Jan 24, 2004 3:04 am
by lizlazloz
yes, but the thing is, i want the user to be able to attack all the other players in the game, just not the 1 they have already attacked. so if i did it the way you said i would need a field in each entry for every other user... right? and that aint gonna happen

Posted: Sat Jan 24, 2004 11:46 am
by ilovetoast
Four db fields:
id - primary key
attacker_id - the one attacking, foreign key for a separate user table
defender_id - the one being attacked, foreign key for a separate user table
attack_time - time of attack as timestamp of your choice
One table row per possible attack. The row only needs to exist if the attack actually occured and you can use a housekeeping routine to periodically discard badly out of date entries.
Then, as Sevengraff pointed out, just run two queries.
peace
eat toast all day long
Posted: Sat Jan 24, 2004 2:27 pm
by d3ad1ysp0rk
make sure you have a cron to delete the tables everynight tho, or 1. your db will get huuuuge and 2. people won't be able to attacks others again