How to have a custom turret skin in your map

Avatar
walropodes
39 Posts
Posted Jun 24, 2011
Hey!

For this tutorial you'll need:

  • Notepad++- Squirrel syntax highlighter for Notepad++, installation instructions should be on the linked article- GCFScape- The latest version of VTFEdit, so you can edit Portal 2's textures
    Navigate to your steamapps/common/portal 2/portal2/ folder, and open pak01_dir.vpk with GCFScape. Navigate to models > npcs > turret, then extract the turret.* files into your portal2 folder (preserving the structure, so you should make a models/npcs/turret/ folder for the extracted turret)

Now, rename them to something unique. I'll rename them to turret_red, so turret_red.mdl turret_red.vtx etc.

Then extract materials > models > npcs > turret from the VPK into your Portal 2 folder, preserving structure like with the model file.

The texture file I want to edit right now is turret_casing.vtf, so we do a crucial step: renaming it. **The new name of the texture MUST** be the same length as the old name. I'll call it turrrt_casing.vtf, be sure to rename turret_casing.vmt, and edit it so it points to the new texture name;

VertexLitGeneric
{
$baseTexture "models/npcs/turret/turret_casing"
$surfaceprop solidmetal
$phong 1
$phongexponent 50
$phongfresnelranges "[5 1 2]"
$phongboost ".6"
$basemapalphaphongmask 1
}

would become:

VertexLitGeneric
{
$baseTexture "models/npcs/turret/turrrt_casing"
$surfaceprop solidmetal
$phong 1
$phongexponent 50
$phongfresnelranges "[5 1 2]"
$phongboost ".6"
$basemapalphaphongmask 1
}

Now we're ready to edit the model. Open turret_red.mdl in Notepad++ and search for "turret_casing", then edit it to "turrrt_casing". If you do not pick a name that is the same length as the old one, the model will break.

img

Edit turrrt_casing.vtf/vmt to your heart's content. Here's what mine looks like:

img

Now for the next part: the VScripts.

Navitate to portal2/scripts/vscripts, make a folder called "modelchanger" then in there make a file called "turret_red.nut" and put this text in and save:

function ChangeTurrets(){
   Entities.FindByClassname(null, "npc_portal_turret_floor").SetModel("models/npcs/turret/turret_red.mdl");
}

Now for the Hammer step.

Load up a map you wanna put a custom turret in, and place a prop_dynamic somewhere you don't think a player will see it and give it the custom turret model. This loads the model into memory so the vscript is able to change the turret's model.

img

Then place a logic_script, name it something and point it to the vscript we just made. (modelchanger/turret_red.nut)

img

Make a logic_auto, give it an OnMapSpawn output, tell it to make the logic_script execute the ChangeTurrets() function.

img

Compile, run then you should have a custom turret! Here's my red turret right beside a console-spawned turret:
img

Note: The turret has more textures than turret_casing.vmt, so you'll have to edit those too. You should also be able to use this method with other ents you can't normally skin, like npc_personality_core
If you have any questions or ideas on how to improve this tutorial, fire away :smile:

Advertisement
Registered users don’t see ads! Register now!
Avatar
KenJeKenny!?
238 Posts
Posted Jun 24, 2011
Replied 1 hour later
There was somebody who posted all of the crazy turret skin models. So not just the coloured ones but more (all that you can see in the turret movie vgui)
Avatar
walropodes
39 Posts
Posted Jun 24, 2011
Replied 2 minutes later
Are you referring to this? You could port these over to P2 but they're actually skins for the P1 turret
Avatar
KenJeKenny!?
238 Posts
Posted Jun 24, 2011
Replied 2 hours later
Yeh those are the ones i mean...

Would i be able to add those turrets to the game/hammer using your method? or does that require a different method?

And when using your method did you simply recreate a skin for the original turret model or a completely new turret model?

Avatar
-ArttyIntel-
76 Posts
Posted Jun 24, 2011
Replied 10 hours later
I was thinking about doing this. Like having reg turrets being white like usual. Then have stronger turrets that are red. So you can tell the difference.
Avatar
h3X
12 Posts
Posted Jun 28, 2011
Replied 4 days later
No wonder I wasn't able to just use the textures right out of the box. Thanks a million, I would've never been able to figure this out without this awesome tutorial!
Avatar
walropodes
39 Posts
Posted Jun 28, 2011
Replied 3 hours later
No problem! :biggrin:

