Jump to content

Adding sound to picked up items


Imchasinyou
 Share

Recommended Posts

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

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

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

  • Upvote 1

Elite Cobra Squad

Link to comment
Share on other sites

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 :)

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

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.

Link to comment
Share on other sites

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.

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

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

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

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