Here is the general idea, I'm trying to make a script that cycles through all the player's ammo types and stores the type and amount of ammo in a table to store in a database. As far as I can see, nothing like this has been done, and there is no Player:GetAllAmmo() function in GMod. Does anyone have a way to do this? All help/suggestions are appreciated!
Thanks!
You want something like this?
[lua]local function StorePlayerAmmo(ply)
local ret = {}
for _,v in ipairs(ply:GetWeapons()) do
table.insert(ret,{v:GetPrimaryAmmoType(),v:Clip1()})
end
return ret
end[/lua]
Returns a table of tables, where each subtable has a [1] of the PrimaryAmmoType and a [2] of the number of primary ammo.
Alternatively, you could do where the key is the ammotype and the value is the number of bullets, like so:
[lua]local function StorePlayerAmmo(ply)
local ret = {}
for _,v in ipairs(ply:GetWeapons()) do
ret[v:GetPrimaryAmmoType()] == v:Clip1()
end
return ret
end[/lua]
However, this would mean that if two guns had the same ammo type then it wouldn't register both of them, just the next one in the loop.
What would be the best way to store this in a sql lite database? I got stuck on that part, also the reading and setting of the ammo tables. Thanks!
I would recommend using glon to either store it in a database or write it to a file. You could also use util.KeyValuesToTable, but that wouldn't be nearly as efficient.
Sorry, you need to Log In to post a reply to this thread.