PHP System to heal x user in x minutes

Asked

Viewed 94 times

0

Good morning guys! I’m creating a little role-playing game and I’m not figuring out how to get it to heal the x user in x minutes. I managed to do via ajax, but it’s not safe right? Easily the user can cheat and heal his whole life if he wants... Is there any way to do this without ajax? In the database I already have all the values, life, maximum life etc... Give me a strength! Thanks.

@EDIT with ajax although until it worked, the user needed to be logged in to work, it would also be something that he did not need to log in... that the system works even if it turned off.

  • 1

    Search on Cron, or something like that, the servers usually provide "chronometers" to perform scheduled tasks, you can leave a php file already done to "heal" the players, and use the scheduled tasks to run that file. I’m just not sure how little time they run..

  • Um I think I’ve seen something about it on my host... I’m going to do some research. @EDIT found, my host has advanced cron tasks option, where it can run php file every 60 seconds, which is the minimum time. Thanks for the help, I’ll leave the question open for a while to see if they give some other ideas! :)

  • 1

    Good that you thought, is that I already had to do it for a RPG game that I had created. At the time this was the best solution I could find. Any doubt can speak

  • Just to understand... you will send something to php or just run a file that is already there?

  • I’m currently using cron... It runs php with the script that heals if life is below the maximum limit...

1 answer

1


You can have an event in the database that every x and x time does some action for you, for example:

Character table, with id, name and life.

CREATE TABLE IF NOT EXISTS personagem (
    id INT PRIMARY KEY AUTO_INCREMENT,
    nome VARCHAR(40) NOT NULL,
    vida INT NOT NULL DEFAULT 50
)

Event, every 2 minutes adds +10 the life of the character, if it is better than 100 (has to have control for if life is in 92, not go to 102, because in the example the maximum life is 100, Mad I will not do this)

DELIMITER $$
--
-- Eventos
--
CREATE EVENT `realizaCura` 
ON SCHEDULE EVERY 2 MINUTE
STARTS '2016-05-12 15:11:10' ON COMPLETION NOT PRESERVE ENABLE 
DO UPDATE personagem SET personagem.vida = (personagem.vida + 10) WHERE personagem.vida < 100$$
DELIMITER ;

Sorry if you have a syntax error, I did it over the phone.

  • 2

    As for the fact that it is not safe using ajax, right, it could manipulate, however it could also work on a "key" and or lock that allows such ajax to be run only every X time and if the key is not the valid it does not perform. Another alternative would be the use of CRON as already said by Fleuquer Lima. How is it done when it "loses" life? If done through ajax, you should take into account that this can also be manipulated...

  • Bacana Ivcs, +1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.