Basically, if you have no weapons of the class you are buying, you'll receive your weapon just fine. However, say if you have an M16 and you wanna buy an AK47 from the PointShop, you don't get your weapon at all. I've created this code with the help of someone who knows Lua in hopes it would check if they had a weapon of the class they are buying, if they do, strip it from then and issue the weapon they bought.
This is my code: [url]http://pastebin.com/a8p0GzQw[/url]
How do I get this to work?
The best way I've found to do this is to not use tables.
Simply make a list of your primaries and put this in ITEM:OnBuy
[CODE]function ITEM:OnBuy(ply)
if ply:HasWeapon( "Whatever" ) then
ply:StripWeapon( "Whatever" )
elseif
ply:HasWeapon( "Whatever" ) then
-- And so on and so on
end
ply:Give(self.WeaponClass)
ply:SelectWeapon(self.WeaponClass)
--ply:SetAmmo( 90, "SMG1" )
end
[/CODE]
Delete the "--" part if you want to give them max ammo upon purchase (Assuming the AK has 45 bullets per mag)
But anyways.
Your names are wrong.
It's not "ttt_weapon_m16" it's "weapon_ttt_m16" etc.
I am quite sure you cannot do
[code]
if primaries:HasValue(v) then
[/code]
on a table value. Similar "hacks" only work on string values, because their metatable is patched to support this kind of behavior.
Replace it with:
[code]
table.HasValue(primaries, v)
-- Or even better, use a hash lookup:
local lookup = {
["weapon_a"] = true,
["weapon_b"] = true,
-- and so on..
}
if lookup[v] then
-- ...
[/code]
[QUOTE=MDave;45803680]I am quite sure you cannot do
[code]
if primaries:HasValue(v) then
[/code]
on a table value. Similar "hacks" only work on string values, because their metatable is patched to support this kind of behavior.
Replace it with:
[code]
table.HasValue(primaries, v)
-- Or even better, use a hash lookup:
local lookup = {
["weapon_a"] = true,
["weapon_b"] = true,
-- and so on..
}
if lookup[v] then
-- ...
[/code][/QUOTE]
This has been sitting around my hard drive for a while now, might be of some use:
[url]http://pastebin.com/gcJ1MQpY[/url]
It's needs to run table.new to initialize tables though, not sure if you can somehow 'hijack' table creation without using C++
[QUOTE=JasonMan34;45803671]The best way I've found to do this is to not use tables.
Simply make a list of your primaries and put this in ITEM:OnBuy
[CODE]function ITEM:OnBuy(ply)
if ply:HasWeapon( "Whatever" ) then
ply:StripWeapon( "Whatever" )
elseif
ply:HasWeapon( "Whatever" ) then
-- And so on and so on
end
ply:Give(self.WeaponClass)
ply:SelectWeapon(self.WeaponClass)
--ply:SetAmmo( 90, "SMG1" )
end
[/CODE]
Delete the "--" part if you want to give them max ammo upon purchase (Assuming the AK has 45 bullets per mag)
But anyways.
Your names are wrong.
It's not "ttt_weapon_m16" it's "weapon_ttt_m16" etc.[/QUOTE]
Looks good, I understand it.
One thing though, wouldn't be easier to run a check if they have a weapon in slot 3 (the primary weapon slot), strip it if there is a value, and then issue the weapon?
[QUOTE=Pjor1;45808407]Looks good, I understand it.
One thing though, wouldn't be easier to run a check if they have a weapon in slot 3 (the primary weapon slot), strip it if there is a value, and then issue the weapon?[/QUOTE]
Sure, it's easier.
But is it simpler?
[QUOTE=JasonMan34;45808447]Sure, it's easier.
But is it simpler?[/QUOTE]
Seems like it would be to me... it'd sure be more simpler then listing everything that goes in slot 3, lol.
UPDATE: Your code didn't work, lol. :(
[QUOTE=Pjor1;45808485]Seems like it would be to me... it'd sure be more simpler then listing everything that goes in slot 3, lol.
UPDATE: Your code didn't work, lol. :([/QUOTE]
Post your new code
[QUOTE=JasonMan34;45808922]Post your new code[/QUOTE]
I was using yours.
[QUOTE=Pjor1;45810005]I was using yours.[/QUOTE]
......................
The whole code
[QUOTE=JasonMan34;45810204]......................
The whole code[/QUOTE]
[url]http://pastebin.com/SvxRUYNr[/url]
UPDATE: I noticed the Famas had a double parentheses, nonetheless the M16 didn't work either.
What doesn't work? Is the weapon stripped?
[QUOTE=code_gs;45811876]What doesn't work? Is the weapon stripped?[/QUOTE]
For instance:
- No weapon in slot 3
- I can buy a slot 3 weapon (i.e. AK47) and have it issued to me
- M16 in slot 3
- I can buy a slot 3 weapon (i.e. AK47) and it won't be issued, I'll have my M16
I have a way to do this but it takes a bit of customizing to get it to work, ill msg you about it if nobody thinks of a simpler solution.
Can you put a print after the StripWeapon and tell me if it ever prints? I have a feeling the if statement isn't passing.
You can easily go through the player weapons... If the user has a weapon with the same GetTable( ).Slot as the purchased weapon, Drop the current one then equip the new one.
We got it coded.
Sorry, you need to Log In to post a reply to this thread.