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


Author Topic: Making something happen when the player gets to a certain area  (Read 14306 times)

0 Members and 1 Guest are viewing this topic.

Offline UltimateGamer9

  • Full Member
  • ***
  • Posts: 190
  • Gender: Male
    • View Profile
Re: Making something happen when the player gets to a certain area
« Reply #15 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)

Offline AWiseMelon

  • Jr. Member
  • **
  • Posts: 42
  • Gender: Male
    • View Profile
Re: Making something happen when the player gets to a certain area
« Reply #16 on: April 05, 2016, 11:38:57 AM »
I didn't even know that was a function.

Offline AlphaTech

  • LostInSpace
  • Sr. Member
  • ***
  • Posts: 758
  • Gender: Male
  • The name's AlphaTECH, whatca need help with?! :)
    • View Profile
Re: Making something happen when the player gets to a certain area
« Reply #17 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

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
« Last Edit: April 05, 2016, 01:55:08 PM by AlphaTech »

Offline AlphaTech

  • LostInSpace
  • Sr. Member
  • ***
  • Posts: 758
  • Gender: Male
  • The name's AlphaTECH, whatca need help with?! :)
    • View Profile
Re: Making something happen when the player gets to a certain area
« Reply #18 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]
« Last Edit: April 05, 2016, 03:15:14 PM by AlphaTech »

Offline Bully_Lover13

  • Full Member
  • ***
  • Posts: 119
    • View Profile
Re: Making something happen when the player gets to a certain area
« Reply #19 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?

Offline Shrimp

  • Sr. Member
  • ***
  • Posts: 514
  • Gender: Male
  • your official b-b's chav. wag wan.
    • View Profile
Re: Making something happen when the player gets to a certain area
« Reply #20 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: ;)

Offline Bully_Lover13

  • Full Member
  • ***
  • Posts: 119
    • View Profile
Re: Making something happen when the player gets to a certain area
« Reply #21 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.

Offline c00ld0c26

  • The D0c
  • Moderator
  • Can't Get Enough
  • *****
  • Posts: 5,137
  • Gender: Male
  • Just a dood doing dood things.
    • View Profile
    • My channel.
Re: Making something happen when the player gets to a certain area
« Reply #22 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.

Offline DaBOSS54320

  • Hero Member
  • ****
  • Posts: 3,398
  • Gender: Female
    • View Profile
Re: Making something happen when the player gets to a certain area
« Reply #23 on: April 11, 2016, 11:24:41 PM »
Oooh the d0c emerges from the dead to moderate some motha fuckaz. Nice job.



You can get the peds coordinates and use those for the look at function.
local x,y,z = PedGetPosXYZ(ped)
PedFaceXYZ(gPlayer,x,y,z)

Or use the other function in the other replies if you prefer it.

gPlayer and 0 are basically the same thing since gPlayer is just a variable with the value 0, so use whatever is best for you. Personally I think gPlayer is a little more descriptive so I go with that.

Important side note with the ped face functions, if you ever set the player's position, you should do it after setting the peds direction. For example...

PlayerSetPosXYZ(270,-110,6)
PedFaceXYZ(gPlayer,275,-110,6)

In my experience, something like that would fail to work. I find it strange but, that's how it seems to happen.

PedFaceXYZ(gPlayer,275,-110,6)
PlayerSetPosXYZ(270,-110,6)

That should work though. Or if you just wait between the setting and facing it'll work too.



It seems you have the area part figured out by now but I still would like to give you a bit more info and elaborate more on how PedInRectangle works.
The PedIsInAreaXYZ function should be used when you want a circular range, and the PedInRectangle function when you have a rectangular one (like rectangular rooms and stuff). PedIsInAreaXYZ is simpler and works best in most cases so I personally usually use that, but PedInRectangle still has its uses.

PedInRectangle works like this:
PedInRectangle(Ped, Max X, Max Y, Min X, Min Y)

It's basically just tests the player's X and Y coordinates to see if they land in a certain range, and ignores the Z coordinate (height). You really could create your own version of it easily if you wanted by just getting the player's coordinates and using the relational operators (>, <, <=, >=, etc) decide if the player is in the rectangle or not. The downside with this function too is that you can't really rotate the rectangle because of how the function works. If you want to include height, you can easily do so by testing the Z coordinate as well with the relational operators, the same way X and Y are tested.

PedIsInAreaXYZ as you already figured out works like this:
PedIsInAreaXYZ(ped,x,y,z,range)

It's honestly a bit simpler and you should probably stick with it unless you have a need for rectangle shaped triggers.

Offline c00ld0c26

  • The D0c
  • Moderator
  • Can't Get Enough
  • *****
  • Posts: 5,137
  • Gender: Male
  • Just a dood doing dood things.
    • View Profile
    • My channel.
Re: Making something happen when the player gets to a certain area
« Reply #24 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.

Offline Phap

  • Full Member
  • ***
  • Posts: 216
  • Gender: Male
    • View Profile
Re: Making something happen when the player gets to a certain area
« Reply #25 on: June 14, 2016, 04:15:17 PM »
Woah when did d0c become Moderator long time no see