Jump to content

Kill, Spawn, Update


Rick
 Share

Recommended Posts

Trying to figure out why this crashes on me when I go out of game mode. It has to do with the Kill() event. If I comment out the code in the Kill() event it works fine, BUT then I get multiple cubes being created every time I run the game.

 

function Spawn(model)
local entity=base_Spawn(model)
entity.model=model

entity.cameraPivot = CreatePivot()
entity.playerPivot = CreatePivot()
entity.playerPivotCube = CreateCube()

-- make the player pivot the camera pivots parent so it moves with the player pivot
EntityParent(entity.cameraPivot, entity.playerPivot)
return entity
end

function Kill(model)
local entity=base_Spawn(model)

FreeEntity(entity.playerPivotCube)
end

Link to comment
Share on other sites

Why are you running spawn in your Kill? You should call base_Kill(model) but call it AFTER you do your other stuff. As an alternative, you could do:

 

function Kill(model)
       entity.playerPivotCube:SetParent(model)
       base_Kill(model)
end

 

This should cause the playerPivotCube to get destroyed along with it's parent. I haven't tested this though, so it could result in bad things like your dog getting sick on your carpet or something.

Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX

ZBrush - Blender

Link to comment
Share on other sites

Still having some issues here. I only want to free the cube and the pivots created in the spawn. I look at the monster truck for an example but when I kind of do the same thing it errors.

 

function Kill(model)
local entity
entity=entitytable[model]

FreeEntity(entity.playerPivotCube)
FreeEntity(entity.playerPivot)
FreeEntity(entity.cameraPivot)
end

 

It says local entity is a nil value

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