Imchasinyou Posted January 11, 2015 Share Posted January 11, 2015 It would be great if some one could show me how to add sound to the medpack script. Ive tried alot of different things and at this point, Im lost. . . . Script.healthpoints=15 --float "Health Points" function Script:Use(person) if person.entity.script.health>0 then person.entity.script.health= person.entity.script.health + self.healthpoints if person.entity.script.health>person.entity.script.maxHealth then person.entity.script.health=person.entity.script.maxHealth end end end Learning is confusing me . . . . Quote Asus sabertooth 990FX, AMD FX 9590 , Windows 7 Home Premium 64 Bit, 4 HDD's Western Digital Caviar Black set in Raid 0, 16 GB Crucial Ballistix Elite, Asus Radeon R9 270 X 4GB, Corsair CM750M, Link to comment Share on other sites More sharing options...
josk Posted January 11, 2015 Share Posted January 11, 2015 Script.healthpoints=15 --float "Health Points" function Script:Start() local sound = Sound:Load("Sound/Player/pickupammo.wav") self.source = Source:Create() self.source:SetSound(sound) end function Script:Use(person) if person.entity.script.health>0 then person.entity.script.health= person.entity.script.health + self.healthpoints self.source:Play() if person.entity.script.health>person.entity.script.maxHealth then person.entity.script.health=person.entity.script.maxHealth end end end Not seen the medpack script but the following should work. Add the code to Script:Start and to play the sound use self.source:Play(). 1 Quote Elite Cobra Squad Link to comment Share on other sites More sharing options...
Imchasinyou Posted January 11, 2015 Author Share Posted January 11, 2015 Thanks Josk. I had tried and tried but wasnt gettign anywhere but errors. I was trying everything I found in the documentation but wasnt getting very far. Thanks again. Now on to other problems Quote Asus sabertooth 990FX, AMD FX 9590 , Windows 7 Home Premium 64 Bit, 4 HDD's Western Digital Caviar Black set in Raid 0, 16 GB Crucial Ballistix Elite, Asus Radeon R9 270 X 4GB, Corsair CM750M, Link to comment Share on other sites More sharing options...
BluHornet Posted January 13, 2015 Share Posted January 13, 2015 Script.HealthEnabled = true Script.health = 25 --int "Health Value" Script.PickupSoundPath = "" --path "Sound" "Wav File (*wav):wav|Sound" Script.PickupSound = nil function Script:Start() self.PickupSound = Sound:Load(self.PickupSoundPath) end function Script:Collision(entity, position, normal, speed) if (entity:GetKeyValue("name") == "Player") then if self.HealthEnabled == true then if entity.script.health < entity.script.maxHealth then entity.script:ReceiveHealth(self.health) self.entity:EmitSound(self.PickupSound) self.HealthEnabled = false self.entity:Hide() end end end end This is my Health Pick up script. Don't forget once you add the script to your entity to add the sound file to the script in the editor. Quote Link to comment Share on other sites More sharing options...
Imchasinyou Posted January 13, 2015 Author Share Posted January 13, 2015 Here is what I use. . . . Script.healthpoints=15 --float "Health Points" function Script:Start() local sound = Sound:Load("Sound/Player/pickupammo.wav") self.source = Source:Create() self.source:SetSound(sound) end function Script:Use(person) if person.entity.script.health>0 then person.entity.script.health= person.entity.script.health + self.healthpoints self.source:Play() if person.entity.script.health>person.entity.script.maxHealth then person.entity.script.health=person.entity.script.maxHealth end end end Very small, very clean and simple. Most of all, it works and is reusable. Id like to either make it single use or timer based. But until i can figure that out, Ill use this. Same as yours, you must reassign the sound that you want to use. Quote Asus sabertooth 990FX, AMD FX 9590 , Windows 7 Home Premium 64 Bit, 4 HDD's Western Digital Caviar Black set in Raid 0, 16 GB Crucial Ballistix Elite, Asus Radeon R9 270 X 4GB, Corsair CM750M, Link to comment Share on other sites More sharing options...
BluHornet Posted January 13, 2015 Share Posted January 13, 2015 Yeah I left the sound file because I want to mod it later to be health and/or ammo one script for both just change the type and sound. But after I got the code wrote I wrote a ammo pick up forgetting this planned feature. I am still new so I fly by the seat a little too much. what is cool Is we have 2 different codes to answer the same problem. It makes the game feel like mine, ya know. if you want it to be single use it is easy to fix. Script.healthpoints=15 --float "Health Points" function Script:Start() local sound = Sound:Load("Sound/Player/pickupammo.wav") self.source = Source:Create() self.source:SetSound(sound) end function Script:Use(person) if person.entity.script.health>0 then person.entity.script.health= person.entity.script.health + self.healthpoints self.source:Play() self.entity:Release() if person.entity.script.health>person.entity.script.maxHealth then person.entity.script.health=person.entity.script.maxHealth end end end Quote Link to comment Share on other sites More sharing options...
BluHornet Posted January 13, 2015 Share Posted January 13, 2015 adding a line self.entity:Release() Removes the object the script is attachd to just be sure that you release it at a time you are done with it. If you do not like deleting it you can do the enable variable like I did and then hide it. Quote Link to comment Share on other sites More sharing options...
BluHornet Posted January 14, 2015 Share Posted January 14, 2015 I made a quick tutorial video on how to make the pickup timed here Quote Link to comment Share on other sites More sharing options...
BluHornet Posted January 14, 2015 Share Posted January 14, 2015 I just watched the video and now see the resolution is shot. The file I uploaded was fine... well anyway here is the code too. Script.healthpoints=15 --float "Health Points" Script.HealTimer = 0 function Script:Start() local sound = Sound:Load("Sound/Player/pickupammo.wav") self.source = Source:Create() self.source:SetSound(sound) end function Script:UpdateWorld() self.HealTimer = self.HealTimer + 1 System:Print(self.HealTimer) if self.HealTimer < 450 then self.entity:Hide() else self.entity:Show() end end function Script:Use(person) if person.entity.script.health>0 then if self.HealTimer > 500 then person.entity.script.health= person.entity.script.health + self.healthpoints self.source:Play() self.HealTimer = 0 end if person.entity.script.health>person.entity.script.maxHealth then person.entity.script.health=person.entity.script.maxHealth end end end Quote Link to comment Share on other sites More sharing options...
Imchasinyou Posted January 14, 2015 Author Share Posted January 14, 2015 I totally understand how you feel. Im just glad to see more ppl willing to post little things like this that just might help some one. YES, you can learn this way. Its frustrating to see a reply like, go look at the documentation when some one cant make heads or tails of it. . . . Ill try and release the script after the pick up is made and see what happens. BTW, if you recorded in a higher resolution, it very well might just take a few minutes to be available in HD. Mine do. Quote Asus sabertooth 990FX, AMD FX 9590 , Windows 7 Home Premium 64 Bit, 4 HDD's Western Digital Caviar Black set in Raid 0, 16 GB Crucial Ballistix Elite, Asus Radeon R9 270 X 4GB, Corsair CM750M, 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.