News: Welcome back to Bullworth! If you haven't already, you will need to reset your password..


Author Topic: A function I just made up  (Read 5659 times)

0 Members and 1 Guest are viewing this topic.

Offline 3gtheepic

  • Jr. Member
  • **
  • Posts: 10
  • Gender: Male
  • I'm just some kid who likes to mod.
    • View Profile
A function I just made up
« on: October 10, 2016, 11:37:04 AM »
I was bored so I made this function you guys can use


Code: [Select]
function SetFightingMusicForPed(song,volume,ped)
              if PedAttackPlayer(ped) then
                     SoundPlayStream(song, volume)
              if PedIsDead(ped) or PedIsValid(ped) then
                    SoundStopStream()
end


Example of how you can use this function:

Code: [Select]
SetFightingMusicForPed('MS_FightingJohnnyVincentBossFight.rsm',1,norton)

This function is good for missions that roleplay as different characters

(ex. Norton as will smith)

« Last Edit: October 10, 2016, 11:39:44 AM by 3gtheepic »

Offline DaBOSS54320

  • Hero Member
  • ****
  • Posts: 3,398
  • Gender: Female
    • View Profile
Re: A function I just made up
« Reply #1 on: October 10, 2016, 02:10:26 PM »
Code: [Select]
function SetFightingMusicForPed(song,volume,ped)
              if PedAttackPlayer(ped) then
                     SoundPlayStream(song, volume)
              if PedIsDead(ped) or PedIsValid(ped) then
                    SoundStopStream()
end

This function seems really broken but it's nice to see you're interested in making stuff like this.

Problem 1: You have 2 if statements and neither have an end (and if the last one has an end then the function doesn't have one). Remember every if statement needs to end with an end and so does every function, or of course you can use elseif to extend alternate conditions on it (still having an end after it all).

Problem 2: You do stuff with the ped before even checking if it is still valid, it'd be best to check if the ped is valid first.

Code: [Select]
SetFightingMusicForPed(song,volume,ped)
  if not PedIsValid(ped) or PedIsDead(ped) then -- check if they are invalid or dead, if so stop the music
    SoundStopStream()
  elseif PedAttackPlayer(ped) then -- if the ped is valid, make them attack and set some music
    SoundPlayStream(song, volume)
  end
end

I think there are other problems with it but I'm not sure, maybe you found a new usage for the PedAttackPlayer function that I don't know of because it normally expects 2 arguments and is used for making a ped attack the player, but the way you use it here it looks as if you meant to check if the ped is attacking the player or not.

Anyways nice to see you share this, maybe we can see more useful shit in da future too, for anyone that can find a use for it.

Offline 3gtheepic

  • Jr. Member
  • **
  • Posts: 10
  • Gender: Male
  • I'm just some kid who likes to mod.
    • View Profile
Re: A function I just made up
« Reply #2 on: October 10, 2016, 03:18:11 PM »
Thanks for pointing out the problems. I kinda knew that I didn't have the ends there I was just too lazy to edit them out.

I'm also working on a cool mission mod. I think it'll come out somewhere around halloween.


Offline DaBOSS54320

  • Hero Member
  • ****
  • Posts: 3,398
  • Gender: Female
    • View Profile
Re: A function I just made up
« Reply #3 on: October 11, 2016, 06:02:06 PM »
Sweet I'm excited to see it yo.