Jump to content

Drop weapon / remove weapon


onaid
 Share

Recommended Posts

hi all having a little trouble with removing / drop a weapon. basically i would like my player to walk through a trigger and have it remove the weapon so player no longer has the weapon if that makes sense.

 

i have tried attaching weapon pickup lua to a invisible box with a blank prefab but to no avail

 

 

https://drive.google.com/open?id=0BxWM6ILP8Pf9Ml8yX2NjdzQ3QUU

 

 

above is the project link test.rar

 

thank you in advance

post-9540-0-86482800-1463374503_thumb.png

Link to comment
Share on other sites

This is roughly how I do it.

C++
---------------------
// Place in Start() function for instance caching
Entity* leftHand = playerModel->FindChild("LeftHand_OrWhateverMyModelSays");
// Wielding
Model* leftHandItem = Model::Load("SomePath")
leftHandItem ->SetParent(leftHand);
// Unwielding
leftHandItem ->SetParent(NULL);
// DELETE if not using again!

Lua?
---------------
// Place in Start() function for instance caching
self.leftHand = playerModel:FindChild("LeftHand");
// Weidling
self.leftHandItem = Model:Load("SomePath");
self.leftHandItem:SetParent(self.leftHand)
// Unweild
self.leftHandItem:SetParent(NULL);
// DELETE if not using again!

 

Btw I think your map is missing some details.

 

It doesn't contain any player object.

 

Are you using the FPSPlayer.lua script for your player?

Link to comment
Share on other sites

Hi Marty j , thanks for your reply yep i am using the fpsplayer.lua script for player , so i pasted the script you gave me in the fps player.lua im not sure if i got it totaly right as i get this error

 

post-9540-0-29619500-1463439246_thumb.png

 

 

also there are no childen in the fps player model ? i s this what you mean when you say there is no player object ? so i cant choose to findchild lefthand

 

sorry pretty newb at script , thank you for your help

Link to comment
Share on other sites

If you look at the Script:AddWeapon() function, basically you've got to reverse what that does:

function Script:AddWeapon(weapon)
if weapon.index==nil then
	weapon.index=1
end
if self.weapons[weapon.index]==nil then
	self.weapons[weapon.index]=weapon
	self.weapons[weapon.index].player = self 
	self.weapons[weapon.index].entity:SetParent(self.weapontag)
	self.weapons[weapon.index].entity:SetPosition(self.weapons[weapon.index].offset)
	if self.weapons[weapon.index].rotation~=nil then
		self.weapons[weapon.index].entity:SetPosition(self.weapons[weapon.index].rotation)
	end
	self.weapons[weapon.index].entity:Hide()
	if weapon.index>self.currentweaponindex then self:SelectWeapon(weapon.index) end
	if self.sound.pickupweapon~=nil then self.sound.pickupweapon:Play() end
	return true
end
return false
end

  • Upvote 2

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...