Adjusting Ammo

Installation support, coding tips, and general tutorials.
21 posts Page 2 of 2 First unread post
GreaseMonkey
Coder
Coder
Posts: 733
Joined: Tue Oct 30, 2012 11:07 pm


By using the script, I imagine.
Which of course would use this packet:
Code: Select all
net_s2c_reload: ; pkt 28 in decimal
        ; load buffer
        lea     edx, [esp+58H]                          ; 00434ACB _ 8D. 54 24, 58
        mov     eax, esi                                ; 00434ACF _ 8B. C6
        call    ?_04395                                 ; 00434AD1 _ E8, FFFF125A

        ; check if player indicated by packet is us, or someone else
        ; jump if it's the latter case
        movzx   eax, byte [esp+59H]                     ; 00434AD6 _ 0F B6. 44 24, 59
        mov     ecx, dword [curplr]                    ; 00434ADB _ 8B. 0D, 017B1CF0(d)
        cmp     eax, ecx                                ; 00434AE1 _ 3B. C1
        jne     ?_05818                                 ; 00434AE3 _ 0F 85, 00000093

        ;  get ammo from packet + player pointer
        movzx   edx, byte [esp+5BH]                     ; 00434AE9 _ 0F B6. 54 24, 5B
        mov     eax, ecx                                ; 00434AEE _ 8B. C1
        movzx   ecx, byte [esp+5AH]                     ; 00434AF0 _ 0F B6. 4C 24, 5A
        imul    eax, eax, 936                           ; 00434AF5 _ 69. C0, 000003A8

        ; set ammo
        mov     dword [plr_ammo_clip+eax], ecx                ; 00434AFB _ 89. 88, 0047CEA8(d)
        mov     dword [plr_ammo_reserve+eax], edx                ; 00434B01 _ 89. 90, 0047CEAC(d)

        ; get gun pointer
        mov     ecx, dword [plr_gun+eax]                ; 00434B07 _ 8B. 88, 0047CE5C(d)
        imul    ecx, ecx, 88                            ; 00434B0D _ 6B. C9, 58

        ; check the gun type, if it's not shotgunlike then jump
        cmp     dword [gun_type+ecx], ebx                ; 00434B10 _ 39. 99, 00451798(d)
        jnz     ?_05816                                 ; 00434B16 _ 75, 29

        ; compare the clip ammo with the gun's max clip ammo
        ; jump if clip ammo >= max clip ammo (use wav/cock.wav instead of the gun's reload sound)
        mov     eax, dword [plr_ammo_clip+eax]                ; 00434B18 _ 8B. 80, 0047CEA8(d)
        mov     edi, 4294966996                         ; 00434B1E _ BF, FFFFFED4
        cmp     eax, dword [gun_ammo_clip+ecx]                ; 00434B23 _ 3B. 81, 00451790(d)
        jnc     ?_05814                                 ; 00434B29 _ 73, 09

        ; get the reload sound and use that
        mov     ecx, dword [gun_wav_reload+ecx]                ; 00434B2B _ 8B. 89, 00451778(d)
        push    ecx                                     ; 00434B31 _ 51
        jmp     ?_05815                                 ; 00434B32 _ EB, 05

?_05814:push    str_wav_cock                                 ; 00434B34 _ 68, 004483E0(d)

        ; call the local sound playing routine
?_05815:call    ?_03253                                 ; 00434B39 _ E8, FFFE50F2
        add     esp, 4                                  ; 00434B3E _ 83. C4, 04

        ; for nonshotgunlike reloading...
        ; get player pointer
?_05816:mov     eax, dword [curplr]                    ; 00434B41 _ A1, 017B1CF0(d)
        imul    eax, eax, 936                           ; 00434B46 _ 69. C0, 000003A8

        ; get gun pointer + player ammo
        mov     edx, dword [plr_gun+eax]                ; 00434B4C _ 8B. 90, 0047CE5C(d)
        mov     ecx, dword [plr_ammo_clip+eax]                ; 00434B52 _ 8B. 88, 0047CEA8(d)
        imul    edx, edx, 88                            ; 00434B58 _ 6B. D2, 58

        ; compare the clip ammo with the gun's max clip ammo
        ; jump if clip ammo >= max clip ammo
        cmp     ecx, dword [gun_ammo_clip+edx]                ; 00434B5B _ 3B. 8A, 00451790(d)
        jnc     ?_05817                                 ; 00434B61 _ 73, 0C
        ; bail out if reserve ammo == 0
        cmp     dword [plr_ammo_reserve+eax], ebx                ; 00434B63 _ 39. 98, 0047CEAC(d)
        jne     net_s2c_noop                                 ; 00434B69 _ 0F 85, 00000A83
        ; i'm actually not sure what this does. it sets some float to 0, but what?
?_05817:fldz                                            ; 00434B6F _ D9. EE
        fstp    dword [?_08992+eax]                     ; 00434B71 _ D9. 98, 0047CEC4(d)
        ; anyhow, we're done.
        jmp     net_s2c_noop                                 ; 00434B77 _ E9, 00000A76

        ; for players who aren't us...
        ; get player pointer + something i don't know the meaning of right now
?_05818:imul    eax, eax, 936                           ; 00434B7C _ 69. C0, 000003A8
        lea     edx, [?_08951+eax]                      ; 00434B82 _ 8D. 90, 0047CE1C(d)

        ; get gun pointer
        mov     eax, dword [plr_gun+eax]                ; 00434B88 _ 8B. 80, 0047CE5C(d)
        imul    eax, eax, 88                            ; 00434B8E _ 6B. C0, 58

        ; play gun's reload sound
        mov     ecx, dword [gun_wav_reload+eax]                ; 00434B91 _ 8B. 88, 00451778(d)
        push    edx                                     ; 00434B97 _ 52
        push    ebx                                     ; 00434B98 _ 53
        push    ecx                                     ; 00434B99 _ 51
        call    ?_03247                                 ; 00434B9A _ E8, FFFE4F51
        add     esp, 12                                 ; 00434B9F _ 83. C4, 0C
        ; and we're done.
        jmp     net_s2c_noop                                 ; 00434BA2 _ E9, 00000A4B
LinktersHD
Deuced Up
Posts: 124
Joined: Thu Nov 01, 2012 12:27 pm


So how can i change the ammo values? Getting confused.
topo
Global Moderator
Global Moderator
Posts: 179
Joined: Thu Nov 01, 2012 12:43 pm


Are you ever not confused?
If you want this to work for you, learn to script for pyspades or ask someone else. I'm not providing a copy-and-paste solution to you. I'll give you this hint, though, since apparently common sense doesn't work for you: an error message, in addition to telling you that something is wrong, usually tells you what is wrong.
LinktersHD
Deuced Up
Posts: 124
Joined: Thu Nov 01, 2012 12:27 pm


topo wrote:
Are you ever not confused?
If you want this to work for you, learn to script for pyspades or ask someone else. I'm not providing a copy-and-paste solution to you. I'll give you this hint, though, since apparently common sense doesn't work for you: an error message, in addition to telling you that something is wrong, usually tells you what is wrong.
I'm actually am learning to code for Pyspades, working on a piece of script called "Badboys" which when you do "/bb <name>" it disables them from killing and building without the hassle to do /togglebuild and /togglekill, It's really a testing script because it's not useful for the public.
CraftDinur
Deuced Up
Posts: 152
Joined: Thu Nov 08, 2012 8:20 pm


LinktersHD wrote:
Simple answer....NO it does not work:
Image
mfw Linkters please learn to Python/pyspades

Anyways, this looks like the solution to the problem. When I was trying this before I was trying to handle ammo values client side but topo says its server side which is most likely the issue I was having.
GreaseMonkey wrote:
By using the script, I imagine.
Which of course would use this packet:
Code: Select all
net_s2c_reload: ; pkt 28 in decimal
        ; load buffer
        lea     edx, [esp+58H]                          ; 00434ACB _ 8D. 54 24, 58
        mov     eax, esi                                ; 00434ACF _ 8B. C6
        call    ?_04395                                 ; 00434AD1 _ E8, FFFF125A

        ; check if player indicated by packet is us, or someone else
        ; jump if it's the latter case
        movzx   eax, byte [esp+59H]                     ; 00434AD6 _ 0F B6. 44 24, 59
        mov     ecx, dword [curplr]                    ; 00434ADB _ 8B. 0D, 017B1CF0(d)
        cmp     eax, ecx                                ; 00434AE1 _ 3B. C1
        jne     ?_05818                                 ; 00434AE3 _ 0F 85, <a href="tel:00000093">00000093</a>

        ;  get ammo from packet + player pointer
        movzx   edx, byte [esp+5BH]                     ; 00434AE9 _ 0F B6. 54 24, 5B
        mov     eax, ecx                                ; 00434AEE _ 8B. C1
        movzx   ecx, byte [esp+5AH]                     ; 00434AF0 _ 0F B6. 4C 24, 5A
        imul    eax, eax, 936                           ; 00434AF5 _ 69. C0, 000003A8

        ; set ammo
        mov     dword [plr_ammo_clip+eax], ecx                ; 00434AFB _ 89. 88, 0047CEA8(d)
        mov     dword [plr_ammo_reserve+eax], edx                ; 00434B01 _ 89. 90, 0047CEAC(d)

        ; get gun pointer
        mov     ecx, dword [plr_gun+eax]                ; 00434B07 _ 8B. 88, 0047CE5C(d)
        imul    ecx, ecx, 88                            ; 00434B0D _ 6B. C9, 58

        ; check the gun type, if it's not shotgunlike then jump
        cmp     dword [gun_type+ecx], ebx                ; 00434B10 _ 39. 99, <a href="tel:00451798">00451798</a>(d)
        jnz     ?_05816                                 ; 00434B16 _ 75, 29

        ; compare the clip ammo with the gun's max clip ammo
        ; jump if clip ammo >= max clip ammo (use wav/cock.wav instead of the gun's reload sound)
        mov     eax, dword [plr_ammo_clip+eax]                ; 00434B18 _ 8B. 80, 0047CEA8(d)
        mov     edi, <a href="tel:4294966996">4294966996</a>                         ; 00434B1E _ BF, FFFFFED4
        cmp     eax, dword [gun_ammo_clip+ecx]                ; 00434B23 _ 3B. 81, <a href="tel:00451790">00451790</a>(d)
        jnc     ?_05814                                 ; 00434B29 _ 73, 09

        ; get the reload sound and use that
        mov     ecx, dword [gun_wav_reload+ecx]                ; 00434B2B _ 8B. 89, <a href="tel:00451778">00451778</a>(d)
        push    ecx                                     ; 00434B31 _ 51
        jmp     ?_05815                                 ; 00434B32 _ EB, 05

?_05814:push    str_wav_cock                                 ; 00434B34 _ 68, 004483E0(d)

        ; call the local sound playing routine
?_05815:call    ?_03253                                 ; 00434B39 _ E8, FFFE50F2
        add     esp, 4                                  ; 00434B3E _ 83. C4, 04

        ; for nonshotgunlike reloading...
        ; get player pointer
?_05816:mov     eax, dword [curplr]                    ; 00434B41 _ A1, 017B1CF0(d)
        imul    eax, eax, 936                           ; 00434B46 _ 69. C0, 000003A8

        ; get gun pointer + player ammo
        mov     edx, dword [plr_gun+eax]                ; 00434B4C _ 8B. 90, 0047CE5C(d)
        mov     ecx, dword [plr_ammo_clip+eax]                ; 00434B52 _ 8B. 88, 0047CEA8(d)
        imul    edx, edx, 88                            ; 00434B58 _ 6B. D2, 58

        ; compare the clip ammo with the gun's max clip ammo
        ; jump if clip ammo >= max clip ammo
        cmp     ecx, dword [gun_ammo_clip+edx]                ; 00434B5B _ 3B. 8A, <a href="tel:00451790">00451790</a>(d)
        jnc     ?_05817                                 ; 00434B61 _ 73, 0C
        ; bail out if reserve ammo == 0
        cmp     dword [plr_ammo_reserve+eax], ebx                ; 00434B63 _ 39. 98, 0047CEAC(d)
        jne     net_s2c_noop                                 ; 00434B69 _ 0F 85, 00000A83
        ; i'm actually not sure what this does. it sets some float to 0, but what?
?_05817:fldz                                            ; 00434B6F _ D9. EE
        fstp    dword [?_08992+eax]                     ; 00434B71 _ D9. 98, 0047CEC4(d)
        ; anyhow, we're done.
        jmp     net_s2c_noop                                 ; 00434B77 _ E9, 00000A76

        ; for players who aren't us...
        ; get player pointer + something i don't know the meaning of right now
?_05818:imul    eax, eax, 936                           ; 00434B7C _ 69. C0, 000003A8
        lea     edx, [?_08951+eax]                      ; 00434B82 _ 8D. 90, 0047CE1C(d)

        ; get gun pointer
        mov     eax, dword [plr_gun+eax]                ; 00434B88 _ 8B. 80, 0047CE5C(d)
        imul    eax, eax, 88                            ; 00434B8E _ 6B. C0, 58

        ; play gun's reload sound
        mov     ecx, dword [gun_wav_reload+eax]                ; 00434B91 _ 8B. 88, <a href="tel:00451778">00451778</a>(d)
        push    edx                                     ; 00434B97 _ 52
        push    ebx                                     ; 00434B98 _ 53
        push    ecx                                     ; 00434B99 _ 51
        call    ?_03247                                 ; 00434B9A _ E8, FFFE4F51
        add     esp, 12                                 ; 00434B9F _ 83. C4, 0C
        ; and we're done.
        jmp     net_s2c_noop                                 ; 00434BA2 _ E9, 00000A4B
Assembly code? Damn Greaser you've just made me feel 10x dumber than I already am. Don't even know what to do with that but thanks for sharing.
cow wrote:
Excuse the shameless advertising, but it's already been done on Stormwind's servers :)
Hmm? Might check that out and see if you've done what I've been attempting to do
thepolm3
Scripter
Scripter
Posts: 424
Joined: Sat Feb 16, 2013 10:49 pm


Here is the answer to all your problems:
(based on this)
Danko pasted this in #aloha a while ago (possibly originally showing it to you?) but in case anyone else wants it, http://paste.quacknet.org/view/e53282c7 ... 81c95da.py
  1. Put this script in your scripts file.
  2. Add "ammo" to your scripts in config.txt (put at the beginning)
  3. To access the ammo of a player from a script just do player.ammo[0]
  4. To access the clip of a player from a script just do player.ammo[1]
  5. To change a player's ammo from a script do player.set_ammo(ammo,clip)
The file contains three examples
  • /ammo which tells you your ammo
  • /reload <ammo> <clip> which sets your ammo and clip
  • /autoreload which sets you to auto reload whenever you stop shooting
Enjoy!
Blue_BigSmile
Attachments
ammo.py
(2.02 KiB) Downloaded 275 times
21 posts Page 2 of 2 First unread post
Return to “Help!”

Who is online

Users browsing this forum: No registered users and 3 guests