Jump to content

Medkits no longer work and physics may be broken


Recommended Posts

When you bring a medkit into Leadwerks as of the new beta, they float into the air when running the game.  Attaching this script makes Leadwerks crash to windows when trying to use the Medkit.

Script.health = 15.0 --float "Health"
Script.useOnce = true --bool "Use once"
Script.ReleaseTimer=0
Script.ReleaseDelay=5000--float "Corpse Time"

function Script:Start()
    if self.health < 0 then
        error("Health can't be a negative value.")
    end
end

function Script:UpdatePhysics()
    if self.ReleaseTimer ~= 0 and self.ReleaseTimer < Time:GetCurrent() then
       self.entity:Release()
    end
end

function Script:Use(player)
    if player.script.health < player.script.maxHealth then
        player.script:ReceiveHealth(self.health)
        if self.useOnce then
            self.entity:Hide()
            self.ReleaseTimer = Time:GetCurrent() + self.ReleaseDelay
        end
    end
end

This worked 100% in the stable version of Leadwerks 4.6.

Mike

MSI Dominator Laptop - Core i7 - 8 cores / 3ghz / 32gb RAM / Nvidia 980 GTX with 16gb vram / SSD drives

MSI Dominator Laptop - Core i7 - 8 cores / 3ghz / 32gb RAM / Nvidia 1060 GTX with 8gb vram / SSD drives

Alienware Laptop - Core i7 - 8 cores / 3ghz / 32gb RAM / Nvidia 1070 Ti with 16gb vram / SSD drives

My Patreon page: https://www.patreon.com/michaelfelkercomposer

My music for sale: https://www.tgcstore.net/category/513?format=all&amp;perpage=30&amp;textures=undefined&amp;price=all&amp;order=default&amp;artists[]=87213

Custom synths and sounds - http://www.supersynths.com

Link to comment
Share on other sites

I think I downloaded them from the workshop

MSI Dominator Laptop - Core i7 - 8 cores / 3ghz / 32gb RAM / Nvidia 980 GTX with 16gb vram / SSD drives

MSI Dominator Laptop - Core i7 - 8 cores / 3ghz / 32gb RAM / Nvidia 1060 GTX with 8gb vram / SSD drives

Alienware Laptop - Core i7 - 8 cores / 3ghz / 32gb RAM / Nvidia 1070 Ti with 16gb vram / SSD drives

My Patreon page: https://www.patreon.com/michaelfelkercomposer

My music for sale: https://www.tgcstore.net/category/513?format=all&amp;perpage=30&amp;textures=undefined&amp;price=all&amp;order=default&amp;artists[]=87213

Custom synths and sounds - http://www.supersynths.com

Link to comment
Share on other sites

Okay, in Leadwerks the entity and the script objects are two different things, and it can be easy to mix them up sometimes.

The Entity is a C++ class and has engine functions built into it. The script object is a Lua table that new values can be attached to.

In the FPSPlayer.lua script we see that the script itself is passed to the Use() function at line 489:

usableentity.script:Use(self)

So our medkit script should look like this. (The check for max health has been removed to show that it is working):

Script.health = 15.0 --float "Health"
Script.useOnce = true --bool "Use once"
Script.ReleaseTimer=0
Script.ReleaseDelay=5000--float "Corpse Time"

function Script:Start()
    if self.health < 0 then
        error("Health can't be a negative value.")
    end
end

function Script:Collision(entity,position,normal,speed)
	if entity.script ~= nil then
		if entity.script.health ~= nil then
			self:Use(entity.script)
		end
	end
end

function Script:Use(player)
    --if player.health < player.maxHealth then
        player:ReceiveHealth(self.health)
        if self.useOnce then
            self.entity:Hide()
        end
    --end
end

If you extract this zip file into a project created from the FPS game template, you can see it working:

medkit example.zip

Having the script and entity as separate object can be confusing, and in the new engine that is in development, I found a way to make them one single object.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

  • Josh locked this topic
Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...