So well i was First triying to limit the player weapons to 3 so later he can change any of those 3 weapons for one of his like
but I have never work on player inventory stuff and yes i alredy readed the lua wiki to see if i could find someting and all that i founded was pl:stripweapons and that only works to delete all the player equipied weapons
so well any hints or at least any sort of info is very appreciated
[lua]
function GM:PlayerInitialSpawn( ply )
ply.numofweapons = 0
function GM:PlayerCanPickupWeapon(ply, weapon)
for k, v in pairs(ply:GetWeapons()) do
ply.numofweapons = ply.numofweapons + 1
end
if numofweapons > 3 then
ply:PrintMessage( HUD_PRINTCENTER, "YOU HAVE TOO MANY WEAPONS(more than 3)" )
return false
else
return true
end
end
[/lua]
I'm not sure if this will drop the weapon he just picked up, or the weapon he was holding before he picked it up, if it drops the weapon he just picked up, can someone tell me a hook that is called when a player picks up a weapons but its not in the inventory yet? Or maybe a workaround, I would like something similar to this too
EDIT:
Users browsing this thread: Andriko1 TheRealc-unit
*sniff* he really cares :_)
[QUOTE=Andriko1;28413501][lua]
ply.numofweapons = 0
function GM:WeaponEquip(weapon)
timer.Simple(0, function() -- wait a frame
local ply = weapon:GetOwner() -- no longer a null entity.
ply.numofweapons = 0
for k, v in pairs(ply:GetWeapons()) do
ply.numofweapons = ply.numofweapons + 1
end
if ply.numofweapons > 3 then
ply:DropWeapon(ply:GetActiveWeapon())
ply:PrintMessage( HUD_PRINTCENTER, "YOU HAVE TOO MANY WEAPONS(more than 3)" )
ply.numofweapons = ply.numofweapons - 1
end
end) -- end the timer
end
[/lua]
I'm not sure if this will drop the weapon he just picked up, or the weapon he was holding before he picked it up, if it drops the weapon he just picked up, can someone tell me a hook that is called when a player picks up a weapons but its not in the inventory yet? Or maybe a workaround, I would like something similar to this too
EDIT:
Users browsing this thread: Andriko1 TheRealc-unit
*sniff* he really cares :_)[/QUOTE]
Boxes.
Also:
[b][url=wiki.garrysmod.com/?title=Gamemode.PlayerCanPickupWeapon]Gamemode.PlayerCanPickupWeapon [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
-snip- facepunch lagging today...
-snip- facepunch lagging today...
[QUOTE=Wizard of Ass;28413734]Boxes.
Also:
[b][url=wiki.garrysmod.com/?title=Gamemode.PlayerCanPickupWeapon]Gamemode.PlayerCanPickupWeapon [img_thumb]http://wiki.garrysmod.com/favicon.ico[/img_thumb][/url][/b][/QUOTE]
why did you rate me dumb :(, and what do you mean by Boxes
EDIT: I changed it to GM:PlayerCanPickupWeapon() is it good now?
[QUOTE=Andriko1;28414012]why did you rate me dumb :(, and what do you mean by Boxes[/QUOTE]
More Boxes.
He means your code/post is dumb.
Why would you set index on the players table when it only needs a variable local to the function?
[QUOTE=zzaacckk;28415565]More Boxes.
He means your code/post is dumb.
Why would you set index on the players table when it only needs a variable local to the function?[/QUOTE]
The dumb rating isn't for saying something is wrong with your code, that's what feedback is called...
BTW you have 666 posts, that and Justin Bieber avatar looks funny lol
Please, leave already, 90% of your posts are wrong or dumb.
[editline]4th March 2011[/editline]
Also Boxes = [img]http://cdn.fpcontent.net/fp/ratings/box.png[/img][img]http://cdn.fpcontent.net/fp/ratings/box.png[/img]
tried to use andriko code and i couldent even equip a weapon
[QUOTE=werewolf0020;28423751]tried to use andriko code and i couldent even equip a weapon[/QUOTE]
Already established his code is fail.
oh nvm then
[QUOTE=Derek_SM;28424446]Already established his code is fail.[/QUOTE]
Compared to yours it's pretty good.
[lua]
local SafeGuns = {"weapon_physcannon","weapon_physgun","gmod_tool"}
function GM:PlayerCanPickupWeapon(pl,wep)
local weaponCount = pl.WeaponCount or 0
if table.HasValue(SafeGuns,wep:GetClass()) then return true end
if weaponCount > 2 then return false end
pl.WeaponCount = weaponCount + 1
return true
end
[/lua]
Try this.
man your always very helpfull! that worked pretty well but since Then how would i go to change the player equipied weapons? unless i can take out a weapon of my choice so i can freely make him unequip a weapon to equip another
okay now i only need a small advice of how to let the player Unequip his weapons i alredy got the equip part sorted out
well im using now concommand.Add("pointshop_unequipitem", function(ply, cmd, args)
local item_id = args[1]
if not item_id then return end
if not ply:PS_HasItem(item_id) then return end
ply:PS_UnequipItem(item_id, true)
ply:StripWeapon("item_id")
end)
with
function Player:PS_UnequipItem(item_id)
if self:PS_HasItem(item_id) then
for id, name in pairs(self.PS_Items) do
if name == item_id then
MsgN("Removing ", id, " from table")
end
end
self:PS_UpdateItems()
local item = POINTSHOP.FindItemByID(item_id)
if not item then return end
if item.Functions and item.Functions.OnTake then
item.Functions.OnTake(self, item)
end
end
return false
end
sorry for lack of lua tags but the problem is that it still isnt working but i got no errors at all! or is there any oter way to unequip a specific weapon/item from the player?
Sorry, you need to Log In to post a reply to this thread.