Skip to content

Instantly share code, notes, and snippets.

@SandeMC
Forked from JuniorDjjr/Reload Mod (Junior_Djjr).sc
Last active December 5, 2024 10:12
Show Gist options
  • Save SandeMC/4c6d52a05f71af24702eaa28f6b692cf to your computer and use it in GitHub Desktop.
Save SandeMC/4c6d52a05f71af24702eaa28f6b692cf to your computer and use it in GitHub Desktop.
Fixed Reload Mod by Junior_Djjr, details in comments
// Originally made by Junior_Djjr - https://www.mixmods.com.br/2019/07/reload-mod.html
// Fixed by GillianMC - https://gist.github.com/SandeMC/4c6d52a05f71af24702eaa28f6b692cf
// You need: https://forum.mixmods.com.br/f16-utilidades/t179-gta3script-while-true-return_true-e-return_false
SCRIPT_START
{
LVAR_INT scplayer playerId pPed i j iCmds[2] pLib bDontReloadIfFull bDisableWeaponsWithoutAnim bRealisticReload bDisabledOnSAMP bKeepNoAmmo bDisableScrollReload bDisableVehicleAutoReload iCurWeapon iSkill iMaxAmmo iCurAmmo pWeapon pWeaponInfo iState iTimeInMilliseconds iReloadTime iLastCurAmmo iTotalAmmo
IF NOT READ_INT_FROM_INI_FILE "CLEO/Reload Mod.ini" "Controls" "CMD_Player1" (iCmds[0])
OR NOT READ_INT_FROM_INI_FILE "CLEO/Reload Mod.ini" "Controls" "CMD_Player2" (iCmds[1])
OR NOT READ_INT_FROM_INI_FILE "CLEO/Reload Mod.ini" "Settings" "DontReloadIfFull" (bDontReloadIfFull)
OR NOT READ_INT_FROM_INI_FILE "CLEO/Reload Mod.ini" "Settings" "DisableWeaponsWithoutAnim" (bDisableWeaponsWithoutAnim)
OR NOT READ_INT_FROM_INI_FILE "CLEO/Reload Mod.ini" "Settings" "RealisticReload" (bRealisticReload)
OR NOT READ_INT_FROM_INI_FILE "CLEO/Reload Mod.ini" "Settings" "DisabledOnSAMP" (bDisabledOnSAMP)
OR NOT READ_INT_FROM_INI_FILE "CLEO/Reload Mod.ini" "Settings" "KeepNoAmmo" (bKeepNoAmmo)
OR NOT READ_INT_FROM_INI_FILE "CLEO/Reload Mod.ini" "Settings" "DisableScrollReload" (bDisableScrollReload)
IF NOT READ_INT_FROM_INI_FILE "CLEO/Reload Mod.ini" "Settings" "DisableVehicleAutoReload" (bDisableVehicleAutoReload)
timera = 0
WHILE timera < 3000
WAIT 0
PRINT_STRING_NOW "Error: Fail to read 'Reload Mod.ini'" 1000
ENDWHILE
TERMINATE_THIS_CUSTOM_SCRIPT
ENDIF
ENDIF
IF bDisabledOnSAMP = TRUE
LOAD_DYNAMIC_LIBRARY "kernel32" (pLib)
GET_DYNAMIC_LIBRARY_PROCEDURE "GetModuleHandleA" pLib (i)
CALL_FUNCTION_RETURN i 1 0 ("SAMP.dll")(i)
FREE_DYNAMIC_LIBRARY pLib
IF i > 0
TERMINATE_THIS_CUSTOM_SCRIPT
ENDIF
ENDIF
IF bKeepNoAmmo = TRUE
IF LOAD_DYNAMIC_LIBRARY "KeepNoAmmo.SA.asi" (i)
IF GET_DYNAMIC_LIBRARY_PROCEDURE "PatchNoReload" i (j)
CALL_FUNCTION j 0 0
ENDIF
FREE_DYNAMIC_LIBRARY i
ENDIF
// Disabled scroll reload to fix an issue with KeepNoAmmo - credit for the code: https://libertycity.net/files/gta-san-andreas/35306-realistichnost-v-prokrutke-oruzhija.html
WRITE_MEMORY 0x60B4FA 6 (0x90) FALSE
ENDIF
IF bRealisticReload = TRUE
WRITE_MEMORY 0x7422A6 3 (0x90) FALSE
WRITE_MEMORY 0x60B4FA 6 (0x90) FALSE
ELSE
IF bDisableScrollReload = TRUE
WRITE_MEMORY 0x60B4FA 6 (0x90) FALSE
ENDIF
IF bDisableVehicleAutoReload = TRUE
WRITE_MEMORY 0x7422A6 3 (0x90) FALSE
ENDIF
ENDIF
/////////////////////////////////////////////
WHILE TRUE
WAIT 0
playerId = 0
GOSUB Activate
IF IS_2PLAYER_GAME_GOING_ON
playerId = 1
GOSUB Activate
ENDIF
ENDWHILE
Activate:
IF IS_PLAYER_CONTROL_ON playerId
IF GOSUB IsPressingCMD
GET_PLAYER_CHAR playerId (scplayer)
GET_PED_POINTER scplayer (pPed)
i = pPed + 0x718 //m_nActiveWeaponSlot
READ_MEMORY i 1 FALSE (i)
IF NOT i = 0
AND NOT IS_CHAR_DEAD scplayer
i *= 0x1C //sizeof CWeapon
i += pPed
pWeapon = i + 0x5A0 //CWeapon
GET_CURRENT_CHAR_WEAPON scplayer (iCurWeapon)
// disabled weapons
IF bDisableWeaponsWithoutAnim = TRUE
IF iCurWeapon = WEAPONTYPE_FLAMETHROWER
OR iCurWeapon = WEAPONTYPE_MINIGUN
OR iCurWeapon = WEAPONTYPE_EXTINGUISHER
OR iCurWeapon = WEAPONTYPE_SPRAYCAN
OR iCurWeapon = WEAPONTYPE_CAMERA
RETURN
ENDIF
ENDIF
//char __thiscall CPed::GetWeaponSkill(CPed *this, eWeaponType weaponType)
CALL_METHOD_RETURN 0x5E3B60 pPed 1 0 (iCurWeapon)(iSkill)
//CWeaponInfo *__cdecl CWeaponInfo::GetWeaponInfo(eWeaponType weaponID, char skill)
CALL_FUNCTION_RETURN 0x743C60 2 2 (iSkill iCurWeapon)(pWeaponInfo)
iMaxAmmo = pWeaponInfo + 0x20 //ammoClip
READ_MEMORY iMaxAmmo 2 FALSE (iMaxAmmo)
IF iMaxAmmo > 1 // only activate on weapons with clips
iCurAmmo = pWeapon + 0x8 //m_nAmmoInClip
READ_MEMORY iCurAmmo 4 FALSE (iCurAmmo)
IF bDontReloadIfFull = TRUE
IF iCurAmmo = iMaxAmmo
RETURN
ENDIF
ENDIF
iState = pWeapon + 0x4 // m_nState
READ_MEMORY iState 4 FALSE (iState)
IF iState = 2 // reloading state
RETURN
ENDIF
// Don't reload if there's no spare ammo
iTotalAmmo = pWeapon + 0xC //m_nTotalAmmo
READ_MEMORY iTotalAmmo 4 FALSE (iTotalAmmo)
IF iTotalAmmo = iCurAmmo
RETURN
ENDIF
//signed int __thiscall CWeaponInfo::GetWeaponReloadTime(CWeaponInfo *this)
CALL_METHOD_RETURN 0x743D70 pWeaponInfo 0 0 ()(iReloadTime)
// Fast reload tweak
j = playerId * 0x190 //sizeof CPlayerInfo
j += 0xB7CB84
READ_MEMORY j 1 FALSE (j) //CWorld::Players[playerId].fastReload
IF j = TRUE
iReloadTime /= 4
ENDIF
// Set shot timer limit
READ_MEMORY 0xB7CB84 4 FALSE (iTimeInMilliseconds)
j = iReloadTime + iTimeInMilliseconds
i = pWeapon + 0x10 //m_nShotTimer
WRITE_MEMORY i 4 (j) FALSE
// Remove the clip if realistic reloading is enabled
IF bRealisticReload = TRUE
j = pWeapon + 0xC //m_nTotalAmmo
i = pWeapon + 0x8 //m_nAmmoInClip
WRITE_MEMORY i 4 (0) FALSE
i = iTotalAmmo-iCurAmmo
WRITE_MEMORY j 4 (i) FALSE
ENDIF
// Set reload state
i = pWeapon + 0x4 //m_nState
WRITE_MEMORY i 4 (2) FALSE
// Wait reload end
timera = 0
i = pWeapon + 0x8 //m_nAmmoInClip
READ_MEMORY i 4 FALSE (iLastCurAmmo)
WHILE iLastCurAmmo = iCurAmmo
AND timera < 3000 // anti-bug
WAIT 0
READ_MEMORY i 4 FALSE (iLastCurAmmo)
ENDWHILE
ENDIF
ENDIF
ENDIF
ENDIF
RETURN
IsPressingCMD:
i = iCmds[playerId]
IF i <= 19
IF IS_BUTTON_PRESSED playerId i
RETURN_TRUE
RETURN
ENDIF
ELSE
IF IS_KEY_PRESSED i
RETURN_TRUE
RETURN
ENDIF
ENDIF
RETURN_FALSE
RETURN
}
SCRIPT_END
@SandeMC
Copy link
Author

