Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
|
04-27-2019
, 18:01
Re: How can I do that...?
|
#11
|
The plugin works as it should do but the code that makes the camera look where the user is aiming at (by the player view), makes the camera move weird like an aimbot basically. In relation of sounds and animations, I blocked the animations and recreated every single sound (I might forgot something, but I stopped working on it since online, due the low FPS or lag for some players, it's useless).
PHP Code:
#include <amxmodx> #include <cstrike> #include <fakemeta> #include <engine> #include <hamsandwich> #include <xs>
#define VERSION "0.0.2"
#define MAX_PLAYERS 32 #define USE_TOGGLE 3
const CONST_SHOTGUNS = (1 << CSW_M3)|(1 << CSW_XM1014) const INVALID_WEAPONS = (1 << 2)|(1 << CSW_KNIFE)|(1 << CSW_C4)|(1 << CSW_HEGRENADE)|(1 << CSW_FLASHBANG)|(1 << CSW_SMOKEGRENADE)
const XTRA_OFS_WEAPON = 4 const XTRAS_OFS_PLAYER = 5 const m_pPlayer = 41 const m_fInReload = 54 const m_fInSpecialReload = 55 const m_flTimeWeaponIdle = 48 const m_pActiveItem = 373
new const g_szGunsEvents[][] = { "events/awp.sc", "events/g3sg1.sc", "events/ak47.sc", "events/scout.sc", "events/m249.sc", "events/m4a1.sc", "events/sg552.sc", "events/aug.sc", "events/sg550.sc", "events/m3.sc", "events/xm1014.sc", "events/usp.sc", "events/mac10.sc", "events/ump45.sc", "events/fiveseven.sc", "events/p90.sc", "events/deagle.sc", "events/p228.sc", "events/glock18.sc", "events/mp5n.sc", "events/tmp.sc", "events/elite_left.sc", "events/elite_right.sc", "events/galil.sc", "events/famas.sc" }
new const g_szDeploySounds[][] = { "", "weapons/p228_slidepull.wav", "", "", "", "", "", "weapons/mac10_boltpull.wav", "weapons/aug_forearm.wav", "", "weapons/elite_deploy.wav", "weapons/fiveseven_slidepull.wav", "", "", "weapons/galil_boltpull.wav", "weapons/famas_forearm.wav", "weapons/usp_slideback.wav", "weapons/slideback1.wav", "", "weapons/mp5_slideback.wav", "weapons/m249_chain.wav", "weapons/m3_pump.wav", "weapons/m4a1_deploy.wav", "", "", "", "", "weapons/sg552_boltpull.wav", "weapons/ak47_boltpull.wav", "", "weapons/p90_boltpull.wav" }
new const g_szSoundReload[] = "weapons/generic_reload.wav"
new CAMERA_FORWARD new CAMERA_RIGHT new CAMERA_UP new CAMERA_FRACTION
new g_iGunsEventsBitsum, g_forwardPrecacheEvent
new g_iPlayerCamera[MAX_PLAYERS + 1] new g_szWeaponSoundFmt[36][64], g_szWeaponDifferent[4][64]
public plugin_init() { register_plugin("Camera View AUTOMATIC", VERSION, "ConnorMcLeod") CAMERA_FORWARD = register_cvar("camera_forward", "-100.0") CAMERA_RIGHT = register_cvar("camera_right", "0.0") CAMERA_UP = register_cvar("camera_up", "25.0") CAMERA_FRACTION = register_cvar("camera_fraction", "-35.0") new szWeaponName[20] for(new i = CSW_P228;i <= CSW_P90;i++) { if((1 << i) & INVALID_WEAPONS) continue get_weaponname(i, szWeaponName, charsmax(szWeaponName)) RegisterHam(Ham_Item_Deploy, szWeaponName, "FwdHamWeaponDeploy", 1) if((i == CSW_M3) || (i == CSW_XM1014)) continue RegisterHam(Ham_Weapon_Reload, szWeaponName, "FwdHamWeaponReload", 1) } RegisterHam(Ham_Spawn, "player", "CBasePlayer_Spawn_Post", 1) RegisterHam(Ham_Think, "trigger_camera", "Camera_Think") RegisterHam(Ham_Weapon_Reload, "weapon_m3", "FwdHamShotgunReload", 1) RegisterHam(Ham_Weapon_Reload, "weapon_xm1014", "FwdHamShotgunReload", 1) register_forward(FM_SetView, "SetView") register_forward(FM_UpdateClientData, "fw_UpdateClientData_Post", 1) register_forward(FM_PlaybackEvent, "fwPlaybackEvent") unregister_forward(FM_PrecacheEvent, g_forwardPrecacheEvent, 1) register_clcmd("aaa", "aa") }
public aa(id) { for(new i = 1;i < 32;i++) { if(is_user_alive(i) && is_user_bot(i)) { set_pev(i, pev_flags, pev(i, pev_flags) | FL_FROZEN) } } }
public plugin_precache() { for(new i;i < sizeof g_szDeploySounds;i++) { if(!g_szDeploySounds[i][0]) continue precache_sound(g_szDeploySounds[i]) } new szWeaponName[20], szSound[64] for(new i = CSW_P228;i <= CSW_P90;i++) { if(INVALID_WEAPONS & (1 << i)) continue new bool:bPrecache = true switch(i) { case CSW_SCOUT: formatex(szSound, charsmax(szSound), "weapons/scout_fire-1.wav") case CSW_ELITE: formatex(szSound, charsmax(szSound), "weapons/elite_fire.wav") case CSW_AWP: formatex(szSound, charsmax(szSound), "weapons/awp1.wav") case CSW_USP: { formatex(szSound, charsmax(szSound), "weapons/usp_unsil-1.wav") precache_sound(szSound) copy(g_szWeaponSoundFmt[i], charsmax(g_szWeaponSoundFmt[]), szSound) formatex(szSound, charsmax(szSound), "weapons/usp2.wav") precache_sound(szSound) copy(g_szWeaponDifferent[0], charsmax(g_szWeaponDifferent[]), szSound) bPrecache = false } case CSW_M4A1: { formatex(szSound, charsmax(szSound), "weapons/m4a1_unsil-1.wav") precache_sound(szSound) copy(g_szWeaponSoundFmt[i], charsmax(g_szWeaponSoundFmt[]), szSound) formatex(szSound, charsmax(szSound), "weapons/m4a1-1.wav") precache_sound(szSound) copy(g_szWeaponDifferent[1], charsmax(g_szWeaponDifferent[]), szSound) bPrecache = false } case CSW_GLOCK18: { formatex(szSound, charsmax(szSound), "weapons/glock18-2.wav") precache_sound(szSound) copy(g_szWeaponSoundFmt[i], charsmax(g_szWeaponSoundFmt[]), szSound) formatex(szSound, charsmax(szSound), "weapons/glock18-1.wav") precache_sound(szSound) copy(g_szWeaponDifferent[2], charsmax(g_szWeaponDifferent[]), szSound) bPrecache = false } case CSW_FAMAS: { formatex(szSound, charsmax(szSound), "weapons/famas-2.wav") precache_sound(szSound) copy(g_szWeaponSoundFmt[i], charsmax(g_szWeaponSoundFmt[]), szSound) formatex(szSound, charsmax(szSound), "weapons/famas-burst.wav") precache_sound(szSound) copy(g_szWeaponDifferent[3], charsmax(g_szWeaponDifferent[]), szSound) bPrecache = false } default: { get_weaponname(i, szWeaponName, charsmax(szWeaponName)) if(i == CSW_MP5NAVY) { replace(szWeaponName, charsmax(szWeaponName), "navy", "") } formatex(szSound, charsmax(szSound), "weapons/%s-1.wav", szWeaponName[7]) } } if(bPrecache) { precache_sound(szSound) copy(g_szWeaponSoundFmt[i], charsmax(g_szWeaponSoundFmt[]), szSound) formatex(szSound, charsmax(szSound), "sound/weapons/%s-2.wav", szWeaponName[7]) if(file_exists(szSound)) { precache_sound(szSound[5]) } } } g_forwardPrecacheEvent = register_forward(FM_PrecacheEvent, "fwPrecacheEvent", 1) precache_sound(g_szSoundReload) }
public fwPrecacheEvent(iType, const szName[]) { for(new i;i < sizeof g_szGunsEvents;++i) { if(equal(g_szGunsEvents[i], szName)) { g_iGunsEventsBitsum |= (1 << get_orig_retval()) return FMRES_HANDLED } } return FMRES_IGNORED }
public fwPlaybackEvent(flags, iInvoker, iEventId) { if(!(g_iGunsEventsBitsum & (1 << iEventId)) || !is_user_connected(iInvoker)) return FMRES_IGNORED new iWeaponID = get_user_weapon(iInvoker) if(!iWeaponID) return FMRES_HANDLED new iWeaponEnt = get_pdata_cbase(iInvoker, m_pActiveItem, XTRAS_OFS_PLAYER), szSound[64] if(cs_get_weapon_silen(iWeaponEnt)) { if(iWeaponID == CSW_USP) { copy(szSound, charsmax(szSound), g_szWeaponDifferent[0]) } else if(iWeaponID == CSW_M4A1) { copy(szSound, charsmax(szSound), g_szWeaponDifferent[1]) } } else if(cs_get_weapon_burst(iWeaponEnt)) { if(iWeaponID == CSW_GLOCK18) { copy(szSound, charsmax(szSound), g_szWeaponDifferent[2]) } else if(iWeaponID == CSW_FAMAS) { copy(szSound, charsmax(szSound), g_szWeaponDifferent[3]) } } else copy(szSound, charsmax(szSound), g_szWeaponSoundFmt[iWeaponID])
emit_sound(iInvoker, CHAN_WEAPON, szSound, VOL_NORM, ATTN_NORM, 0, PITCH_NORM) new iTarget, iBody get_user_aiming(iInvoker, iTarget, iBody) if(is_user_alive(iTarget)) return FMRES_IGNORED new Float:fEntityEndPosition[3] getAimEndPosition(iInvoker, fEntityEndPosition) drawSpark(fEntityEndPosition) return FMRES_IGNORED }
public fw_UpdateClientData_Post(id, sendweapons, cd_handle) { if(!is_user_alive(id)) return FMRES_IGNORED set_cd(cd_handle, CD_flNextAttack, get_gametime() + 0.001) return FMRES_HANDLED }
public FwdHamWeaponDeploy(const iWeapon) { static id;id = get_pdata_cbase(iWeapon, m_pPlayer, XTRA_OFS_WEAPON) if(!is_user_connected(id)) return HAM_IGNORED client_cmd(id, "spk ^"%s^"", g_szDeploySounds[cs_get_weapon_id(iWeapon)]) return HAM_IGNORED }
public FwdHamWeaponReload(const iWeapon) { if(get_pdata_int(iWeapon, m_fInReload, XTRA_OFS_WEAPON)) { emit_sound(get_pdata_cbase(iWeapon, m_pPlayer, XTRA_OFS_WEAPON), CHAN_ITEM, g_szSoundReload, VOL_NORM, ATTN_NORM, 0, PITCH_NORM) } }
public FwdHamShotgunReload(const iWeapon) { if(get_pdata_int(iWeapon, m_fInSpecialReload, XTRA_OFS_WEAPON) != 1) return HAM_IGNORED
new Float:flTimeWeaponIdle = get_pdata_float(iWeapon, m_flTimeWeaponIdle, XTRA_OFS_WEAPON) if(flTimeWeaponIdle != 0.55) return HAM_IGNORED emit_sound(get_pdata_cbase(iWeapon, m_pPlayer, XTRA_OFS_WEAPON), CHAN_WEAPON, g_szSoundReload, VOL_NORM, ATTN_NORM, 0, PITCH_NORM) return HAM_IGNORED }
public CBasePlayer_Spawn_Post(id) { if(!is_user_alive(id)) { return } new iEnt = g_iPlayerCamera[id] if(!pev_valid(iEnt)) { static iszTriggerCamera if(!iszTriggerCamera) { iszTriggerCamera = engfunc(EngFunc_AllocString, "trigger_camera") } iEnt = engfunc(EngFunc_CreateNamedEntity, iszTriggerCamera) set_kvd(0, KV_ClassName, "trigger_camera") set_kvd(0, KV_fHandled, 0) set_kvd(0, KV_KeyName, "wait") set_kvd(0, KV_Value, "999999") dllfunc(DLLFunc_KeyValue, iEnt, 0) set_pev(iEnt, pev_owner, id) set_pev(iEnt, pev_spawnflags, SF_CAMERA_PLAYER_TARGET|SF_CAMERA_PLAYER_POSITION) set_pev(iEnt, pev_flags, pev(iEnt, pev_flags) | FL_ALWAYSTHINK) dllfunc(DLLFunc_Spawn, iEnt) g_iPlayerCamera[id] = iEnt new Float:flMaxSpeed, iFlags = pev(id, pev_flags) pev(id, pev_maxspeed, flMaxSpeed) ExecuteHam(Ham_Use, iEnt, id, id, USE_TOGGLE, 1.0) set_pev(id, pev_flags, iFlags) engfunc(EngFunc_SetClientMaxspeed, id, flMaxSpeed) set_pev(id, pev_maxspeed, flMaxSpeed) } }
public SetView(id, iEnt) { if(is_user_alive(id)) { new iCamera = g_iPlayerCamera[id] if(iCamera && iEnt != iCamera) { new szClassName[16] pev(iEnt, pev_classname, szClassName, charsmax(szClassName)) if(!equal(szClassName, "trigger_camera")) // should let real cams enabled { engfunc(EngFunc_SetView, id, iCamera) // shouldn't be always needed return FMRES_SUPERCEDE } } } return FMRES_IGNORED }
public client_disconnected(id) { new iEnt = g_iPlayerCamera[id] if(pev_valid(iEnt)) { engfunc(EngFunc_RemoveEntity, iEnt) } g_iPlayerCamera[id] = 0 }
public client_putinserver(id) { g_iPlayerCamera[id] = 0 }
public Camera_Think(iEnt) { static id if(!(id = pev(iEnt, pev_owner))) { return } static Float:fVecPlayerOrigin[3], Float:fVecCameraOrigin[3], Float:fVecAngles[3], Float:fVecForward[3], Float:fVecRight[3], Float:fVecUp[3] pev(id, pev_origin, fVecPlayerOrigin) pev(id, pev_view_ofs, fVecAngles) fVecPlayerOrigin[2] += fVecAngles[2] pev(id, pev_v_angle, fVecAngles) angle_vector(fVecAngles, ANGLEVECTOR_FORWARD, fVecForward) angle_vector(fVecAngles, ANGLEVECTOR_RIGHT, fVecRight) angle_vector(fVecAngles, ANGLEVECTOR_UP, fVecUp) fVecCameraOrigin[0] = fVecPlayerOrigin[0] + fVecForward[0] * get_pcvar_float(CAMERA_FORWARD) + fVecRight[0] * get_pcvar_float(CAMERA_RIGHT) + fVecUp[0] * get_pcvar_float(CAMERA_UP) fVecCameraOrigin[1] = fVecPlayerOrigin[1] + fVecForward[1] * get_pcvar_float(CAMERA_FORWARD) + fVecRight[1] * get_pcvar_float(CAMERA_RIGHT) + fVecUp[1] * get_pcvar_float(CAMERA_UP) fVecCameraOrigin[2] = fVecPlayerOrigin[2] + fVecForward[2] * get_pcvar_float(CAMERA_FORWARD) + fVecRight[2] * get_pcvar_float(CAMERA_RIGHT) + fVecUp[2] * get_pcvar_float(CAMERA_UP) engfunc(EngFunc_TraceLine, fVecPlayerOrigin, fVecCameraOrigin, IGNORE_MONSTERS, id, 0) static Float:flFraction get_tr2(0, TR_flFraction, flFraction) if(flFraction != 1.0) // adjust camera place if close to a wall { flFraction *= get_pcvar_float(CAMERA_FRACTION) fVecCameraOrigin[0] = fVecPlayerOrigin[0] + (fVecForward[0] * flFraction) fVecCameraOrigin[1] = fVecPlayerOrigin[1] + (fVecForward[1] * flFraction) fVecCameraOrigin[2] = fVecPlayerOrigin[2] + (fVecForward[2] * flFraction) } set_pev(iEnt, pev_origin, fVecCameraOrigin) set_pev(iEnt, pev_angles, fVecAngles) set_pev(id, pev_angles, fVecAngles) new Float:fEntityEndPosition[3] getAimEndPosition(id, fEntityEndPosition) entity_set_aim(iEnt, fEntityEndPosition) }
getAimEndPosition(id, Float:fOrigin[3]) { new Float:fStart[3], Float:fViewOfs[3] pev(id, pev_origin, fStart) pev(id, pev_view_ofs, fViewOfs) xs_vec_add(fStart, fViewOfs, fStart)
new Float:fDest[3] pev(id, pev_v_angle, fDest) engfunc(EngFunc_MakeVectors, fDest) global_get(glb_v_forward, fDest) xs_vec_mul_scalar(fDest, 4096.0, fDest) xs_vec_add(fStart, fDest, fDest)
engfunc(EngFunc_TraceLine, fStart, fDest, DONT_IGNORE_MONSTERS, id, 0) get_tr2(0, TR_vecEndPos, fOrigin) }
entity_set_aim(id, Float:fEndOrigin[3]) { static Float:fOrigin[3] pev(id, pev_origin, fOrigin) static Float:fVec[3] pev(id, pev_view_ofs, fVec) xs_vec_add(fOrigin, fVec, fOrigin) static Float:fLook[3], Float:fLen xs_vec_sub(fEndOrigin, fOrigin, fOrigin) fLen = xs_vec_len(fOrigin) fOrigin[0] /= fLen fOrigin[1] /= fLen fOrigin[2] /= fLen vector_to_angle(fOrigin, fLook) fLook[0] *= -1 set_pev(id, pev_angles, fLook) set_pev(id, pev_fixangle, 1) }
drawSpark(Float:origin[3]) { message_begin(MSG_ALL, SVC_TEMPENTITY) write_byte(TE_SPARKS) engfunc(EngFunc_WriteCoord, origin[0]) engfunc(EngFunc_WriteCoord, origin[1]) engfunc(EngFunc_WriteCoord, origin[2]) message_end() message_begin(MSG_BROADCAST,SVC_TEMPENTITY) write_byte(TE_WORLDDECAL) engfunc(EngFunc_WriteCoord, origin[0]) engfunc(EngFunc_WriteCoord, origin[1]) engfunc(EngFunc_WriteCoord, origin[2]) write_byte(random_num(41, 45)) message_end() }
__________________
Last edited by EFFx; 04-27-2019 at 18:35.
|
|