Bully-Board

Bully Modding Section => Script Modding => LUA Scripting Help => Topic started by: NamesStephen on November 03, 2020, 12:10:55 AM

Title: Lua PedSetWeapon & PedSetHealth
Post by: NamesStephen on November 03, 2020, 12:10:55 AM
I'm currently learning lua scripting, and I've run into a problem I just don't know how to fix. I'm trying to spawn Johnny with a bat, and with 200 health. I've just been messing around so I have know idea what I am doing, I'm into that self teaching kinda thing, ya know.

Heres what I have so far.

function MissionSetup()
   PlayerSetPosXYZArea(270,-110,6,0)
   PlayerSetHealth(300)
end

function main()
   PedSetWeapon(23,300,1)
   PedSetHealth(23,2000)
   PedSetHealth(21,33)
   PedSetWeapon(23,395,1)
  TextPrintString("Defeat the Greasers", 5, 1)
   enemy = PedCreateXYZ(23,265,-110,6)
   PedSetPedToTypeAttitude(enemy,13,0)
   PedAttackPlayer(enemy,3)
   enemy = PedCreateXYZ(21,265,-110,6)
   PedSetPedToTypeAttitude(enemy,13,0)
   PedAttackPlayer(enemy,3)
   
   repeat
      Wait(0)
   until PedIsDead(enemy)
   MissionSucceed()
end




One more question I've been wondering about is does the spacing matter in sentences or not?
Title: Re: Lua PedSetWeapon & PedSetHealth
Post by: SimonBestia on November 03, 2020, 10:17:13 AM
There's a couple of issues with your code. Let me help:


Spacing doesn't matter, but having a clean-looking code feels good.

I tried to rewrite your script so try and learn from this:
Code: [Select]
function MissionSetup()

PlayerSetHealth(300) --This could be moved to main since there's no point in having an entire MissionSetup function to do just one thing, but you decide. (MissionSetup is not mandatory, but if present, it will be the first function read by the game)

end

function main()

AreaTransitionXYZ(0, 270, -110, 6)
Johnny = PedCreateXYZ(23, YourX, YourY, YourZ) --Replace the cords for both peds. (duh)
Peanut = PedCreateXYZ(21, YourX, YourY, YourZ)
PedSetWeapon(Johnny, 300, 1)
PedSetWeapon(Peanut, 395, 1)
PedSetHealth(Johnny, 2000)
PedSetHealth(Peanut, 33)
TextPrintString("Defeat the Greasers", 5, 1)
PedSetPedToTypeAttitude(Johnny, 13, 0)
PedSetPedToTypeAttitude(Peanut, 13, 0)
PedAttackPlayer(Johnny, 3)
PedAttackPlayer(Peanut, 3)

repeat
Wait(0)
until PedIsDead(Johnny) and PedIsDead(Peanut)

MissionSucceed()

end

Random extra tip:
Since you're changing the attitude of two greaser peds, instead of doing PedSetPedToTypeAttitude twice, you could just do PedSetTypeToTypeAttitude(Faction1, Faction2, Attitude) once. (Unless, again, you want to control those two independently)
Title: Re: Lua PedSetWeapon & PedSetHealth
Post by: NamesStephen on November 04, 2020, 10:19:31 PM
Thank you very much my good man!

Also I like your videos, keep up the good work!