KenJeKenny!? wrote:
Yeh those are the ones i mean...

Would i be able to add those turrets to the game/hammer using your method? or does that require a different method?

And when using your method did you simply recreate a skin for the original turret model or a completely new turret model?

I made a new skin using portal 2's turret model. Also P2's textures use a completely different texture layout from Portal's turrets so you're going to need to remake those skins in Portal 2 (or ask the creator of those turret skins to) if you wanna use 'em

Avatar
Groxkiller585
652 Posts
Posted May 24, 2012
Replied 10 months later
When I try running the script I get an error about the index not existing.

EDIT: And I just now realize how old this thread is, crap!

I do want to do this however, is there a way to make this work? The script is broken for me.

Avatar
ChickenMobile
2,460 Posts
Posted May 24, 2012
Replied 1 hour later
What error is the script giving you? (If any)
Avatar
Groxkiller585
652 Posts
Posted May 24, 2012
Replied 1 hour later

chickenmobile wrote:
What error is the script giving you? (If any)

I posted it, it complains the index "ChangeTurrets" doesn't exist. I know I spelled it right in the script and in Hammer, so I'm not sure what's wrong.

Avatar
ChickenMobile
2,460 Posts
Posted May 24, 2012
Replied 9 minutes later

That may be displayed beacuse:

  • The script you are referencing is wrong in the logic_script. E.g. the script isn't even listed in the Entity Scripts field.- There is a syntax error- You are trying to RunScriptCode ChangeTurrets not ChangeTurrets()- Some other obscure reason which is not listed here.
Avatar
FelixGriffin
2,680 Posts
Posted May 24, 2012
Replied 35 minutes later
Don't turrets support normal studiomodel keyvalues if model is set to "unused"?
Avatar
Brainstone
401 Posts
Posted May 25, 2012
Replied 9 hours later
Hey. You are right FelixGriffin. I just tried it. I set the model to unused, ans afterwards created a new key named 'model' with my custom model path.
Thanks, that saved me from having to use a custom script.
Avatar
CamBen
973 Posts
Posted May 25, 2012
Replied 11 hours later
does the mdl text changing work with XVI32?
Avatar
FourthReaper
356 Posts
Posted May 25, 2012
Replied 2 hours later

CamBen wrote:
does the mdl text changing work with XVI32?

Should work, yes. But then again, so does editing it with Notepad++. The things you can read, at least, are changeable. :wink:

Avatar
Scathach
5 Posts
Posted Jul 02, 2012
Replied 1 month later
I'm kinda new and I can't open the pak01_dir.vpk file with GCFspace.
Any reccomendations?
Avatar
FelixGriffin
2,680 Posts
Posted Jul 02, 2012
Replied 1 hour later
Get the newest version of GCFscape, or Validate the file.
Avatar
Skotty
671 Posts
Posted Jul 02, 2012
Replied 47 minutes later
There is another method to change the turret skin in your own map.
If you want to replace ALL turrets with that new skin, it's enough to pack the original VMT into the map but change it's path.

I just did this in a map for Garry's Mod.
It seems like the game will ever use the VTFs given by the GCF/VPK. But, at least in the "older" Source games, the VMT of the BSP has the higher priority.

Just make a copy of the turret VMT into your map and change the path of $basetexture to your new VTF.
(I hope I don't mix something up, but it should be right).

So you don't need to hex any model or to use any script.

Avatar
FelixGriffin
2,680 Posts
Posted Jul 02, 2012
Replied 21 minutes later
But isn't it VPK > BSP > GCF? So it works in the older games but not in AS or P2?
Advertisement
Registered users don’t see ads! Register now!
Avatar
Scathach
5 Posts
Posted Jul 03, 2012
Replied 7 hours later
I'm so sorry, I probably look like an idiot but this is the first time I ever tried to modify something in a game. How can I validate a file?