Jump to content

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






above is the project link test.rar


thank you in advance


Share this post

Link to post

This is roughly how I do it.

// 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!

// Place in Start() function for instance caching
self.leftHand = playerModel:FindChild("LeftHand");
// Weidling
self.leftHandItem = Model:Load("SomePath");
// Unweild
// 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





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







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






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









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
if self.weapons[weapon.index]==nil then
	self.weapons[weapon.index].player = self 
	if self.weapons[weapon.index].rotation~=nil then
	if weapon.index>self.currentweaponindex then self:SelectWeapon(weapon.index) end
	if self.sound.pickupweapon~=nil then self.sound.pickupweapon:Play() end
	return true
return false

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.






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.

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...