Need help spawning a WAC Aircraft on a non-sandbox Gamemode

I’m trying to figure out how to spawn a WAC Aircraft on my gamemode like the title says. I’ve tried to search for a way to do it on google and I haven’t been able to find anything, so hopefully someone here knows how. This is what I have so far.



concommand.Add("spawnapache", function(ply)
local Vehicle = ents.Create( "i dont know" ); //Dont know what the type of vehicle should be

	if ( !IsValid( Vehicle ) ) then return; end

	Vehicle:SetPos(Vector(4607, 0, -8575));
	Vehicle:SetAngles(Angle(0, 90, 0)); 
	Vehicle:SetModel( "models/sentry/apache.mdl" );
	//Vehicle:SetColor(Color(40,40,40, 255))
	Vehicle:SetKeyValue( "vehiclescript", "lua/entities/wac_hc_ah64d_longbow" ); //pretty sure this isn't right
	Vehicle:Spawn( );
	Vehicle:Activate( );
	ply:PrintMessage(3, "Enjoy! Asshole.")
end)

I don’t know what ents.Create should be, or what to put for the script because there is no text file in a scripts folder I can find, only a lua file for each aircraft with the init, cl_init and shared files.

If you know how this can be done then please help me out.

I’m pretty sure WAC, like SCARs, use their own entities. They should be in entities/entities/ folder; if they’re in a .gma, use a gma explorer tool, extract it, or grab the contents via local _files, _folders = file.Find( “*”, v.title );

Basic info on extracting ( not fully typed up, but the links should be fine. )
https://dl.dropboxusercontent.com/u/26074909/tutoring/server_srcds_steamcmd/extracting_addons_to_remove_lua_etc.lua.html

I know how to use gma extracter, which is how I got the model and why I said, “there is no text file in a scripts folder I can find, only a lua file for each aircraft with the init, cl_init and shared files.”

Just extracting the file isn’t really helping me. I’ve tried to look through the lua files some of the apache helicopter I am trying to spawn, but I’m not experienced at all in actually scripting entities so I don’t know how I can find the type of entity I need to put in ents.Create() and also like I said in all of the vehicles I’ve spawned before there was a folder called scripts that contained 1 text file that is put in SetKeyValue(), but in WAC there is only a lua folder that contains the init, cl_init and shared files, so I’m confused.

Thanks for trying to help Acecool, but if anyone really knows how to spawn WAC Aircraft then please help me out.

The folder name is the name of the entity that you spawn with ents.Create( “entity_name” );

The way it works is this ( all are the same… Look for the patterns in the folder names, the way GM loads everything is via virtual directories. All of them get merged together virtually )…

garrysmod/addons/<addon_name>/lua/entities/<entity_name_as_file>.lua – This is a SHARED REALM file
garrysmod/addons/<addon_name>/lua/entities/<entity_name_as_folder>/ – This directory should contain init.lua SERVER REALM file, cl_init.lua CLIENT REALM file, and shared.lua SHARED REALM file.

garrysmod/addons/<addon_name>/lua/weapons/<weapon_name_as_file>.lua – This is a SHARED REALM file
garrysmod/addons/<addon_name>/lua/weapons/<weapon_name_as_folder>/ – This directory should contain init.lua SERVER REALM file, cl_init.lua CLIENT REALM file, and shared.lua SHARED REALM file.

garrysmod/lua/entities/ – Works the same as above, just a different location…
garrysmod/lua/weapons/ – Works the same as above, just a different location…

garrysmod/gamemodes/<gamemode_name>/entities/entities/ – Works the same as above, just a different location…
garrysmod/gamemodes/<gamemode_name>/entities/weapons/ – Works the same as above, just a different location…

How addons work:
garrysmod/addons/<addon_name>/lua/autorun/ – Any files inside the folder is automatically included on the CLIENT and the SERVER, and AddCSLuaFile’d on the SERVER – SHARED REALM
garrysmod/addons/<addon_name>/lua/autorun/client/ – Any files inside the folder is automatically included on the CLIENT, and AddCSLuaFile’d on the SERVER – CLIENT REALM
garrysmod/addons/<addon_name>/lua/autorun/server/ – Any files inside the folder is automatically included on the SERVER – SERVER REALM

garrysmod/lua/autorun/ – Works the same as above, just a different location…
garrysmod/lua/autorun/client/ – Works the same as above, just a different location…
garrysmod/lua/autorun/server/ – Works the same as above, just a different location…

