guido892 Posted June 18, 2018 Share Posted June 18, 2018 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. Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted June 18, 2018 Share Posted June 18, 2018 Can you show the script? Are loading in the prefab or the model via script? Quote Link to comment Share on other sites More sharing options...
guido892 Posted June 19, 2018 Author Share Posted June 19, 2018 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 Quote Link to comment Share on other sites More sharing options...
guido892 Posted June 19, 2018 Author Share Posted June 19, 2018 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 Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted June 19, 2018 Share Posted June 19, 2018 I mean the script you use to load in the medkit in to your scene. If you load the model of the medpack, you need to set the script yourself. Once you have spawned the medpack, can you access any variable in it? if not than that would mean there is no script attached to it. Quote Link to comment Share on other sites More sharing options...
guido892 Posted June 19, 2018 Author Share Posted June 19, 2018 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 Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted June 19, 2018 Share Posted June 19, 2018 And can you access the scripta variables? Is the collision type set? Is the mass set? Quote Link to comment Share on other sites More sharing options...
guido892 Posted June 19, 2018 Author Share Posted June 19, 2018 The collison type and mass are set by script in start function,as in the first script i've post Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted June 19, 2018 Share Posted June 19, 2018 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.