| 4082 | */ |
| 4083 | |
| 4084 | static void NPC_Spawn_f(void) |
| 4085 | { |
| 4086 | gentity_t *NPCspawner = G_Spawn(); |
| 4087 | vec3_t forward, end; |
| 4088 | trace_t trace; |
| 4089 | qboolean isVehicle = qfalse; |
| 4090 | |
| 4091 | if(!NPCspawner) |
| 4092 | { |
| 4093 | gi.Printf( S_COLOR_RED"NPC_Spawn Error: Out of entities!\n" ); |
| 4094 | return; |
| 4095 | } |
| 4096 | |
| 4097 | NPCspawner->e_ThinkFunc = thinkF_G_FreeEntity; |
| 4098 | NPCspawner->nextthink = level.time + FRAMETIME; |
| 4099 | |
| 4100 | char *npc_type = gi.argv( 2 ); |
| 4101 | if (!npc_type || !npc_type[0] ) |
| 4102 | { |
| 4103 | gi.Printf( S_COLOR_RED"Error, expected:\n NPC spawn [NPC type (from NCPCs.cfg)]\n" ); |
| 4104 | return; |
| 4105 | } |
| 4106 | |
| 4107 | if ( !Q_stricmp( "vehicle", npc_type ) ) |
| 4108 | {//spawning a vehicle |
| 4109 | isVehicle = qtrue; |
| 4110 | npc_type = gi.argv( 3 ); |
| 4111 | if (!npc_type || !npc_type[0] ) |
| 4112 | { |
| 4113 | gi.Printf( S_COLOR_RED"Error, expected:\n NPC spawn vehicle [NPC type (from NCPCs.cfg)]\n" ); |
| 4114 | return; |
| 4115 | } |
| 4116 | } |
| 4117 | |
| 4118 | //Spawn it at spot of first player |
| 4119 | //FIXME: will gib them! |
| 4120 | AngleVectors(g_entities[0].client->ps.viewangles, forward, NULL, NULL); |
| 4121 | VectorNormalize(forward); |
| 4122 | VectorMA(g_entities[0].currentOrigin, 64, forward, end); |
| 4123 | gi.trace(&trace, g_entities[0].currentOrigin, NULL, NULL, end, 0, MASK_SOLID, (EG2_Collision)0, 0); |
| 4124 | VectorCopy(trace.endpos, end); |
| 4125 | end[2] -= 24; |
| 4126 | gi.trace(&trace, trace.endpos, NULL, NULL, end, 0, MASK_SOLID, (EG2_Collision)0, 0); |
| 4127 | VectorCopy(trace.endpos, end); |
| 4128 | end[2] += 24; |
| 4129 | G_SetOrigin(NPCspawner, end); |
| 4130 | VectorCopy(NPCspawner->currentOrigin, NPCspawner->s.origin); |
| 4131 | //set the yaw so that they face away from player |
| 4132 | NPCspawner->s.angles[1] = g_entities[0].client->ps.viewangles[1]; |
| 4133 | |
| 4134 | gi.linkentity(NPCspawner); |
| 4135 | |
| 4136 | NPCspawner->NPC_type = Q_strlwr( G_NewString( npc_type ) ); |
| 4137 | NPCspawner->NPC_targetname = G_NewString(gi.argv( 3 )); |
| 4138 | |
| 4139 | NPCspawner->count = 1; |
| 4140 | |
| 4141 | NPCspawner->delay = 0; |
no test coverage detected