• Print

Author Topic: Need help with coding!  (Read 4638 times)

0 Members and 1 Guest are viewing this topic.

Offline Rain

  • Newbie
  • *
  • Posts: 16
  • Karma: 0
Need help with coding!
« on: July 05, 2015, 08:44:26 am »
So I'm not very good at this and I've searched all over!

I'm wanting a prop to auto spawn on players backs ( for my zombie server )

I tried making the prop into an entity and got these errors-

It will spawn, but it is invisible and nothing can be done to it then this error shows in console~

[ERROR]

[ERROR] addons/backpack/lua/entities/ent_backpack/init.lua:6: attempt to index global 'self' (a nil value)
  1. unknown - addons/backpack/lua/entities/ent_backpack/init.lua:6
   2. Spawn - [C]:-1
    3. SpawnFunction - gamemodes/base/entities/entities/base_entity/init.lua:77
     4. Spawn_SENT - gamemodes/sandbox/gamemode/commands.lua:609
      5. unknown - gamemodes/sandbox/gamemode/commands.lua:674
       6. unknown - lua/includes/modules/concommand.lua:54


[MY SCRIPT]
[INIT.LUA FILE]

AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include( "shared.lua" )

function ENT:Initialize()

    self:SetModel( "models/fallout3/campish_pack.mdl" )
   self:PhysycsInit( SOLID_VPHYSICS )
   self:SetMoveType( MOVETYPE_VPHYSICS )
   self:SetSolid( SOLID_VPHYSICS )
   self:SetUseType( SIMPLE_USE )
   Self:DrawShadow( false )

end

function ENT:Think()
local owner=self:GetOwner()
if owner==NULL then return end
local bone=owner:LookupBone("ValveBiped.Bip01_Spine")
if(bone)then
local position,angles=owner:GetBonePosition(bone)
angles:RotateAroundAxis(angles:Forward(),0)
angles:RotateAroundAxis(angles:Right(),-90)
angles:RotateAroundAxis(angles:Up(),0)
self.Entity:SetPos(position+(angles:Up()*-7)+(angles:Forward()*8))
self.Entity:SetAngles(angles)
end
end

I NEED URGENT HELP PLEASE :(!
« Last Edit: July 05, 2015, 08:46:17 am by Rain »

Offline Caustic Soda-Senpai

  • Sr. Member
  • ****
  • Posts: 469
  • Karma: 54
  • <Insert something clever here>
    • Steam Page
Re: Need help with coding!
« Reply #1 on: July 05, 2015, 10:19:38 am »
Code: Lua
  1. AddCSLuaFile( "cl_init.lua" )
  2. AddCSLuaFile( "shared.lua" )
  3. include( "shared.lua" )
  4.  
  5. function ENT:Initialize()
  6.  
  7.     self:SetModel( "models/fallout3/campish_pack.mdl" )
  8.    self:PhysycsInit( SOLID_VPHYSICS )
  9.    self:SetMoveType( MOVETYPE_VPHYSICS )
  10.    self:SetSolid( SOLID_VPHYSICS )
  11.    self:SetUseType( SIMPLE_USE )
  12.    Self:DrawShadow( false )
  13.  
  14. end
  15.  
  16. function ENT:Think()
  17. local owner=self:GetOwner()
  18. if owner==NULL then return end
  19. local bone=owner:LookupBone("ValveBiped.Bip01_Spine")
  20. if(bone)then
  21. local position,angles=owner:GetBonePosition(bone)
  22. angles:RotateAroundAxis(angles:Forward(),0)
  23. angles:RotateAroundAxis(angles:Right(),-90)
  24. angles:RotateAroundAxis(angles:Up(),0)
  25. self.Entity:SetPos(position+(angles:Up()*-7)+(angles:Forward()*8))
  26. self.Entity:SetAngles(angles)
  27. end
  28. end

Note Line 6 (As it says in the error log). Line 6 is a blank line which means something after it is something it doesn't like. Looking through it, I noticed the final "self" is capitalized. I'm not sure if changing that will solve the problem on its own but give it a shot.
Once you get to know me, you'll find you'll have never met me at all.

Offline Rain

  • Newbie
  • *
  • Posts: 16
  • Karma: 0
Re: Need help with coding!
« Reply #2 on: July 05, 2015, 10:51:01 am »
ok so fixed a few spelling mistakes, NO ERRORS ANYMORE! but it doesn't want to spawn on me :(

Offline Rain

  • Newbie
  • *
  • Posts: 16
  • Karma: 0
Re: Need help with coding!
« Reply #3 on: July 05, 2015, 11:02:22 am »
so all it needs to do now is spawn onto me when I spawn it XD

Offline Rain

  • Newbie
  • *
  • Posts: 16
  • Karma: 0
Re: Need help with coding!
« Reply #4 on: July 07, 2015, 04:15:43 am »
anyone know :(?

  • Print