Jump to content
onaid

Drop weapon / remove weapon

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

Share this post


Link to post

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?

Share this post


Link to post

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

Share this post


Link to post

The error is caused by using c++ style comments // in Lua. Replace those // with --.

Regarding the player object. It's the object you attached the script to.

Share this post


Link to post

thanks Roland now i get this

 

 

post-9540-0-64431500-1463440541_thumb.png

 

 

 

not sure if this helps but this is what i had in my head was to change the FPSplayer.lua so i could enable / disable weapon

 

 

post-9540-0-70005800-1463440634_thumb.png

 

 

again sorry newb at script

Share this post


Link to post

The player model is the entity the script is attached to, so it would be self.entity:FindChild. I'm at my phone now so I can't give any more detailed help.

Share this post


Link to post

thanks for your help Roland but im not sure where to change the script would

 

self.entity:FindChild

replace

 

playerModel:FindChild

 

?

 

also the FPSplayer model has no children in the scene tab ?

Share this post


Link to post

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

Share this post


Link to post

sorry guys just total newb when it comes to script super keen to learn just need some help here

Share this post


Link to post

ok guys all thanks for your help , big thanks to the living legend Paul Thomas who totally got this sorted, mate you are a bloody champion.

 

here is script for fps player.lua if you want to do the same.

 

http://pastebin.com/D12H7Qbi

 

post-9540-0-00747000-1464933698.png

 

Paul Thomas living legend

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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.

×
×
  • Create New...