Bully-Board

Bully Modding Section => Script Modding => LUA Scripting Help => Topic started by: AWiseMelon on April 03, 2016, 06:13:01 PM

Title: Making something happen when the player gets to a certain area
Post by: AWiseMelon on April 03, 2016, 06:13:01 PM
I'm making a mission and I want a bit in it to be like this: The player goes to the autoshop and wwhen he gets there text appears and controls are disabled. I have this but nothing seems to happen:

if PedInRectangle(Player, 120, 46, 98, 24) then
PlayerSetControl(0)
TextPrintString("Jimmy: Norton! Where's that punk Johnny!?", 4, 1)
TextPrintString("Norton: Sorry, Hopkins, Johnny couldn't make it",4.5, 1)
TextPrintString("Jimmy: Well then I guess there'll be one more grease ball hurting after this!", 5, 1)
PedSetPedToTypeAttitude(Norton, 13, 0)
PlayerSetControl(1)
TextPrintString("Beat up Norton.", 3, 1)
Title: Re: Making something happen when the player gets to a certain area
Post by: Shrimp on April 03, 2016, 07:40:13 PM
The player isn't called Player, he's called gPlayer.
Try that, if that doesn't work then don't do PedInRectangle and try,
PedIsInAreaXYZ(gPlayer, coord's here)

Also, instead of PedSetPedToTypeAttitude,
try using the PedAttack()
Title: Re: Making something happen when the player gets to a certain area
Post by: AWiseMelon on April 03, 2016, 08:20:32 PM
Thanks, I got it worked out, It turns out I can also use the player's ID (0) and also I tried PedAttack but when they attacked me their hits didn't connect....EVER, this was because the save game that I'm using the Greasers are at 100% relationship with me and therefore they're obviously not supposed to be attacking me without being provoked, so I had to make them hate me. If you see also where i have the three pieces of text between Norton and Jimmy, I found out you have to actually put "Wait(How long you want)" for it to work or the text will go so fast it looks like the script skipped it :( also do you know how to make a ped face a certain direction when they're spawned because Norton is facing the complete wrong direction lmao
Title: Re: Making something happen when the player gets to a certain area
Post by: Shrimp on April 03, 2016, 08:26:50 PM
I forgot about the Wait thing, damn.
But you can see a ped relationship after you spawned it, (Right after the code) and then do pedattack
i find pedattack better cause it's directly attacking instead of it idle for a second, pointing, then attacking, delaying it for a few seconds.
am glad i helped.
Title: Re: Making something happen when the player gets to a certain area
Post by: AWiseMelon on April 03, 2016, 08:35:01 PM
Yeah, I used PedAttack for some other greasers earlier in the mission, but I have a problem where I have to run in front of Norton to get him to see me, therefore attack me, because he's facing the wrong direction. Is there any way I can get him to face a certain direction when I spawn him?
Title: Re: Making something happen when the player gets to a certain area
Post by: Shrimp on April 03, 2016, 08:57:02 PM
Yeah, I used PedAttack for some other greasers earlier in the mission, but I have a problem where I have to run in front of Norton to get him to see me, therefore attack me, because he's facing the wrong direction. Is there any way I can get him to face a certain direction when I spawn him?
Yes.
PedFaceXYZ()
Title: Re: Making something happen when the player gets to a certain area
Post by: AWiseMelon on April 03, 2016, 09:21:23 PM
How do I use it? PedFaceXYZ(Norton,..........) then what?
Title: Re: Making something happen when the player gets to a certain area
Post by: Shrimp on April 03, 2016, 10:42:41 PM
How do I use it? PedFaceXYZ(Norton,..........) then what?
The XYZ after seperated by ,
like X,Y,Z,
to find the gPlayer/ped facing XYZ...
well I only know how to get XYZ's of Ped facing from Daboss Supermod 5 which isn't released and I think I only have it sadly.
Title: Re: Making something happen when the player gets to a certain area
Post by: AWiseMelon on April 04, 2016, 02:54:13 AM
Wait, is that to GET their direction or to SET it?
Title: Re: Making something happen when the player gets to a certain area
Post by: UltimateGamer9 on April 04, 2016, 11:29:49 AM
Wait, is that to GET their direction or to SET it?
set
Title: Re: Making something happen when the player gets to a certain area
Post by: AWiseMelon on April 04, 2016, 01:56:04 PM
Can I write "gPlayer" in the () instead of co-ords?
Title: Re: Making something happen when the player gets to a certain area
Post by: Shrimp on April 04, 2016, 03:27:19 PM
Can I write "gPlayer" in the () instead of co-ords?
I don't think it'll work, it probably might, fuck know's I never tried it, but you can try it if you want.
Title: Re: Making something happen when the player gets to a certain area
Post by: AWiseMelon on April 04, 2016, 03:34:07 PM
Nah, it doesn't work unfortunately :(
Title: Re: Making something happen when the player gets to a certain area
Post by: UltimateGamer9 on April 04, 2016, 10:21:17 PM
PedFaceXYZ is one of the simplest code dude. it's just like this PedFaceXYZ(ped,X,Y,Z) that's it
Title: Re: Making something happen when the player gets to a certain area
Post by: Shrimp on April 04, 2016, 11:23:28 PM
PedFaceXYZ is one of the simplest code dude. it's just like this PedFaceXYZ(ped,X,Y,Z) that's it
His question was if he can use gPlayer, so the ped can face the player instead, he know's how to use the code.
Title: Re: Making something happen when the player gets to a certain area
Post by: UltimateGamer9 on April 05, 2016, 09:33:14 AM
PedFaceXYZ is one of the simplest code dude. it's just like this PedFaceXYZ(ped,X,Y,Z) that's it
His question was if he can use gPlayer, so the ped can face the player instead, he know's how to use the code.
that's even more simpler. code: PedFaceObject(Ped,Ped,3)
Title: Re: Making something happen when the player gets to a certain area
Post by: AWiseMelon on April 05, 2016, 11:38:57 AM
I didn't even know that was a function.
Title: Re: Making something happen when the player gets to a certain area
Post by: AlphaTech on April 05, 2016, 01:46:55 PM
Check my tutorials for how to use certain functions and anything you want to do. http://www.bully-board.com/index.php?topic=22996.msg394002#msg394002 (http://www.bully-board.com/index.php?topic=22996.msg394002#msg394002)

Code: [Select]
MissionSetup = function()
-- (0) is the area code for the main map, all area codes are placed here.
    PlayerSetHealth(800)
    AreaTransitionXYZ(0, 477.5798, -107.3748, 16.6911)

PedSetUniqueModelStatus(29, -1)

SoundPlayInteractiveStream("MS_BikeFunLow.rsm", 0.5)
SoundSetMidIntensityStream("MS_BikeFunMid.rsm", 0.60000002384186)
SoundSetHighIntensityStream("MS_BikeFunHigh.rsm", 0.60000002384186)

Norton = PedCreateXYZ(29,120,46,98,)

PedSetAmbiet(Norton,true)

TestBlip = BlipAddXYZ(120,46,98,0) (0 is the small Yellow X appearing on the map) (The blip's location should always be the same as the objective location not any wear else. If you script the blip in another location you may mess up player's in finding certain things.)
TextPrintString("Follow the X on the map to go to the location!",4,1)
Wait(3000)

MissionObjective()

end

MissionObjective = function()
  local x,y = 120,46 (Created by Daboss, can be used to make a certain instance.)
  local r1 = x + 3.5
  local r2 = y + 3.5
  local r3 = x - 3.5
  local r4 = y - 3.5
  repeat
    Wait(0)
  until PedInRectangle(gPlayer,r1,r2,r3,r4)

BlipRemove(TestBlip)

TextPrintString("Jimmy: Norton! Where's that punk Johnny!?", 4, 1)
TextPrintString("Norton: Sorry, Hopkins, Johnny couldn't make it",4.5, 1)
TextPrintString("Jimmy: Well then I guess there'll be one more grease ball hurting after this!", 5, 1)
PedSetPedToTypeAttitude(Norton, 13, 0)
PlayerSetControl(1)
TextPrintString("Beat up Norton.", 3, 1)
IsNortonDead = false
end

MissionObjectiveFinal = function()
if PedIsDead(Norton) and IsNortonDead == false then
IsNortonDead = true
TextPrintString("Great you've defeated!",4,1)
Wait(3000)

SoundPlayMissionEndMusic(true, 8)
MissionSucceed(true, false, false)
CameraSetWidescreen(true) 
Wait(4000)
CameraFade(500, 0)
AreaTransitionXYZ(14, -501.4, 316.11, 31.5)
Wait(500)
CameraAllowChange(true)
SoundSetAudioFocusPlayer()
CameraReturnToPlayer()
CameraReset()
CameraSetWidescreen(false)
PlayerSetControl(1)
end

F_PlayerFail = function()
if PedIsDead(gPlayer) then
SoundPlayMissionEndMusic(true, 6)
MissionFail(true, false, false)
Wait(4000)
CameraSetWidescreen(true)
CameraFade(700, 0)
AreaTransitionXYZ(14, -501.4, 316.11, 31.5)
Wait(500)
CameraAllowChange(true)
SoundSetAudioFocusPlayer()
CameraReturnToPlayer()
CameraReset()
CameraSetWidescreen(false)
PlayerSetControl(1)
end

F_LoadAnim = function()
  LoadAnimationGroup("Cheer_Cool2")
  LoadAnimationGroup("NPC_Adult")
  LoadAnimationGroup("TSGate")
  LoadAnimationGroup("SCgrdoor")
  LoadAnimationGroup("Sbarels1")
  LoadAnimationGroup("Area_School")
  LoadAnimationGroup("Px_Rail")
  LoadAnimationGroup("DO_Grap")
  LoadAnimationGroup("1_07_SaveBucky")
  LoadAnimationGroup("TSGate")
  LoadAnimationGroup("F_Nerds")
  LoadAnimationGroup("Hang_Jock")
  LoadAnimationGroup("NPC_AggroTaunt")
  LoadAnimationGroup("Hang_Talking")
  LoadAnimationGroup("1_07_Sk8Board")
  Load("Act/Conv/1_07.act")
  LoadActionTree("Act/Props/SBarels1.act")
  LoadActionTree("Act/Props/barrelLad.act")
  LoadActionTree("Act/Conv/1_03.act")
  LoadActionTree("Act/Anim/1_03_Davis.act")
end

F_CleanUpAnim = function() (Not necessary to use the mission will work either way.)
  UnLoadAnimationGroup("Cheer_Cool2")
  UnLoadAnimationGroup("NPC_Adult")
  UnLoadAnimationGroup("TSGate")
  UnLoadAnimationGroup("SCgrdoor")
  UnLoadAnimationGroup("Sbarels1")
  UnLoadAnimationGroup("Area_School")
  UnLoadAnimationGroup("Px_Rail")
  UnLoadAnimationGroup("DO_Grap")
  UnLoadAnimationGroup("1_07_SaveBucky")
  UnLoadAnimationGroup("TSGate")
  UnLoadAnimationGroup("F_Nerds")
  UnLoadAnimationGroup("Hang_Jock")
  UnLoadAnimationGroup("NPC_AggroTaunt")
  UnLoadAnimationGroup("Hang_Talking")
  UnLoadAnimationGroup("1_07_Sk8Board")
  collectgarbage()
end

main = function()
F_LoadAnim()
F_PlayerFail()
MissionObjectiveFinal()
repeat
Wait(0)
until not Alive
Title: Re: Making something happen when the player gets to a certain area
Post by: AlphaTech on April 05, 2016, 03:00:28 PM
Code: [Select]
@Shrimp Can I actually finish scripting the mission Jesus Fucking Christ.

@AWiseMelson Fixed your spawn point the other one didn't show the first time.

[codeMissionSetup = function()
-- (0) is the area code for the main map, all area codes are placed here.
    PlayerSetHealth(800)
    AreaTransitionXYZ(0, 477.5798, -107.3748, 16.6911)

PedSetUniqueModelStatus(29, -1)

SoundPlayInteractiveStream("MS_BikeFunLow.rsm", 0.5)
SoundSetMidIntensityStream("MS_BikeFunMid.rsm", 0.60000002384186)
SoundSetHighIntensityStream("MS_BikeFunHigh.rsm", 0.60000002384186)

Norton = PedCreateXYZ(29,503.7057,-112.5930,5.1166)

TestBlip = BlipAddXYZ(503.7057,-112.5930,5.1166,0) --(0 is the small Yellow X appearing on the map) (The blip's location should always be the same as the objective location not any wear else. If you script the blip in another location you may mess up player's in finding certain things.)
TextPrintString("Follow the X on the map to go to the location!",4,1)
Wait(3000)

MissionObjective()

end

MissionObjective = function()
  local x,y = 503,-112 --(Created by Daboss, can be used to make a certain instance.)
  local r1 = x + 3.5
  local r2 = y + 3.5
  local r3 = x - 3.5
  local r4 = y - 3.5
  repeat
    Wait(0)
  until PedInRectangle(gPlayer,r1,r2,r3,r4)

BlipRemove(TestBlip)

TextPrintString("Jimmy: Norton! Where's that punk Johnny!?", 4, 1)
TextPrintString("Norton: Sorry, Hopkins, Johnny couldn't make it",4.5, 1)
TextPrintString("Jimmy: Well then I guess there'll be one more grease ball hurting after this!", 5, 1)
PedSetPedToTypeAttitude(Norton, 13, 0)
PlayerSetControl(1)
TextPrintString("Beat up Norton.", 3, 1)
IsNortonDead = false
end

MissionObjectiveFinal = function()
if PedIsDead(Norton) and IsNortonDead == false then
IsNortonDead = true
TextPrintString("Great you've defeated!",4,1)
Wait(3000)
SoundPlayMissionEndMusic(true, 8)
MissionSucceed(true, false, false)
CameraSetWidescreen(true) 
Wait(4000)
CameraFade(500, 0)
AreaTransitionXYZ(14, -501.4, 316.11, 31.5)
Wait(500)
CameraAllowChange(true)
SoundSetAudioFocusPlayer()
CameraReturnToPlayer()
CameraReset()
CameraSetWidescreen(false)
PlayerSetControl(1)
end
if PedIsDead(Norton) and IsNortonDead == false then
IsNortonDead = true
TextPrintString("Great you've defeated!",4,1)
Wait(3000)
SoundPlayMissionEndMusic(true, 8)
MissionSucceed(true, false, false)
CameraSetWidescreen(true) 
Wait(4000)
CameraFade(500, 0)
AreaTransitionXYZ(14, -501.4, 316.11, 31.5)
Wait(500)
CameraAllowChange(true)
SoundSetAudioFocusPlayer()
CameraReturnToPlayer()
CameraReset()
CameraSetWidescreen(false)
PlayerSetControl(1)
end
end

F_PlayerFail = function()
if PedIsDead(gPlayer) then
SoundPlayMissionEndMusic(true, 6)
MissionFail(true, false, false)
Wait(4000)
CameraSetWidescreen(true)
CameraFade(700, 0)
AreaTransitionXYZ(14, -501.4, 316.11, 31.5)
Wait(500)
CameraAllowChange(true)
SoundSetAudioFocusPlayer()
CameraReturnToPlayer()
CameraReset()
CameraSetWidescreen(false)
PlayerSetControl(1)
end
if PedIsDead(gPlayer) then
SoundPlayMissionEndMusic(true, 6)
MissionFail(true, false, false)
Wait(4000)
CameraSetWidescreen(true)
CameraFade(700, 0)
AreaTransitionXYZ(14, -501.4, 316.11, 31.5)
Wait(500)
CameraAllowChange(true)
SoundSetAudioFocusPlayer()
CameraReturnToPlayer()
CameraReset()
CameraSetWidescreen(false)
PlayerSetControl(1)
end
end

F_LoadAnim = function()
  LoadAnimationGroup("Cheer_Cool2")
  LoadAnimationGroup("NPC_Adult")
  LoadAnimationGroup("TSGate")
  LoadAnimationGroup("SCgrdoor")
  LoadAnimationGroup("Sbarels1")
  LoadAnimationGroup("Area_School")
  LoadAnimationGroup("Px_Rail")
  LoadAnimationGroup("DO_Grap")
  LoadAnimationGroup("1_07_SaveBucky")
  LoadAnimationGroup("TSGate")
  LoadAnimationGroup("F_Nerds")
  LoadAnimationGroup("Hang_Jock")
  LoadAnimationGroup("NPC_AggroTaunt")
  LoadAnimationGroup("Hang_Talking")
  LoadAnimationGroup("1_07_Sk8Board")
  Load("Act/Conv/1_07.act")
  LoadActionTree("Act/Props/SBarels1.act")
  LoadActionTree("Act/Props/barrelLad.act")
  LoadActionTree("Act/Conv/1_03.act")
  LoadActionTree("Act/Anim/1_03_Davis.act")
end

F_CleanUpAnim = function() --(Not necessary to use the mission will work either way.)
  UnLoadAnimationGroup("Cheer_Cool2")
  UnLoadAnimationGroup("NPC_Adult")
  UnLoadAnimationGroup("TSGate")
  UnLoadAnimationGroup("SCgrdoor")
  UnLoadAnimationGroup("Sbarels1")
  UnLoadAnimationGroup("Area_School")
  UnLoadAnimationGroup("Px_Rail")
  UnLoadAnimationGroup("DO_Grap")
  UnLoadAnimationGroup("1_07_SaveBucky")
  UnLoadAnimationGroup("TSGate")
  UnLoadAnimationGroup("F_Nerds")
  UnLoadAnimationGroup("Hang_Jock")
  UnLoadAnimationGroup("NPC_AggroTaunt")
  UnLoadAnimationGroup("Hang_Talking")
  UnLoadAnimationGroup("1_07_Sk8Board")
  collectgarbage()
end

main = function()
F_LoadAnim()
repeat
F_PlayerFail()
MissionObjectiveFinal()
Wait(0)
until not Alive
end]
Title: Re: Making something happen when the player gets to a certain area
Post by: Bully_Lover13 on April 06, 2016, 04:00:14 AM
shrimp is right.

alpha, that's just stupid coding, if you did  not even type finish, why bother clicking on the post button?
Title: Re: Making something happen when the player gets to a certain area
Post by: Shrimp on April 06, 2016, 08:42:36 AM
shrimp is right.

alpha, that's just stupid coding, if you did  not even type finish, why bother clicking on the post button?

Maybe he's desperate for post count?  :jajaja: :jajaja: ;)
Title: Re: Making something happen when the player gets to a certain area
Post by: Bully_Lover13 on April 07, 2016, 06:53:13 AM
shrimp is right.

alpha, that's just stupid coding, if you did  not even type finish, why bother clicking on the post button?

Maybe he's desperate for post count?  :jajaja: :jajaja: ;)

he sure is.
Title: Re: Making something happen when the player gets to a certain area
Post by: c00ld0c26 on April 10, 2016, 03:41:32 PM
Alpha and Shrimp, I will not stand members who insult eachother.
Behave please.
Posts deleted for now.
Title: Re: Making something happen when the player gets to a certain area
Post by: c00ld0c26 on April 12, 2016, 11:50:23 AM
I indeed have returned from the dead.
As for this forum, Ima keep a close watch on it due to the latest behaviour of some members.
Title: Re: Making something happen when the player gets to a certain area
Post by: Phap on June 14, 2016, 04:15:17 PM
Woah when did d0c become Moderator long time no see