I'm trying to put together a plugin that lets me switch between different cameras.
It will be used to "shoot" a tournament that will be streamed live on twitch.
I have taken apart a plugin I found here called "spectator camera".
Just to see what I could do, I added some coordinates from a file created by "map spawn editor".
It sort of worked, I can switch to a camera but the coordinates are not the same as the spawn point.
And there is no angle to it, so it is just sitting close to the skybox aiming straight forward.
The idea is that I want to be able to press different keys and switch between different shots.
What am I doing wrong? And how do I get the coordinates (including angles) that I need?
Code:
#include <amxmodx>
#include <fakemeta>
new MODEL[] = "models/player/vip/vip.mdl";
new giCameraEntity;
new bool:gbCameraActive[33];
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR);
register_clcmd("+camera", "CameraActivate");
CameraInit();
}
public plugin_precache()
precache_model(MODEL);
public CameraInit() {
giCameraEntity = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target")); // Create Camera Entity
set_pev(giCameraEntity, pev_classname, "Multiply_Camera"); // Give the Camera a name
set_pev(giCameraEntity, pev_solid, SOLID_NOT); // Make the Camera semiclip
engfunc(EngFunc_SetModel, giCameraEntity, MODEL); // Set Camera Model (Needed, for EngFunc_SetView to work properly)
set_pev(giCameraEntity, pev_movetype, MOVETYPE_FLY); // Stop the Camera from dropping on the ground
set_pev(giCameraEntity, pev_health, 1.0); // Set Camera health to 1
set_pev(giCameraEntity, pev_takedamage, 0.0); // Make Camera invincible
set_pev(giCameraEntity, pev_rendermode, 5); // Fix rendermode
set_pev(giCameraEntity, pev_renderamt, 0.0); // Make it less visable
set_pev(giCameraEntity, pev_angles, Float:{0.0, 180.0, 0.0}); // Test using angles
CameraSetOrigin(Float:{438.2510, 142.0, 312.0}); // ( This is where I placed my coordinates from the spawn editor plugin .cfg)
}
public CameraSetOrigin(Float:fOrigin[3]) {
new Float:fMins[3], Float:fMaxs[3];
pev(giCameraEntity, pev_mins, fMins);
pev(giCameraEntity, pev_maxs, fMaxs);
engfunc(EngFunc_SetSize, giCameraEntity, fMins, fMaxs);
return engfunc(EngFunc_SetOrigin, giCameraEntity, fOrigin);
}
public CameraActivate(iPlayerId) {
engfunc(EngFunc_SetView, iPlayerId, giCameraEntity);
gbCameraActive[iPlayerId] = true;
client_print(iPlayerId, print_chat, "[Camera] Has just been enabled.");
}
stock entity_set_aim(ent,const Float:origin2[3],bone=0)
{
if(!pev_valid(ent))
return 0;
static Float:origin[3]
origin[0] = origin2[0]
origin[1] = origin2[1]
origin[2] = origin2[2]
static Float:ent_origin[3], Float:angles[3]
if(bone)
engfunc(EngFunc_GetBonePosition,ent,bone,ent_origin,angles)
else
pev(ent,pev_origin,ent_origin)
origin[0] -= ent_origin[0]
origin[1] -= ent_origin[1]
origin[2] -= ent_origin[2]
static Float:v_length
v_length = vector_length(origin)
static Float:aim_vector[3]
aim_vector[0] = origin[0] / v_length
aim_vector[1] = origin[1] / v_length
aim_vector[2] = origin[2] / v_length
static Float:new_angles[3]
vector_to_angle(aim_vector,new_angles)
new_angles[0] *= -1
if(new_angles[1]>180.0) new_angles[1] -= 360
if(new_angles[1]<-180.0) new_angles[1] += 360
if(new_angles[1]==180.0 || new_angles[1]==-180.0) new_angles[1]=-179.999999
set_pev(ent,pev_angles,new_angles)
set_pev(ent,pev_fixangle,1)
return 1;
}