Jump to content

Search the Community

Showing results for tags 'suburbsdistribution'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • News & Announcements
    • News
  • Project Zomboid
    • PZ Updates
    • General Discussions
    • Bug Reports
    • PZ Support
    • PZ Multiplayer
    • PZ Community & Creativity
    • PZ Suggestions
  • PZ Modding
    • Tutorials & Resources
    • Mods
    • Items
    • Mapping
    • Mod Ideas and Requests
  • General Games Development
    • Indie Scene
  • Other Discussions
    • General Discussion
    • Forum Games & Activities

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Twitter


Interests

Found 1 result

  1. First, this all comes from NCrawler, who seems to have left the community 6 months back. It's from a beta of his YAWM that never was released. I have it since I was a beta tester for him at the time he left. The purpose of this is to allow the modder far more flexibility in how his items are spawned, when, and with what. It also allows a modder to set values lower than 0.01 for probability, in fact as low as desired (1 in 10,000, okay!). Some of this has been heavily altered by me for personal use with the KY firearms mod that's currently out in this forum, but it can work with any items mod you like. This works through the media\lua\server\Items subfolder. Add this to the bottom to start. The random value generator is used an awful lot, and the Events line is what calls the script to run each time a container is "filled" by the game engine. Without that, nothing will happen. --From RoboMat's RMUtility Modfunction rnd(_value) return ZombRand(_value) + 1;endEvents.OnFillContainer.Add(spawnNCStuff);Next is the main function. Note that "OnFillContainer" will pass 3 values to this, the room name (the first value we see in SuburbsDistribution tables, like "kitchen"), the type of container (the second value, "all" or "metal_shelves"), and the specific container being filled: function spawnNCStuff(_roomName, _containerType, _containerFilled)-- ALL THE IF AND WHILE LOOPS DISCUSSED BELOW GO IN HEREendNow we can use these in IF statements to specify when to spawn things depending on room type or container type: if _containerType == "wardrobe" then-- STUFFend if _roomName ~= "kitchen" then if _containerType == "counter" or _containerType == "locker" or _containerType == "metal_shelves" then-- STUFFendendWithin these, we can set how rare the spawn is thusly: --Roll for firearm (0.2% chance) if rnd(1000) >= 999 then-- STUFFendThe next part is a bit trickier. It requires two things. First, the code within the above IF statements. Second, a separate array outside of this entire function. Let's start with the array. Here's an example for guns and their respective ammo: gun_array = { "RKFmod.ColtPython", "RKFmod.TaurusModel444RagingBull", "RKFmod.Kimber1911", "RKFmod.Ruger1022ArchangelNomad", "RKFmod.Ruger1022", "RKFmod.MarlinModel795", "RKFmod.MarlinModel795", "RKFmod.MarlinModel795", "RKFmod.MarlinModel795",};ammo_array = { "RKFmod.357Mrounds", "RKFmod.44rounds", "RKFmod.45rounds", "RKFmod.Ruger1022ArchangelNomadMag", "RKFmod.Ruger1022Mag", "RKFmod.MarlinModel795Mag", "RKFmod.MarlinModel795Mag", "RKFmod.MarlinModel795Mag", "RKFmod.MarlinModel795Mag",};Notice how the first member of the array in gun_array matches the first member of ammo_array, and so on to the end? This is important if you want to spawn matching items together. Also notice how we've had the Marlin 795 repeated 3 times, so it takes up 4 of the 8 choices? That means it has a 50% chance of spawning IF any gun is spawned from its array. This is how to make specific entries more or less likely within the array. Now, let's assume we have several such paired arrays, one for long rifles, one for pistols, one for AR-15s, etc. We want to choose randomly which to pick from when spawning. Next the code for the main function: weaponType = rnd(100); if weaponType <= 50 then --pistols-- STUFF elseif weaponType > 50 and weaponType <= 90 then --rifles-- STUFF elseif weaponType > 90 then --AR-15s-- STUFF endSo here you can see we are choosing between which set of arrays to spawn from. Next, to pick a member of the array to spawn: gun_Index = rnd(#gun_array); _containerFilled:AddItem(gun_array[gun_index]);#gun_array means that it counts the number of entires in our gun_array. The rnd function picks a random number within that range. Then we have the main "doer" of this whole thing, the AddItem() command. This adds in the selected item to the specific container. You could just replace (gun_array[gun_index]) with ("mymod.my_gun") and it'd work just as well. Now here's a fun twist. You can add specific ammo/magazines/etc to the spawn as well: NCY_ammovar = rnd(100); if NCY_ammovar >= 40 then --Add 1 magazine for that weapon(60% chance) _containerFilled:AddItem(ammo_array[gun_index]); if NCY_ammovar >= 75 then --Another mag (25% chance) _containerFilled:AddItem(ammo_array[gun_index]); if NCY_ammovar >= 92 then --2 more mags (8% chance) _containerFilled:AddItem(ammo_array[gun_index]); _containerFilled:AddItem(ammo_array[gun_index]); end end endLet's walk through that a bit slowly. First, we have a new random value, this is just used to see if we want to spawn something or not. You could just make this 100, so something always spawns (or nix the IF statements and just follow with an AddItem() command). But here it's random, and the first checks to see if it's >= 40, which means 60% of the time we'll get ammo spawned with the gun. Notice that we're using the SAME gun_index value as before, we haven't rerandomized it, but now with the ammo array? Yes, this is how we get a matching gun/magazine/ammo spawn. Then you can see that there are two additional IF checks, for rarer likelihood of further spare ammo. This can be tailored however you like, once you understand the basic syntax of what's going on here. There's a lot more you can do with this stuff, like spawning a melee if a gun doesn't spawn, using an ELSE statement that follows the original IF statement way above. Sky's the limit. I'm not going to say this is the most streamlined code imaginable, but it works and it's pretty easy to edit on the fly and adjust to how you like it. Anyway, let's look at a finished version of what we just did (different names for some things, but exact same structure/commands): This was altered by me to work with the KY firearms mod, for personal use. I guess now it's open to all. I will also post the original YAWmod lua if anyone wants to experiment with thatj. NOTE: You will want to get rid of all the... table.insert(SuburbsDistributions["garagestorage"]["all"].items, "RKFmod.BoxOf22");...type code if you want to do this, or at least that which is relevant to what you're trying to achieve with these functions. Anyway, thanks should go to NCrawler, wherever he is, as far as I know he was the one to come up with this approach and code for this game.
×
×
  • Create New...