SandeMC commented Mar 4, 2024

Changes:

  • Fixed the issue of the original script where it will restart the reload animation if you press R again during reload.
  • Fixed the issue of the original script where it will reload even if you have no spare ammo.
  • Fixed the issue of the original script that allowed to reload with the Minigun, Flamethrower, Fire Extinguisher, Spraycan and the Camera despite having no reload animation for them (optional).

Additions:

  • Realistic reloading, which removes all the ammo you had before reloading (optional).
  • Disabling scroll reloading (optional; forced on with KeepNoAmmo to fix a bug).

Download: https://www.mediafire.com/file/7cogwzzwbqiang0/Reload_Mod_Fixed.zip/file

@JuniorDjjr
Copy link

JuniorDjjr commented Sep 17, 2024

The disabled weapons are checked by ID, if this is important (what is the issue? CJ does some animation that does nothing?), is better to change it to check by flags (I don't know exactly, need to do some research), because whatever you can reload or not is defined by flag (check weapon.dat). That way will be adapted for added weapons without replacing or weapon mods that may make it possible/impossible to reload some gun.

@SandeMC
Copy link
Author

SandeMC commented Sep 17, 2024

what is the issue? CJ does some animation that does nothing?

There's no animation at all, the ammo count just gets refilled (and the ones disabled do have a magazine for whatever reason)

@The-Haxor
Copy link

I left a comment in the libertycity page but I'll copy paste here too and include a video:
I have a bug that I also had with Junior_Djjr's version where if I empty the clip of a gun and then immediately swap weapons (before the reload), when I go back to that gun it will appear as reloaded and will do the shooting animations but no actual bullets will be shot and no sound will play either, basically softlocking this gun. I'm using the KeepNoAmmo integration (this bug doesn't seem to happen without it).

gta.mp4

I would also love if there was an option to make it so you can't reload by swapping weapons, this way you'll always have to press R and go through the reload animation to reload a weapon.

@SandeMC
Copy link
Author

SandeMC commented Sep 24, 2024

I left a comment in the libertycity page but I'll copy paste here too and include a video: I have a bug that I also had with Junior_Djjr's version where if I empty the clip of a gun and then immediately swap weapons (before the reload), when I go back to that gun it will appear as reloaded and will do the shooting animations but no actual bullets will be shot and no sound will play either, basically softlocking this gun. I'm using the KeepNoAmmo integration (this bug doesn't seem to happen without it).

gta.mp4
I would also love if there was an option to make it so you can't reload by swapping weapons, this way you'll always have to press R and go through the reload animation to reload a weapon.

I think it's a bug with KeepNoAmmo script itself rather than mine - I don't think I can fix it

The only way to fix it would be to avoid restoring ammo when switching weapons, but I have no idea how to implement that and the only script that did online doesn't have some source code to look at

@SandeMC
Copy link
Author

SandeMC commented Sep 24, 2024

@The-Haxor Hey, try the updated version, I've found some code I could put

@JuniorDjjr
Copy link

But this is already fixed by MixSets.

@SandeMC
Copy link
Author

SandeMC commented Sep 24, 2024

I want everything related to the script to be a part of the same script - telling people to download multiple mods just to fix a bug isn't it

@JuniorDjjr
Copy link

I want everything related to the script to be a part of the same script - telling people to download multiple mods just to fix a bug isn't it

I think you don't know MixSets. The goal of MixSets is literally what you said right now, is almost 300 tweak options (including dozens of fixes) in the same mod so people don't need to download multiple mods to fix the game.

So, just like you said, use MixSets instead of adding multiple mods to fix the game.

@SandeMC
Copy link
Author

SandeMC commented Sep 24, 2024

I want everything related to the script to be a part of the same script - telling people to download multiple mods just to fix a bug isn't it

I think you don't know MixSets. The goal of MixSets is literally what you said right now, is almost 300 tweak options (including dozens of fixes) in the same mod so people don't need to download multiple mods to fix the game.

So, just like you said, use MixSets instead of adding multiple mods to fix the game.

I think you didn't understand the problem. It comes from KeepNoAmmo and Reload Mod cross-compatibility - we don't have MixSets installed here (let's assume we don't, anyway). When the ammo stays at 0 it doesn't auto-reload and KeepNoAmmo expects that - but it breaks when the ammo refills by scrolling the wheel.

What you suggest is for that person to install MixSets (again, in the scenario let's assume it isn't already) just to fix the issue that comes from two existing mods, whereas I can simply integrate it into this script and keep it at two. Which I did.

P.S. I do agree that MixSets is great, but I want this to work without MixSets aswell

@JuniorDjjr
Copy link

I want everything related to the script to be a part of the same script - telling people to download multiple mods just to fix a bug isn't it

I think you don't know MixSets. The goal of MixSets is literally what you said right now, is almost 300 tweak options (including dozens of fixes) in the same mod so people don't need to download multiple mods to fix the game.
So, just like you said, use MixSets instead of adding multiple mods to fix the game.

I think you didn't understand the problem. It comes from KeepNoAmmo and Reload Mod cross-compatibility - we don't have MixSets installed here (let's assume we don't, anyway). When the ammo stays at 0 it doesn't auto-reload and KeepNoAmmo expects that - but it breaks when the ammo refills by scrolling the wheel.

What you suggest is for that person to install MixSets (again, in the scenario let's assume it isn't already) just to fix the issue that comes from two existing mods, whereas I can simply integrate it into this script and keep it at two. Which I did.

P.S. I do agree that MixSets is great, but I want this to work without MixSets aswell

Ah, is another additional issue, because refilling by scroll wheel is a native issue, so we now also have a new issue besides of that.
But is fixed if use MixSets, right?

@The-Haxor
Copy link

The-Haxor commented Sep 25, 2024

@The-Haxor Hey, try the updated version, I've found some code I could put

I was only able to test it briefly but it looks like the new functionality and the bug fix both work! The mod is like 200% better now! For me, at least.

I didn't know MixSets let you disable switch reloading. I have MixSets on the backlog of mods that I wanted to check out, it just had such a long list of changes that I had been putting it off because just thinking about fully configuring it gave me a headache.

Now there's only one small thing left that's bugging me. Although I think this is technically a problem with the vanilla game, it becomes more apparent when using the mod. If you reload and, while the animation is going, you see something you wanna shoot at and you aim at it, the reload gets cancelled and then plays a second time, which wastes times and throws me off. I did a quick search and I believe MixSets doesn't fix this.

Edit: actually, it looks like more things can cancel the reload animation. If you're crouched and not moving when you start reloading then moving or standing up can cancel it too. This game is kinda annoying.

I also noticed a thing that could be a bit more relevant. In vanilla, when you walk over a weapon on the ground, doing so still puts bullets in your mag so it removes the need for reloading in some cases.

@SandeMC
Copy link
Author

SandeMC commented Sep 25, 2024

Now there's only one small thing left that's bugging me. Although I think this is technically a problem with the vanilla game, it becomes more apparent when using the mod. If you reload and, while the animation is going, you see something you wanna shoot at and you aim at it, the reload gets cancelled and then plays a second time, which wastes times and throws me off. I did a quick search and I believe MixSets doesn't fix this.

Edit: actually, it looks like more things can cancel the reload animation. If you're crouched and not moving when you start reloading then moving or standing up can cancel it too. This game is kinda annoying.

I also noticed a thing that could be a bit more relevant. In vanilla, when you walk over a weapon on the ground, doing so still puts bullets in your mag so it removes the need for reloading in some cases.

I'm afraid I can't fix either of these, sadly

@The-Haxor
Copy link

I think I found an actual bug now. When using the country rifle only the first shot works. This is the config I'm using:
DisabledOnSAMP = 1
DontReloadIfFull = 1
RealisticReload = 0
DisableScrollReload = 1
KeepNoAmmo = 1

Doesn't seem to happen without KeepNoAmmo.

@SandeMC
Copy link
Author

SandeMC commented Sep 25, 2024

I think I found an actual bug now. When using the country rifle only the first shot works. This is the config I'm using: DisabledOnSAMP = 1 DontReloadIfFull = 1 RealisticReload = 0 DisableScrollReload = 1 KeepNoAmmo = 1

Doesn't seem to happen without KeepNoAmmo.

This seems to be a bug with KeepNoAmmo itself - in particular, the asi file, which has no source code, so I can't tackle on it.
At least I think that's the case.

@The-Haxor
Copy link

Unlucky. I guess I can just uninstall KeepNoAmmo then. Only wanted it for being able to empty the mag and switch quickly but I guess I'll live without it. Vanilla game animation cancels are more annoying

@JuniorDjjr
Copy link

I updated the official download

@SandeMC
Copy link
Author

SandeMC commented Nov 13, 2024

@JuniorDjjr In the MixMods upload, you accidentally removed the [Controls] category, which breaks the mod
image

@SandeMC
Copy link
Author

SandeMC commented Nov 25, 2024

Update

  • Added a new option, DisableVehicleAutoReload (per request on LibertyCity)
  • Readjusted forced options
    • KeepNoAmmo forces scroll reloading to be disabled
    • RealisticReload forces scroll reloading and vehicle autoreloading to be disabled

@SandeMC
Copy link
Author

SandeMC commented Nov 25, 2024

@JuniorDjjr Update the MixMods upload when you're free, thanks
Take note of the new option

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment