Jump to content

Script Pickup weapon (LUA)


Leon
 Share

Recommended Posts

Hi I'm following Ricky Weapon pickup tutorial

https://www.youtube.com/watch?v=VWBGtJ7NQ4Y

 

but after I attached the script to my weapon I have an error on line 30

that says

 

 

Script.entered = false

Script.exited = false

Script.hadCollision = false

 

Script.vModel = "" --path

 

function Script:UpdatePhysics()

if self.entered then

if self.hadCollision == false then

if self.exited == false then

self.exited = true

self.component:CallOutputs("TriggerExit")

self.entered = false

end

end

end

 

self.hadCollision = false

end

 

function Script:Collision(entity, position, normal, speed)

self.hadCollision = true

 

self.component:CallOutputs("OnCollide")

 

if self.entered == false then

self.component:CallOutputs("TriggerEnter")

if entity:GetKeyValue("type") == "player" then

entity.script.weaponfile = self.vModel

entity.script:Loadweapon()

self.entity:Hide()

end

 

self.entered = true

self.exited = false

end

end

 

 

 

 

 

2u76dja.jpg

Link to comment
Share on other sites

Can you show us your LoadWeapon() function, and what script do you have the LoadWeapon() function in. Want to make sure you have function Script:LoadWeapon() and not just function LoadWeapon(). Those 2 are at different scopes and could cause this error also.

Link to comment
Share on other sites

I dont have any loadweapon script--

 

In your tutorial I didnt see any loadweapon script

 

if you are referring to fpsplayer script that contain the weaponscript...i didnt touch anything..

 

 

this...

 

--Load the default weapon, if one is set

if self.weaponfile~="" then

local entity = Prefab:Load(self.weaponfile)

if entity~=nil then

if entity.script~=nil then

entity.script.player = self

self.weapon = entity.script

self.weapon.entity:SetParent(self.camera)

self.weapon.entity:SetRotation(0,0,0)

if self.weapon.offset~=nil then

self.weapon.entity:SetPosition(self.weapon.offset)

else

self.weapon.entity:SetPosition(0,0,0)

end

end

end

end

Link to comment
Share on other sites

I dont have any loadweapon script--

 

And that right there is your problem, you need to create a LoadWeapon function. You can't call what doesn't exist, ergo you get "nil" value errors. View the tutorial video again and you will see what is changed and where the LoadWeapon function is created.

Link to comment
Share on other sites

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