Author Topic: Single-bullet Reload System  (Read 2252 times)

0 Members and 1 Guest are viewing this topic.

Offline AL

  • Major(1)
  • Posts: 10
  • ...
Single-bullet Reload System
« on: January 30, 2013, 05:37:19 am »
Single-bullet Reload System
(Alternatively known as the: Single Action Reload System)

Ever wanted to top up your magazine, but not waste time going through the whole reload cycle?
Or perhaps role-play a handful of survivors of the zombie apocalypse, carefully conserving their ammo?

Regardless of your answer to either of those questions, this script is for you!  8)



Credits: Idea and code both by me (AL).

Written for Soldat Server Version: 2.7.3 (Client v1.6.3)


Synopsis: Adds a (optional) 'spas style' bullet-by-bullet reload mechanic to all weapons (should work even with weapon mods).
Players can choose whether to perform the normal full reload by tapping the reload key, or to use my reload system by holding the reload key instead.

Code snippets:
(None! - With the whole script being only ~60 lines long, I may as well just paste the full thing in directly)


Notes:
  • For best results: release your reload key once your weapon switches to a spas, and run soldatserver with '-safe 0' for optimal timings
    (if you don't, you will trigger a normal reload when your wep switches back again) the script will wait for you to release the reload button before proceeding (as of v1.1)
  • You may want to add some kind of messaging system to tell your players that this script actually exists. The script by itself does not add anything of the sort.
  • The code is uncommented, due to its comparatively tiny length and a (small?) degree of laziness from myself

Known Issues/Bugs:
  • Idle animations such as /tabac cancel the reloading sequence
  • If you change weapons twice (quickly), the ammo you start reloading from is sometimes different from what it should be
  • Any person with reasonable reflexes can turn their gun into a spas (reduced from outright spawning a new spas)
« Last Edit: February 01, 2013, 05:43:09 am by AL »

Offline TheOne

  • Soldier
  • **
  • Posts: 208
Re: Single-bullet Reload System
« Reply #1 on: January 30, 2013, 08:56:50 am »
First of all, you're a brave scripter to dive into weapon things right at the start  (I guess you don't have coded in soldat much yet). It's - in my opinion - the ugliest area in the entire scriptcore. :)

It's a nice idea to abuse this bug, and I don't know if there's a more successful way to code it. It works quite well once you get used to the timing. Maybe you could achieve better results by using a higher AppOnIdle Frequency, for example to turn the spas back into the right weapon faster (currently you do it after 60 ticks, as that's the default frequency), because currently you waste a lot of time until it starts reloading. I'm not familiar with how the bug exactly works, though, it'd need a LOT of time for testing and debugging.
« Last Edit: January 30, 2013, 09:00:13 am by TheOne »

Offline TheOne

  • Soldier
  • **
  • Posts: 208
Re: Single-bullet Reload System
« Reply #2 on: January 30, 2013, 09:08:14 am »
Tested with an AppOnIdleTimer of 10 (Ticks) now, that worked even smoother. Probably you achieve the same results with 30, as your threshold is exactly that.
The check for OnKeyPress should stay at 1hz like it is, otherwise it can be difficult to trigger a normal reload instead of the SARS.

One note: To be more efficient and on the safe side, you should check in the for-loop, whether that ID is active at all (and maybe, whether he's alive).

Offline AL

  • Major(1)
  • Posts: 10
  • ...
Re: Single-bullet Reload System
« Reply #3 on: January 30, 2013, 04:27:11 pm »
First and foremost, thanks for your feedback, I appreciate it   :D

While this is my first script release on the soldat forums (or anywhere else for that matter), I've been doing soldat scripting privately for a while now. This was just a bit of a side project I did while I polished off my larger scripts.

To the extent of my knowledge, AppOnIdle is only called once a second, so setting delays < 60 ticks would not make any difference. I tried setting the timer to 10 ticks instead, but it didn't have any perceptible difference for me :/

As per your suggestion, I've also added the extra checks on the player ID before doing anything else.

Offline TheOne

  • Soldier
  • **
  • Posts: 208
Re: Single-bullet Reload System
« Reply #4 on: January 30, 2013, 05:11:26 pm »
Yes, AppOnIdle is called once per second by default. The AppOnIdle timer changes that, I'm not sure why it didn't work for you - perhaps you have to disable the safe mode when starting the server? I noticed a drastic change to good when enabling it.

Offline AL

  • Major(1)
  • Posts: 10
  • ...
Re: Single-bullet Reload System
« Reply #5 on: January 31, 2013, 04:11:14 pm »
Disregard the previous response, I thought you meant something else   ::)
One question about using AppOnIdleTimer tho: if you change it in one script, wont it affect the timers on every other script you're running?

Offline TheOne

  • Soldier
  • **
  • Posts: 208
Re: Single-bullet Reload System
« Reply #6 on: January 31, 2013, 04:24:44 pm »
It will only affect that script you're putting it into. You can set it in ActivateServer().
Also you can always have some parts on 1 hz and some parts faster, like this:
Code: [Select]
procedure AppOnIdle(Ticks: integer);
begin
  if Ticks mod 10 <> 0 then
    Execute6hzAppOnIdle();
  if Ticks mod 60 <> 0 then
    Execute1hzAppOnIdle();
end;

In your case, the check for key presses would be 1hz, the other things 6hz?

Offline AL

  • Major(1)
  • Posts: 10
  • ...
Re: Single-bullet Reload System
« Reply #7 on: February 01, 2013, 02:37:22 am »
Alright, thanks for helping again; I'll have a new version posted soon.