English Ho do i make an inf ammo? (W/o reloading)

11 replies
Goto Page
To the start Previous 1 Next To the start
Up
UrNightmare
User
Offline Off
As the title said, i want to make a gun with inf ammo (w/o reloading). I hope you guys can help me out
[ String+ ] make string library more extended and advanced!
22.01.22 11:21:54 am
Up
Bowlinghead
User
Offline Off
With reloading:
Code:
1
parse("mp_infammo 1");
cs2d cmd mp_infammo



Without reloading:
Code:
1
2
3
4
5
6
7
8
--untested
addhook("attack","atk")
function atk(id)

local itemType = player(id,"weapontype");
parse("setammo "..id.." "..itemType.." 999 999");

end
cs2d cmd setammo
Share time limited free games here
22.01.22 04:19:00 pm
Up
SQ
Moderator
Offline Off
@user Bowlinghead: Parsing on every attack is rather expensive.

You can hide ammo with cs2d cmd mp_hud
Set ammo only when it is less than 1
22.01.22 06:01:40 pm
Up
Bowlinghead
User
Offline Off
Without reloading v2:
Code:
1
2
3
4
5
6
7
8
9
10
11
--untested
addhook("attack","atk")
function atk(id)

   local itemType = player(id,"weapontype");

   if (playerammo(id,itemType) <= 1) then -- if ammo amount (ammoin) is less than 2
      parse("setammo "..id.." "..itemType.." 999 999"); -- fill up ammo&ammoin
   end

end
cs2d cmd setammo , cs2d lua cmd playerammo , cs2d lua cmd player


Thanks, @user SQ!
Share time limited free games here
23.01.22 01:08:07 pm
Up
Gaios
Security Supporter
Offline Off
@user Bowlinghead: I would set it higher, because of lags, eg.
<= 10
23.01.22 03:39:47 pm
Up
Masea
Super User
Offline Off
@user Gaios: That would make it more frequent though. Even Deagle would always call it.
Shit your pants: file cs2d Outlast II Mod (29) | Create your UI faster: CS2D UI Framework
25.01.22 02:43:39 pm
Up
MikuAuahDark
User
Offline Off
What about 1/3 of the max ammo of such weapon rounded down? I don't quite know if the max ammo can be retrieved through Lua though (and you need to handle special case if it's 0).
file cs2d LuaJIT for Dedicated Server (13) JIT POWER! | Know your Lua errors! | Part of LÖVE development team since 11.3
25.01.22 05:29:35 pm
Up
Bowlinghead
User
Offline Off
Without reloading v3:
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
--untested
refillCap = 0.33 -- Reload ammo on 33% of its maximum capacity

addhook("attack","atk")
function atk(id)

     local itemType = player(id,"weapontype");
     AmmoRefill(playerammo(id,itemType), itemType);
end

addhook("collect", "garbage")
function garbage(id,iid,itype, ain)
     AmmoRefill(ain,itype)

end


function AmmoRefill(ammoIn, itemType)
     if (ammoIn <= itemtype(itemType,"ammoin") * refillCap) then
          parse("setammo "..id.." "..itemType.." 999 999"); -- fill up ammo&ammoin
     end 
     return false;
end
cs2d cmd setammo , cs2d lua cmd playerammo , cs2d lua cmd player , cs2d lua cmd itemtype

Lets make it ping dependent
Share time limited free games here
27.01.22 07:15:18 am
Up
UrNightmare
User
Offline Off
@user Bowlinghead: Can i make so its only affect on certain weapon (like making a table for the weapon id/name and then make an "if" statment for the weapon table)
[ String+ ] make string library more extended and advanced!
27.01.22 05:17:04 pm
Up
Bowlinghead
User
Offline Off
@user UrNightmare: Yes, you can.

For example, you create a table and a for-loop to iterate through the table.

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
myGunzWithInfAmmo = {
45,
3,
2
};


addhook("attack","atk")
function atk(id)

     local itemType = player(id,"weapontype");

     for _,v in ipairs(myGunzWithInfAmmo) do
          if (v == itemType) {
               AmmoRefill(playerammo(id,itemType), itemType);
               return;
           end
      end
end


Note the return in line 16: Once you found your weapon, you can stop searching.

Depending on the amount of weapons you need with infinite ammo, you maybe want to "invert" the table (=> make a table 'myGunzWithoutInfAmmo'), so you dont need to go over too much weapons
Share time limited free games here
27.01.22 06:09:14 pm
Up
Mami Tomoe
User
Offline Off
I have created this file: file cs2d [MT] No Reload Module (2) in response to all of your attempts.
Enjoy
Look at me standing, here on my own again
28.01.22 10:16:28 am
Up
UrNightmare
User
Offline Off
@user Mami Tomoe: Thanks! I don't have to write a code for my zombie mod that i'll make soon if i have some free time. Thanks again
[ String+ ] make string library more extended and advanced!
To the start Previous 1 Next To the start