Hi!
I am Slasher and im new to the forums!
I want to make an small objective/mission map in gmod that the player has limited ammo, i've tried searching on google and in the forum
and I stumbled on this thread: [url]http://www.facepunch.com/threads/1098661-Help-with-creating-a-Maximum-ammo-pool[/url]
[code]
-- The ammo limit for each ammo type, you will have to find out the additional ones
-- The ones working are listed on [url]http://wiki.garrysmod.com/?title=Player.GiveAmmo[/url]
local AMMO_TYPES = {}
AMMO_TYPES["Pistol"] = 168
AMMO_TYPES["357"] = 18
AMMO_TYPES["SMG1"] = 270
AMMO_TYPES["SMG1_Grenade"] = 3
AMMO_TYPES["AR2"] = 90
AMMO_TYPES["AR2AltFire"] = 3
AMMO_TYPES["Buckshot"] = 36
AMMO_TYPES["XBowBolt"] = 11
AMMO_TYPES["RPG_Round"] = 2
AMMO_TYPES["Grenade"] = 4
-- You do not need to edit anything below this line, but if you know what you're doing, go right ahead.
local ITEM_CONV_TYPES = {}
ITEM_CONV_TYPES["Pistol"] = "weapon_pistol"
ITEM_CONV_TYPES["357"] = "weapon_357"
ITEM_CONV_TYPES["SMG1"] = "weapon_smg1"
ITEM_CONV_TYPES["AR2"] = "weapon_ar2"
ITEM_CONV_TYPES["Buckshot"] = "weapon_shotgun"
ITEM_CONV_TYPES["XBowBolt"] = "weapon_crossbow"
ITEM_CONV_TYPES["Grenade"] = "weapon_frag"
ITEM_CONV_TYPES["RPG_Round"] = "weapon_rpg"
hook.Add("Think", "LimitPlayerAmmo", function()
for _,pl in pairs(player.GetAll()) do
for k,v in pairs(AMMO_TYPES) do
local ammo = pl:GetAmmoCount(k)
local plus = 0
if ITEM_CONV_TYPES[k] then
if pl:HasWeapon(ITEM_CONV_TYPES[k]) then
plus = pl:GetWeapon(ITEM_CONV_TYPES[k]):Clip1()
end
end
if (ammo+plus) > v then
pl:RemoveAmmo((ammo+plus)-v, k)
end
end
end
end)[/code]
This script is limiting my maximum ammo but whenever I already reached the max ammo count my character still picks up ammo... (although it doesn't adds up, which is a good thing)
Could someone help me with improving this script or make a new one that doesn't pick more ammo than needed and leave extra ammo on the ground untouched? (Just like in Half life 2!)
A reply is always welcome even if you don't have the solution! =)
I would be very gratefull!
Switch the k and v around in your comparing for ammo types.
thanks for the reply!
in which line or lines?
this one? pl:RemoveAmmo((ammo+plus)-v, k)
sorry I am a dummy in LUA scripting! :S
k is the number of the index, v is the value it holds.
Example:
[lua]
local table = {
["index"] = "Something",
["other_index"] = "Same."
};
for k, v in pairs(table) do
print(k, v);
end;
[/lua]
Would outcome:
> 1 Something
> 2 Same
Just a heads up for next time.
This is the Lua section, dont add [LUA] tag to your title, icons are there for that.
Also, do not say (Gmod11), Gmod9 is old and unsupported here so we only talk about the new gmod, if you want to get technical we are on around Gmod128.
Another thing, use the sub forums: Questions are for questions only and Requests are for things that you want us to make for you. Dont expect to get what you want every time.
@Science nice to meet you too! but I was wrong :S sorry did'nt knew that... it wasn't in the rules i've read :(
I don't want to get all profit for my self, I think a lot of other people have this kind of problem and it would be a good addition to other people if it gets fixed...
Needs this topic to be closed now? so I will post this in the sub-forum?
Don't bother asking for it be locked, snip the op out and let it die.
Also, I recommend you delete that script from your pc followed by burning your harddrive.
That script is so laggy and unoptimised it will not be worth your time.
Just ask someone to make you a new script.
Sorry, you need to Log In to post a reply to this thread.