Jump to content

Gamecrash; due to kill or respawn script changes something...


Kenneth Nyström
 Share

Recommended Posts

Gamecrash; due to kill/respawn script changes/removes??? a value that is used within the default "TriggerChangeMap.Lua" script

My suspiscion atm...have had like 20 other ideas before:what it might be (not working);
Is that the respawn script is missing something (but My skill isnt yet up to that level yet so i can see what is missing. If that is the case. (yes im suspecting there is missing an "if" statement but not sure) (I have gotten to the point I cant keep track of all my ideas flying around what it might be)
= time to ask:
---------------------------------------------------------------------------------------
Description:
Before dying the game and its Changemap scripts work just fine:
But after dying once:
Game just hangs it self when entering the TriggerChangeMap script...

::::::::::::::::::::::::::::::::::::::::::Player.Lua "script":::::::::::::::::::::::::::::::::::::::::::::::::

function Script:Kill()
    self.corpse = Pivot:Create()
    
    self.alive = false

    local shape = Shape:Load("Models/Characters/Generic/corpse.phy")

    self.corpse:SetShape(shape)
    if shape~=nil then shape:Release() end
    self.flashlight:Hide()
    if self.weapons[self.currentweaponindex]~=nil then
        self.weapons[self.currentweaponindex]:Hide()
    end
    self.corpse:SetMass(5)
    self.corpse:SetMatrix(self.camera:GetMatrix())
    self.camera:SetParent(self.corpse)
    self.camera:SetPosition(0,0,0)
    self.camera:SetRotation(0,0,0)
    self.corpse:SetCollisionType(Collision.Prop)
    self.corpse:SetSweptCollisionMode(true)
    self.entity:SetCollisionType(0)
    self.corpse:SetFriction(10,10)
    local maxomega=5
    self.corpse:SetOmega(Vec3(math.random(-maxomega,maxomega),math.random(-maxomega,maxomega),math.random(-maxomega,maxomega)))
    local v = self.entity:GetVelocity()
    if v:Length()>1 then
        v=v:Normalize()
    end
    self.corpse:SetVelocity(Vec3(math.random(-1,1),math.random(-1,1),math.random(-1,1)))
    self.entity:SetMass(0)
    self.entity:SetPhysicsMode(Entity.RigidBodyPhysics)
end



function Script:Respawn()
    
    self.alive = true
    self.health = self.maxHealth
    self.entity:SetMass(self.originalMass)

    self.entity:SetCollisionType(Collision.Character)
    self.entity:SetPhysicsMode(Entity.CharacterPhysics)
    self.entity:SetPosition(self.checkpointMgr.script:GetCheckpointPosition())

    self.camera:SetParent(nil)

    self.corpse:Release()
end
 

::::::::::::::::::::::::::default "TriggerChangeMap.Lua" script::::::::::::::::::::::::::::::::::::::::::

function Script:Start()

    self.enabled=true
end

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

    changemapname=self.mapname
end

function Script:Enable()--in
    if self.enabled==false then
        self.enabled=true
        self:CallOutputs("Enable")
    end
end

function Script:Disable()--in
    if self.enabled then
        self.enabled=false
        self:CallOutputs("Disable")
    end
end

Link to comment
Share on other sites

 

29 minutes ago, havenphillip said:

I think the line

self.entity:SetMass(0)

was causing crash problems. Maybe uncomment that.

Hmm I tried it -- and several alternatives to SetMass thruout the kill/respawn part of the script.
still same result in the game crashing.

Only wierd i can see is that the Output says.

"process complete"

Without having reached the loading bit of the ChangeMap script it usully does...

Hmm.

I perhaps I need find a "never" version of the respawn  bit in the script (using lesson 27 of the LW tutorial) and it has worked great until now when it messes with the changemap script...

Hmm.

Anyone can point me in a direction for an alternative place/tutorial  for a wiew into a diffrent version of a respawn script?

Link to comment
Share on other sites

What I ended up doing with  my game was removing all the code that says what happens if the player dies. Then inserted my own code that says; teleport to respawn location, reset health, reset stamina, reset thirst, reset hunger, empty inventory.

Using this method the player technically doesn't die but it simulates death. Then all you have to do is for your enemies is add code that makes thier target nil and tells them to search for new target.

But as for your code the only thing I can suggest is set up a trigger value and then breadcrumb. So for example add something like;

Script.trigger = 0

Then in your update world add;

if self.health <= 0 then

self.trigger = 1

end

if self.health > 0 then

self.trigger = 0

end

if self.trigger == 1 then

--Add the code here that triggers or references the change map.

end

Link to comment
Share on other sites

On 10/23/2018 at 4:55 AM, Wafflesoft said:

What I ended up doing with  my game was removing all the code that says what happens if the player dies. Then inserted my own code that says; teleport to respawn location, reset health, reset stamina, reset thirst, reset hunger, empty inventory.

Using this method the player technically doesn't die but it simulates death. Then all you have to do is for your enemies is add code that makes thier target nil and tells them to search for new target.

But as for your code the only thing I can suggest is set up a trigger value and then breadcrumb. So for example add something like;

Script.trigger = 0

Then in your update world add;

if self.health <= 0 then

self.trigger = 1

end

if self.health > 0 then

self.trigger = 0

end

if self.trigger == 1 then

--Add the code here that triggers or references the change map.

end

 

On 10/23/2018 at 4:15 AM, Gonan said:

http://www.leadwerks.com/werkspace/topic/11065-monsterailua-function-scriptendattack-bug-fix/

This problem occurs when more than one monster is attacking you. Not sure if it was ever fixed.

 

Both; Thank you for your inputs. and yeah I thought the same way with working around the problem (acctully a very good thing); taught me alot of useful "stuff" while dealing with the LUA code.

I really only have one last issue with the coding I will soon dive into:

Hmm I could just ask you guys (without starting yet one more thread):

making the code for saving, 
map/position/rotation/tables
is there a good place to begin lookin @?
(didnt find the info in the "index" (could be there; this is just me just getting to that stage of/in the programming)


 

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