Hopefully this helps a bit. If not, here are some more examples:

https://dl.dropboxusercontent.com/u/26074909/tutoring/_zipped_code/acecool_npc_jointeam_example.rar
File structure:

// You can use this as the entity
acecool_npc_jointeam_example/lua/entities/npc_jointeam.lua

OR

// these 3 files ( both are not needed and both should not be there )
acecool_npc_jointeam_example/lua/entities/npc_jointeam/cl_init.lua
acecool_npc_jointeam_example/lua/entities/npc_jointeam/sv_init.lua
acecool_npc_jointeam_example/lua/entities/npc_jointeam/shared.lua

// Read this so you understand; either folder OR file of the same name, one should be removed.
acecool_npc_jointeam_example/lua/entities/npc_jointeam_readme.txt

acecool_npc_jointeam_example/lua/autorun/ – NO FILES, no shared files for the net/receiver/sender part of the example
acecool_npc_jointeam_example/lua/autorun/client/ – 1 file: cl_npc_jointeam.lua
acecool_npc_jointeam_example/lua/autorun/server/ – 1 file: sv_npc_jointeam.lua

Here is another for TTT, end round music with music files in place: https://dl.dropboxusercontent.com/u/26074909/tutoring/_zipped_code/acecool_ttt_end_round_music.rar
No NPCs, no entities, just autorun code for all 3 realms… Client, Shared and Server in addition to content/sound/ where the audio files reside.

Because of the way the virtual directory system is built, you can have a game-mode in an addon folder, you can have a game-mode in the gamemodes folder, you can put audio in an addon, in the base garrysmod/sound/ directory, in gamemodes/<gm_name>/content/sound/, etc etc… Find the patterns, it’s all the same.

For your apache:


concommand.Add("spawnapache", function(ply)
	local Vehicle = ents.Create( "wac_hc_ah64d_longbow" ); //Dont know what the type of vehicle should be -- Yes you do, you found it. Good intuition.

	// Good, error checking is good!
	if ( !IsValid( Vehicle ) ) then return; end

	// Spawn position and angle are required!
	Vehicle:SetPos( Vector( 4607, 0, -8575 ) );
	Vehicle:SetAngles( Angle( 0, 90, 0 ) ); 

	// You may not need to set the model, it should be defined in the entity
	// Vehicle:SetModel( "models/sentry/apache.mdl" );

	// May work, may not work, it depends on the skin
	// Vehicle:SetColor( Color( 40, 40, 40, 255 ) );
	// Vehicle:SetSkin( 1 ); 1 to how ever many skins the vehicle has you can choose from

	// Not needed
	-- Vehicle:SetKeyValue( "vehiclescript", "lua/entities/wac_hc_ah64d_longbow" ); //pretty sure this isn't right -- You're right, this is NOT right. BUT you located the correct ENTITY to spawn in ents.Create. This vehiclescript is for prop_vehicle_jeep / prop_vehicle_airboat entities like TDM cars, which require a vehiclescript.txt ( yes TXT ) which contains all the information about how the vehicle handles.

	// Spawn AND Activate; excellent. If you spawn a prop_vehicle_airboat and do not Activate, it'll crash the server.
	Vehicle:Spawn( );
	Vehicle:Activate( );

	// Nicely done..
	ply:PrintMessage(3, "Enjoy! Asshole.")
end)
	

WAC can be found at here and here, to find the entity names.

[editline]27th October 2014[/editline]

For example, the MH-6 is ‘wac_hc_littlebird_mh6’ - so you’d need to do ents.Create(“wac_hc_littlebird_mh6”)

Thanks so much for the help Acecool! It never ceases to amaze me how some people are kind enough to not just fix errors in a op’s code but actually explain it in extreme detail, in order to really help the person understand how the system works. I have the vehicles spawning, and you were right, you don’t need to put in the script or even the model. Here is my code now:


concommand.Add("spawnapache", function(ply)
local Vehicle = ents.Create( "wac_hc_littlebird_h500" );

	if ( !IsValid( Vehicle ) ) then return; end

	Vehicle:SetPos(Vector(4607, 0, -8575));
	Vehicle:SetAngles(Angle(0, 90, 0)); 
	Vehicle:Spawn( );
	Vehicle:Activate( );
end)

I have a couple more questions but I will make a new post for them just in case you aren’t on, so that other people wont have to read through this whole one.