Forked from JuniorDjjr/Reload Mod (Junior_Djjr).sc
Last active
December 5, 2024 10:12
-
-
Save SandeMC/4c6d52a05f71af24702eaa28f6b692cf to your computer and use it in GitHub Desktop.
Fixed Reload Mod by Junior_Djjr, details in comments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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 |
Author
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
I updated the official download
Author
@JuniorDjjr In the MixMods upload, you accidentally removed the [Controls] category, which breaks the mod

Author
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
Author
@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
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.