Jump to content

Problem with medikit (Workshop) model


guido892
 Share

Recommended Posts

 
 
 
 
 
494/5000
 
Hello everyone ,
I have a problem with a template downloaded from workshop.it is a medikit.
When I create a prefab with this model, setting it as Prop and mass 10, setting it for a script with function use() and then save it, if I insert it in the map through the editor it works correctly (Photo 1), but if I insert it via script,the 
function use() does not work anymore (Photo 2). It also happens to me with the ammo model of the workshop. What can I do ?
Thank you and excuse me for my bad english.

Photo1.jpg

Photo 2.jpg

Link to comment
Share on other sites

Thanks AggrorJorn for your answer.
I tried both , the prefab and with the model via script, but the result is the same.

This is the script that is attached to the medikit model,it's basically like the push button trigger with added instructions to give energy.

I added the collision function () to test if it works and the result is that it works. Only use () function does not work.

Script.enabled=true--bool "Enabled"
Script.soundfile=""--path "Sound" "Wav Files (*.wav):wav"
Script.Energy=20 --int "proiettili da dare"

function Script:Start()
	if self.soundfile then
		self.sound = Sound:Load(self.soundfile)
	end
self.entity:SetCollisionType(Collision.Prop)
self.entity:SetMass(10)
end

function Script:Use(Player)
	if self.enabled then
		if self.sound then self.entity:EmitSound(self.sound) end
		self.component:CallOutputs("Use")
			if Player.health < Player.maxHealth then
				Player:GiveHealth(self.Energy)
				self.entity:Release()
				else
				Player.timeStartandDuration = Time:GetCurrent() + 2000
				Player.hemax=true
			end
	end
end

function Script:Collision(entity, position, normal, speed)
	if self.enabled then
		if entity:GetKeyValue("name")=="giocatore" then
			if entity.script~=nil then self:Use(entity.script) end
		end
	end
end

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

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

function Script:Release()
	if self.sound then self.sound:Release() end
end
Link to comment
Share on other sites

And this is the function that spawn the medikit.

function Script:SpawnEnergy(type1)
	for f=1,self.Energy do
		if type1 == 1 then
			local enemy=Prefab:Load("Prefabs/medi.pfb")
			local x1,z1
			x1,z1=self:GetPosObj(self.rommcr[self.energycr[f]])
			enemy:SetPosition(self.rommcr[self.energycr[f]]:GetPosition()+Vec3(x1,-0.7,z1))
		end
	end

end

 

Link to comment
Share on other sites

I tried now with model but the result is the same.This is the script changed

function Script:SpawnEnergy(type1)
	for f=1,self.Energy do	
		if type1 == 1 then
			local enemy=Model:Load("healtkit.mdl")
			local x1,z1
			x1,z1=self:GetPosObj(self.rommcr[self.energycr[f]])
			enemy:SetPosition(self.rommcr[self.energycr[f]]:GetPosition()+Vec3(x1,-0.7,z1))
			enemy:SetScript("Scripts/Objects/Items/Med.lua")
		end
	end
end

 

Link to comment
Share on other sites

So you load the model, set the script, and mass and physics type are set. And your medkit falls down when you start the game?

If you run your game in debug mode and debug physics (I think you have to press P or F1) to toggle, does your entity have a physics shape? Does that differ from a medkit that is loaded via the editor?

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