• Pointshop ammo
    5 replies, posted
I have a TTT server with the latest version of pointshop. I cannot seem to get the ammo to work no matter how I configure it. I have searched and found nothing. Just a simple line of script would help. Thanks!
What have you tried so far? Can you show us what you have?
So far I have tried turning the weapons items so that it would spawn ammo instead of a gun [LUA]ITEM.Name = '357 ammo' ITEM.Price = 200 ITEM.Model = 'models/Items/357ammo.mdl' ITEM.WeaponClass = 'item_ammo_357' ITEM.SingleUse = true function ITEM:OnBuy(ply) ply:Give(self.WeaponClass) ply:SelectWeapon(self.WeaponClass) end function ITEM:OnSell(ply) ply:StripWeapon(self.WeaponClass) end[/LUA] Then it showed up under the category, but when I tried spawning it, it did nothing. I looked more and found a code that looked like this [lua] ITEM.Name = '357' ITEM.Price = 18 ITEM.Model = 'models/Items/357ammo.mdl' ITEM.SingleUse = true ITEM.NoPreview = false function ITEM:OnBuy(ply, tr) if (!tr.Hit) then return end local SpawnPos = tr.HitPos + tr.HitNormal * 16 local ent = ents.Create("item_ammo_357") ent:SetPos(SpawnPos) ent:Spawn() ent:Activate() self.Entity:SetMaterial("nordahl/n762mm.vmt") return ent end[/lua] But neither worked
Alright, almost right... I wouldn't spawn an entity, it'd be easier to give the player the ammo directly.. So, look in the item_ammo_357 folder / Lua and see which ammo it gives the player. Then you should just do Player:GiveAmmo( type, amount ) ( or reversed ) Don't use a trace to spawn ammo either, if you do it, at least only set it in front of the player buy using the eye position, the aim vector ( normal facing forward ) and doing eyepos + ( normal_vector * units ) : example of spawning stuff in front of player: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/spawn_entity_in_front_of_player_by_calc_size_of_object.lua.html[/url] ( I need to revise this ) You can loop through weapons by using Player:GetWeapons( ), Get the ammo type and give for each, or for whatever... So, use CanEquip in pointshop to scan the weapons, if the player doesn't have the weapon which uses that ammo, deny equipping ( prevent loss of ammo / currency is always a plus ) Example of an ammo dispenser for the primary ammo type of held-weapon: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/entities/ammo_dispenser_entity.lua.html[/url] List of HL2 weapons, Default ammo for the weapon, and Ammo Type ( list isn't 100% accurate, I think I need to finalize carry ammo and type ) [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/weapons/hl2_weapons_table.lua.html[/url]
Thanks! [editline]28th June 2014[/editline] [QUOTE=Acecool;45241263]Alright, almost right... I wouldn't spawn an entity, it'd be easier to give the player the ammo directly.. So, look in the item_ammo_357 folder / Lua and see which ammo it gives the player. Then you should just do Player:GiveAmmo( type, amount ) ( or reversed ) Don't use a trace to spawn ammo either, if you do it, at least only set it in front of the player buy using the eye position, the aim vector ( normal facing forward ) and doing eyepos + ( normal_vector * units ) : example of spawning stuff in front of player: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/spawn_entity_in_front_of_player_by_calc_size_of_object.lua.html[/url] ( I need to revise this ) You can loop through weapons by using Player:GetWeapons( ), Get the ammo type and give for each, or for whatever... So, use CanEquip in pointshop to scan the weapons, if the player doesn't have the weapon which uses that ammo, deny equipping ( prevent loss of ammo / currency is always a plus ) Example of an ammo dispenser for the primary ammo type of held-weapon: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/entities/ammo_dispenser_entity.lua.html[/url] List of HL2 weapons, Default ammo for the weapon, and Ammo Type ( list isn't 100% accurate, I think I need to finalize carry ammo and type ) [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/weapons/hl2_weapons_table.lua.html[/url][/QUOTE] Just tried it out ended up with this [lua] ITEM.Name = '357 ammo' ITEM.Price = 200 ITEM.Model = 'models/Items/357ammo.mdl' ITEM.WeaponClass = 'item_ammo_357' ITEM.SingleUse = true function ITEM:OnBuy(ply) Player:GiveAmmo("Pistol", 8) end [/lua] Also tried using ply instead of Player. Didn't work and got this lua error each time I tried to buy it. [lua] [ERROR] addons/pointshop-master/lua/items/ammo/357.lua:8: bad argument # 1 to 'GiveAmmo' (number expected, got string) 1. GiveAmmo - [C]:-1 2. OnBuy - addons/pointshop-master/lua/items/ammo/357.lua:8 3. PS_BuyItem - addons/pointshop-master/lua/sv_player_extension.lua:239 4. func - addons/pointshop-master/lua/sv_pointshop.lua:4 5. unknown - lua/includes/modules/net.lua:30 [/lua]
[QUOTE=Vorpalbunny;45241282]Thanks! [editline]28th June 2014[/editline] Just tried it out ended up with this [lua] ITEM.Name = '357 ammo' ITEM.Price = 200 ITEM.Model = 'models/Items/357ammo.mdl' ITEM.WeaponClass = 'item_ammo_357' ITEM.SingleUse = true function ITEM:OnBuy(ply) Player:GiveAmmo("Pistol", 8) end [/lua] Also tried using ply instead of Player. Didn't work and got this lua error each time I tried to buy it. [lua] [ERROR] addons/pointshop-master/lua/items/ammo/357.lua:8: bad argument # 1 to 'GiveAmmo' (number expected, got string) 1. GiveAmmo - [C]:-1 2. OnBuy - addons/pointshop-master/lua/items/ammo/357.lua:8 3. PS_BuyItem - addons/pointshop-master/lua/sv_player_extension.lua:239 4. func - addons/pointshop-master/lua/sv_pointshop.lua:4 5. unknown - lua/includes/modules/net.lua:30 [/lua][/QUOTE] replace [lua] Player:GiveAmmo("Pistol", 8) [/lua] with [lua] Player:GiveAmmo( 200, "Pistol", true ) [/lua]
Sorry, you need to Log In to post a reply to this thread.