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


Author Topic: [Help] Spawning too much npcs until game crash, not working out of a loop  (Read 1996 times)

0 Members and 2 Guests are viewing this topic.

Offline feliiperh

  • Jr. Member
  • **
  • Posts: 13
    • View Profile
Hello guys,
I am trying to get a script to spawn a ped when i enter an interior, but i'm facing some problems.
I tried studying the lua files for bdorm and etc to try to understand how it spawns npcs but for now it's too complicated ... I can't manage to understand how the Spawnlocation and docklocation works.
So I did a simple lua script.
The problem is, If I get the script to run without a loop in the function or above the main loop, the game will only read my script once so If I don't load the game in the interior the ped is gone and it will not spawn again if I exit the interior. And if I put the script in a loop, the game will spawn too many npcs until the game crashes.

I tried to study Altamurenza's public sources and learn a way to do that but those scripts are something else xD I can't make sense of them. He made a mod with a public source exactly with the functionality I am looking for, he spawned preps in the prephouse, i'm trying to make a mod to make the hideouts populated.

How would you guys do it?

Code: [Select]
Populatedhideout_mod = function()
if AreaGetVisible() == 59 then
local x,y,z = GetPlayerPosXYZ()
local ped = PedCreateXYZ(ID,x,y,z)
PedMakeAmbient(ped)
end
end

Offline SimonBestia

  • Full Member
  • ***
  • Posts: 294
  • Gender: Male
  • Bully-Board's Best Weeb
    • View Profile
    • Youtube Channel
Use a variable to manipulate whether a loop should do its thing or not, like this:
Code: [Select]
while true do
if AreaGetVisible() == 59 and not ConstantinosSpawned then
X, Y, Z = PlayerGetPosXYZ()
Const = PedCreateXYZ(70, X, Y+1, Z)
PedWander(Const)
PedMakeAmbient(Const)
ConstantinosSpawned = true
repeat
Wait(0)
until AreaGetVisible() ~= 59
ConstantinosSpawned = false
end
Wait(0)
end

To spawn peds coming from doors, the game uses a multitude of functions.
I looked into them when Cautious was making his dorm recreation.
I don't quite understand all the arguments in the functions, but you might get away by copying and altering this the way you need:
Code: [Select]
Guys1 = AreaAddAmbientSpawner(10, 3, 0, 1000)
AreaSpawnerSetSexGeneration(Guys1, false, true) -- Males only
AreaAddAmbientSpawnPeriod(Guys1, 7, 0, 125)
AreaAddAmbientSpawnPeriod(Guys1, 12, 30, 30)
AreaAddAmbientSpawnPeriod(Guys1, 16, 0, 300)
Guys2 = AreaAddDocker(10, 2)
AreaSetDockerSexReception(Guys2, false, true)
AreaAddDockPeriod(Guys2, 11, 30, 60)
AreaAddDockPeriod(Guys2, 15, 30, 900)
AreaSetDockerChanceToDock(Guys2, 10)
AreaAddSpawnLocation(Guys1, POINTLIST._BdrDoorDownstairs3, TRIGGER._BdrDoorDownstairs3) -- Pointlists and Triggers can be found in the .DAT files (obviously custom ones need to made yourself). Change the names accordingly.

I should point out that peds won't really do much on their own in these areas as they were never meant to have peds roaming around. You'd have to script all their behaviour yourself.

Offline feliiperh

  • Jr. Member
  • **
  • Posts: 13
    • View Profile
Thanks a lot Simon!
I will check it out the spawn from doors code when I have some more time and start to code the peds behaviour.
I understand I will have to code the path they walk, the anims, they gathering around talking in a circle etc.
I will get back if something come up.
If you know a mod that's opensource and have this kind of code in it, feel free to share here so I can study.

Offline RBS ID

  • Jr. Member
  • **
  • Posts: 67
  • Gender: Male
  • I don't know.
    • View Profile
    • This is website title.
I made a mod like that kind of things. You can check at my Pastebin, https://pastebin.com/nGiqN782

Offline feliiperh

  • Jr. Member
  • **
  • Posts: 13
    • View Profile
I made a mod like that kind of things. You can check at my Pastebin, https://pastebin.com/nGiqN782
Your mods are awesome! I'm using this mod in the moment, it was my inspiration to start this one i'm coding
I first started using your code to spawn in the interiors but for some reason you code doesn't spawn infinite peds when in interior and I simply didn't understand why, that's why i created this post  :laugh:

I see you have the xyz coords to make peds walk, you spawn them in the door and make them walk, and make them walk out when its night ... Very cool. Definetely will use that