Jump to content

Dillybob

New Members
  • Posts

    6
  • Joined

  • Last visited

Dillybob's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. That is quite a reply. I understand the 'tick process' more thoroughly now though. Thanks for that! My issue I'm trying to comprehend is, how in the hell do I install a tick server that runs along side with PHP? I'm currently re-writing my game socket server from php to nodejs (javascript), so I can literally, just use setInterval. I think it's a waste of time, but the setInterval is what will make the game dynamic and differentiate it between a regular pokemon combat game, or an action RPG where monsters can attack you. I'm aiming moreover for the dynamic attack system. It's for monster ticks. As of right now, the only way a monster can do any damage to the main characters in game, is if a user engages a request to PHP so I can do the calculations. I am not going to rely on javascript clientside coding to cast the monster to attack, that is unreliable and not secure. This is where setInterval comes in and where I cannot achieve it with PHP. When a player enters a world and walks in range to a monster the setInterval will start ticking. This will include the monsters attack speed, and other functions. This achieves a much more 'dynamic' and 'fluid' feel for combat and attack mechanisms. I can also incorporate HP Regeneration, MP Regeneration, fury regeneration and other fun stuff. All using simple setIntervals (or a simple ticker). That's pretty much the jist of it thus far.
  2. Don't mean to be rude but a lot of that stuff flew right over my head. (Not your fault) From what I get is you're recommending a daemon server to be running along side my gameserver? And this can keep track of the setIntervals? (Or in this case, if I use PHP's pthreads) I can incorporate usleep, or your function above).
  3. Thanks for the response. One issue though. usleep won't work for my project as other players will be accessing that code at the same time (It will bottleneck other users access to the script itself) Someone told me I need to use threads? Would that make the usleep per user specific? So it won't effect other people accessing the script?
  4. I have a very troubling problem at hand. I am using a web-socket server that runs in PHP. The issue is I need to be able to use a setInterval/setTimeout function similar to javascript, but within my php server. I do not have the time or resources to convert my entire project over to nodejs/javascript. It will take forever. I love php so much, that I do not want to make the switch. Everything else works fine and I feel like it's not worth it to re-write everything just because I cannot use a similar setInterval function inside php. Since the php socket server runs through the shell, I can use a setInterval type function using a loop: protected function on_server_tick($counter) { if($counter%5 == 0) { // 5 seconds interval } if($counter%10 == 0) { // 10 seconds interval } } $this->last_tick_time = microtime(true); $this->tick_interval = 1; $this->tick_counter = 0; while(true) { //loop code here... $t= microtime(true) - $this->last_tick_time; if($t>= $this->tick_interval) { $this->on_server_tick(++$this->tick_counter); $this->last_tick_time = microtime(true) - ($t- $this->tick_interval); } } This code does work as intended, but it seems a bit overboard for resources and I feel like that while loop will suck a lot resources. Is there anyway I can re-compile PHP from source and include a "while2" loop that only iterates every 500 miliseconds instead of instantly?
  5. Yeah but someone can just simply disable that monster from attacking via F12 (Dev tools on Chrome)? (Or by clientside JS) I need some type of server ticker on PHP's websocket, is it possible? Similiar to setTimeout or setInterval functions. I can achieve this effect by doing this: $echo_time = $users[$clientID]['last_session_request']; $interval = 3; while($echo_time + $interval >= time() ){ echo 'Looping...'; if ($echo_time + $interval <= time()){ echo "$interval seconds have passed... \n "; $echo_time = time(); // set up timestamp for next interval } // other uninterrupted code goes here. } But, the 'echo Looping...' runs like mad and I think that sucks in a lot of CPU usage on my socket server, that isn't supposed to be used.. Hmm...
  6. I am creating a top-down rpg character movement w/ combat. You click on a part of the map (in this case, it's a image, and your character .png image transitions to that spot). It's with Javascript and PHP. I'm using a PHP socket server. I have it where players can only move up to 200 pixels per each click. Each click is essentially a packet being sent to my gameserver. Then the gameserver validates if it's a valid input (1235x1235) format, and spits it out to other players in that specific game. (So it's a consistent world/map). This works perfect. If I want to incorporate a monster that has AI and starts to attack the character... I can do that with javascript easily with setInterval or setTimeout functions (to make the mob move and then attack the character). But how do I do that serverside with PHP simultaneously? Because a user could just press F12 and edit the javascript to stop the mob from attacking. But, I need the mob to attack the player every xxx milliseconds serverside as well. How can this done with PHP? I feel like I need some type of heartbeat going on where it's a constant check between client and server every xxx seconds? I might be going off on the deep end and I'll stop talking I hope you get the jist of it. Any ideas are greatly appreciated. Another thought: Think of the popular aRPG games out there. Diablo 2, Diablo 3, Path of Exile, etc. Imagine using a hack that just stops mobs from moving towards your character and attacking it. Is that just an illusion? And the "auto attacking" is done serverside regardless if you've stopped that mob on the client, right? If so, how to accomplish this with a PHP socket server with some Javascript? I'm not looking for code, just an application theory or design process would be awesome. P.S. It's either I go this route, or the game becomes a simple real time strategy Pokemon style combat. Which I really, really don't want... TLDR: How to have monsters auto attack your character (or in this case, update values in a temp variable, or a field name) server-side with some client-side JavaScript, and a php socket server. Securely on the server.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.