• Active Weapon?
    4 replies, posted
[B]Hello FP.[/B] i want it to do so if you are holding a ak47 in your hand and type holster in console it's remove the ak47 and add it to my inventory addon, [B]but can't get the if to work.[/B] Code: [CODE] function TypeHolster( activator, caller ) if Player:GetActiveWeapon() == "weapon_mad_ak47" then // Add the item to the inventory activator:GiveItem("weapon_mad_ak47", 1); // Play Sound activator:EmitSound("items/ammocrate_open.wav"); // Remove Weapon From Player activator:StripWeapon("weapon_mad_ak47") end end concommand.Add("holster", TypeHolster) [/CODE] Error: [CODE] [lua\autorun\ia_holster.lua:4] attempt to index global 'Player' (a function value) [/CODE]
You can do this 1 of 2 ways: [lua] function TypeHolster( Player, caller ) if Player:GetActiveWeapon():GetClass() == "weapon_mad_ak47" then --I think its the class of the gun you want // Add the item to the inventory Player:GiveItem("weapon_mad_ak47", 1); // Play Sound Player:EmitSound("items/ammocrate_open.wav"); // Remove Weapon From Player Player:StripWeapon("weapon_mad_ak47") end end concommand.Add("holster", TypeHolster) [/lua] or This ones easier and more understanding imo [lua] function TypeHolster( activator, caller ) if activator:GetActiveWeapon():GetClass() == "weapon_mad_ak47" then -- same here with the class // Add the item to the inventory activator:GiveItem("weapon_mad_ak47", 1); // Play Sound activator:EmitSound("items/ammocrate_open.wav"); // Remove Weapon From Player activator:StripWeapon("weapon_mad_ak47") end end concommand.Add("holster", TypeHolster) [/lua]
[QUOTE=brandonj4;35813141]You can do this 1 of 2 ways: [lua] function TypeHolster( Player, caller ) if Player:GetActiveWeapon():GetClass() == "weapon_mad_ak47" then --I think its the class of the gun you want // Add the item to the inventory Player:GiveItem("weapon_mad_ak47", 1); // Play Sound Player:EmitSound("items/ammocrate_open.wav"); // Remove Weapon From Player Player:StripWeapon("weapon_mad_ak47") end end concommand.Add("holster", TypeHolster) [/lua] or This ones easier and more understanding imo [lua] function TypeHolster( activator, caller ) if activator:GetActiveWeapon():GetClass() == "weapon_mad_ak47" then -- same here with the class // Add the item to the inventory activator:GiveItem("weapon_mad_ak47", 1); // Play Sound activator:EmitSound("items/ammocrate_open.wav"); // Remove Weapon From Player activator:StripWeapon("weapon_mad_ak47") end end concommand.Add("holster", TypeHolster) [/lua][/QUOTE] [B]Thanks Working :)[/B]
No problem :) Do you understand what you were missing though?
[QUOTE=brandonj4;35822762]No problem :) Do you understand what you were missing though?[/QUOTE] yes and got it working with tabels too..
Sorry, you need to Log In to post a reply to this thread.