Gentaurg
|
  |
| Joined: 19 Mar 2011 |
| Total Posts: 8648 |
|
|
| 08 Mar 2016 02:21 PM |
| I want to make a server-side stamina system. It needs to regenerate at X stamina per second consistently. How would I go about making this? |
|
|
| Report Abuse |
|
|
sonihi
|
  |
| Joined: 27 Jun 2009 |
| Total Posts: 3655 |
|
|
| 08 Mar 2016 02:23 PM |
You could make it so if the player spawns a stamina script with a value is added to his character.
|
|
|
| Report Abuse |
|
|
xlaser23
|
  |
| Joined: 10 Dec 2011 |
| Total Posts: 20341 |
|
| |
|
Gentaurg
|
  |
| Joined: 19 Mar 2011 |
| Total Posts: 8648 |
|
|
| 08 Mar 2016 02:37 PM |
| I was thinking about doing that but I was wondering if there was some other clever way. Does it cause lag to have many scripts that do this? |
|
|
| Report Abuse |
|
|
OzzyFin
|
  |
| Joined: 07 Jun 2011 |
| Total Posts: 3600 |
|
|
| 08 Mar 2016 02:49 PM |
have a table of all the players' staminas. Use a remotefunctions to tell the server that a client wants to use stamina, server checks if there's enough for the wanted action, if so return true, if not return false
|
|
|
| Report Abuse |
|
|
OzzyFin
|
  |
| Joined: 07 Jun 2011 |
| Total Posts: 3600 |
|
|
| 08 Mar 2016 02:54 PM |
I forgot the second part I suppose you're wondering about efficiency. Firing an RF/RE multiple times in a short time shouldn't be too big of a problem but I bet you can make the delay a bit longer. I doubt it matters if a player can run for .3 secs longer in certain scenarios
also I swear I took the s in "remotefunctions" out |
|
|
| Report Abuse |
|
|
|
| 08 Mar 2016 02:56 PM |
Have two stamina values per player. One is stored in local storage, the other in server storage. Whenever the player uses or gains stamina, update both the local and server values at the same time. Check only the server value when determining if the player has enough stamina to do a certain action, and periodically reset the client side value to the server side value.
The reasoning for this method is that you want any GUI's or other visuals to instantly reflect changes in stamina, providing feedback is an important trick in making a game not feel laggy.
There may be better ways to do it, but that's a method that I like. |
|
|
| Report Abuse |
|
|
OzzyFin
|
  |
| Joined: 07 Jun 2011 |
| Total Posts: 3600 |
|
|
| 08 Mar 2016 02:58 PM |
| with my method you also want to decrease the stamina as well as return the new stamina for GUIs though for those you want the smallest possible delay which again shouldn't be a big problem |
|
|
| Report Abuse |
|
|
Gentaurg
|
  |
| Joined: 19 Mar 2011 |
| Total Posts: 8648 |
|
|
| 08 Mar 2016 03:48 PM |
| what I'm most concerned about is the regeneration - wouldn't I have to run one while loop per player? |
|
|
| Report Abuse |
|
|
sonihi
|
  |
| Joined: 27 Jun 2009 |
| Total Posts: 3655 |
|
|
| 08 Mar 2016 04:33 PM |
You could have them all in a table and add to them one after another
|
|
|
| Report Abuse |
|
|
|
| 08 Mar 2016 04:33 PM |
| No, you can have them all regenerate at a set rate from one script |
|
|
| Report Abuse |
|
|
Gentaurg
|
  |
| Joined: 19 Mar 2011 |
| Total Posts: 8648 |
|
|
| 08 Mar 2016 04:40 PM |
| so every player would regenerate stamina at the exact same time? |
|
|
| Report Abuse |
|
|