Call of Duty: Black Ops III

Call of Duty: Black Ops III

Not enough ratings
[Scripting] Dynamically Placing Models
By Mysti and 1 collaborators
   
Award
Favorite
Favorited
Unfavorite
Introduction
Hey guys, yet another tutorial from me, this one is a follow up to my FX tutorial, this is how you place models dynamically through scripting. I shouldn't really need to explain it all to much, so let's get into it.
Radiant Requirements [Optional]
So, as the title says this section is optional, this if you want to put a model in a specific place E.G. behind a door or something. If you want to randomly spawn one it's up to you to make sure it's in the bounds of the map, but oh well. Let's get into it.

First off, find the model or models you want to spawn, I'm going to use the Jugg bottle. I'm using APE to find out what it's xModel name is, so for me it's model name is
t6_wpn_zmb_perk_bottle_jugg_world

You can find it out by searching for the model in APE and here

Now, we need to add it to the zone file of our map, so as I said in my FX tutorial the zone file can be found by either navitgating to it, or right clicking on your map then saying edit zone file. Once it's opened in your editor of choice we need to tell the compiler we're using a model, so we have to hadd the line
xmodel,*MODEL NAME*

So my line would be
xmodel,t6_wpn_zmb_perk_bottle_jugg_world

That's that, now you can save your zone file and we're good to go. Now open up Radiant.You're going to want to drag a Script Origin

To where you want your model to show up, now take a note, this is the optional part, if you already know where you want to spawn it with specific origins it's up to you. But if you want it spawned this easy way continue going. Once you've placed the origin where you want it give it a targetname you can remember, we'll be giving it "ModelSpawnLoc" now you can save your map and close radiant. If you're a smart cookie you might have noticed you can call Hide() or Show() on this, that will work just fine given a few other lines of code but I am going to cover it below for those who didn't catch it.
Scripting Requirements
First off, I'm not going to show you how you set up the GSC file, to get this to work, I am only going to show you how to spawn models dynamically. So here goes, at the top of your GSC file under your #usings directives add the line
#precache("model","MODEL NAME");

So my line would be
#precache("model","t6_wpn_zmb_perk_bottle_jugg_world");

This is telling the game we want to use that model somewhere in our code so it loads it up and gets it ready for us, now off we go. The code I am going to supply will be valid, but will require you to code your own way of triggering it, the easist way would be to make it happen after interacting with a trigger. Anyway, here goes.
OriginEnt = GetEnt("ModelSpawnLoc","targetname"); OriginEnt SetModel("t6_wpn_zmb_perk_bottle_jugg_world");

Anti-climatic I know, but that will set the model of the Script Origin we placed to the jug model, if you used a Misc Model and set it's model manually in Radiant you'd use this code
OriginEnt = GetEnt("ModelSpawnLoc","targetname"); OriginEnt Show();
This is taking account if you've hidden it at the start of your code using
OriginEnt = GetEnt("ModelSpawnLoc","targetname"); OriginEnt Hide();
I'd stick with the first one presonally as it doesn't require you to hide it before showing it again.

A little side note, you can precahce multiple models and make the Script Orgin rotate between them by using SetModel, just put all the models in an array like so
Models = []; Models[0] = ""; Models[1] = ""; Models[2] = ""; OriginEnt = GetEnt("ModelSpawnLoc","targetname"); OriginEnt SetModel(Models[RandomInt(Models.size)]);
You'll need to precache and add to your zone file whatever models you added to your list or it will either not show up in game or show up as a black rectangle.
Final Words
Thanks for reading another one of my tutorials, I'm not sure if these are easy to read or not as they're focused on how I learn not a general way, I want to expand into other tutorials of stuff I know, but I am trying to stick to generic stuff at the moment so when I do go into specific stuff I can refer back to these if people are lost. Either or we'll see where I go.

Thanks, Johnathon.
1 Comments
Farmer 11 Jan, 2017 @ 7:40am 
nice to see someone posting guides here thanks man