AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [Help] 3rd View shoot accuracy (Not Solved) (https://forums.alliedmods.net/showthread.php?t=240467)

dias 05-16-2014 02:56

[Help] 3rd View shoot accuracy (Not Solved)
 
I have this code
PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <fakemeta_util>
#include <hamsandwich>
#include <xs>

#define VERSION "0.0.2"

#define MAX_PLAYERS    32

#define USE_TOGGLE 3


#define CAMERA_FORWARD -35.0
#define CAMERA_RIGHT 30.0
#define CAMERA_UP 10.0
#define CAMERA_FRACTION -35.0

new g_iPlayerCamera[MAX_PLAYERS+1]

new 
g_iMaxPlayers

public plugin_init()
{
    
register_plugin("Camera View AUTOMATIC"VERSION"ConnorMcLeod")
    
    
RegisterHam(Ham_Spawn"player""CBasePlayer_Spawn_Post"1)
    
register_forward(FM_SetView"SetView")
    
RegisterHam(Ham_Think"trigger_camera""Camera_Think")
    
    
g_iMaxPlayers get_maxplayers()
}

public 
CBasePlayer_Spawn_Postid )
{
    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_CreateNamedEntityiszTriggerCamera)
        
set_kvd(0KV_ClassName"trigger_camera")
        
set_kvd(0KV_fHandled0)
        
set_kvd(0KV_KeyName"wait")
        
set_kvd(0KV_Value"999999")
        
dllfunc(DLLFunc_KeyValueiEnt0)
        
        
set_pev(iEntpev_spawnflagsSF_CAMERA_PLAYER_TARGET|SF_CAMERA_PLAYER_POSITION)
        
set_pev(iEntpev_flagspev(iEntpev_flags) | FL_ALWAYSTHINK)
        
        
dllfunc(DLLFunc_SpawniEnt)
        
        
g_iPlayerCamera[id] = iEnt
        
//   }
        
        
new Float:flMaxSpeediFlags pev(idpev_flags)
        
pev(idpev_maxspeedflMaxSpeed)
        
        
ExecuteHam(Ham_UseiEntididUSE_TOGGLE1.0)
        
        
set_pev(idpev_flagsiFlags)
        
// depending on mod, you may have to send SetClientMaxspeed here.
        // engfunc(EngFunc_SetClientMaxspeed, id, flMaxSpeed)
        
set_pev(idpev_maxspeedflMaxSpeed)
    }
}

public 
SetView(idiEnt)
{
    if( 
is_user_alive(id) )
    {
        new 
iCamera g_iPlayerCamera[id]
        if( 
iCamera && iEnt != iCamera )
        {
            new 
szClassName[16]
            
pev(iEntpev_classnameszClassNamecharsmax(szClassName))
            if( !
equal(szClassName"trigger_camera") ) // should let real cams enabled
            
{
                
engfunc(EngFunc_SetViewidiCamera// shouldn't be always needed
                
return FMRES_SUPERCEDE
            
}
        }
    }
    return 
FMRES_IGNORED
}

public 
client_disconnect(id)
{
    new 
iEnt g_iPlayerCamera[id]
    if( 
pev_valid(iEnt) )
    {
        
engfunc(EngFunc_RemoveEntityiEnt)
    }
    
g_iPlayerCamera[id] = 0
}

public 
client_putinserver(id)
{
    
g_iPlayerCamera[id] = 0
}

public 
get_cam_owner(iEnt)
{
    static 
id
    
for(id 1id<=g_iMaxPlayersid++)
    {
        if( 
g_iPlayerCamera[id] == iEnt )
        {
            return 
id
        
}
    }
    return 
0
}

public 
Camera_ThinkiEnt )
{
    static 
id
    
if( !(id get_cam_owneriEnt )) )
    {
        return
    }
    
    static 
Float:fVecPlayerOrigin[3], Float:fVecCameraOrigin[3], Float:fVecAngles[3], 
    
Float:fVecForward[3], Float:fVecRight[3], Float:fVecUp[3]

    
pev(idpev_originfVecPlayerOrigin)
    
pev(idpev_view_ofsfVecAngles)
    
    
fVecPlayerOrigin[2] += fVecAngles[2]
    
pev(idpev_v_anglefVecAngles)
    
    
angle_vector(fVecAnglesANGLEVECTOR_FORWARDfVecForward)
    
angle_vector(fVecAnglesANGLEVECTOR_RIGHTfVecRight)
    
angle_vector(fVecAnglesANGLEVECTOR_UPfVecUp)
    
    
fVecCameraOrigin[0] = fVecPlayerOrigin[0] + fVecForward[0] * CAMERA_FORWARD fVecRight[0] * CAMERA_RIGHT fVecUp[0] * CAMERA_UP
    fVecCameraOrigin
[1] = fVecPlayerOrigin[1] + fVecForward[1] * CAMERA_FORWARD fVecRight[1] * CAMERA_RIGHT fVecUp[1] * CAMERA_UP
    fVecCameraOrigin
[2] = fVecPlayerOrigin[2] + fVecForward[2] * CAMERA_FORWARD fVecRight[2] * CAMERA_RIGHT fVecUp[2] * CAMERA_UP
    
    engfunc
(EngFunc_TraceLinefVecPlayerOriginfVecCameraOriginIGNORE_MONSTERSid0)
    static 
Float:flFraction
    get_tr2
(0TR_flFractionflFraction)
    if( 
flFraction != 1.0 // adjust camera place if close to a wall
    
{
        
flFraction *= CAMERA_FRACTION
        
        
//fVecCameraOrigin[0] = fVecPlayerOrigin[0] + fVecForward[0] * flFraction + fVecRight[0] * flFraction + fVecUp[0] * flFraction
        //fVecCameraOrigin[1] = fVecPlayerOrigin[1] + fVecForward[1] * flFraction + fVecRight[1] * flFraction + fVecUp[1] * flFraction
        //fVecCameraOrigin[2] = fVecPlayerOrigin[2] + fVecForward[2] * flFraction + fVecRight[2] * flFraction + fVecUp[2] * flFraction
        
        
fVecCameraOrigin[0] = fVecPlayerOrigin[0] + (fVecForward[0] * flFraction)
        
fVecCameraOrigin[1] = fVecPlayerOrigin[1] + (fVecForward[1] * flFraction)
        
fVecCameraOrigin[2] = fVecPlayerOrigin[2] + (fVecForward[2] * flFraction)
    }
    
    
set_pev(iEntpev_originfVecCameraOrigin)
    
set_pev(iEntpev_anglesfVecAngles)


This code make the players see their character from back side and right side... But when i fire a bullet, the hit origin is different from the crosshair origin... Could someone help me to solve it ? :)

http://i.imgur.com/0PG5jq8.png

.Dare Devil. 05-16-2014 09:14

Re: [Help] 3rd View shoot accuracy (Not Solved)
 
When i created new camera system i had one problem what cant be fixed.
The camera movements was really laggy. Well movements was not that bad but the rotation was just horrible.
Have you tested this plugin in server side? ( and i dont mean local server or lan )

============================================= =======================
Now lets talk about solution.
What if you set player v_angle after setting camera angles so it will aim to the correct place?

idea
PHP Code:

static float:a[3]
pevidpev_v_angle)
a[1] += 5.0
a
[0] += 1.0 

If the origin of two points ( where and where it must aim ) is always same then just mess with those values i gave.

dias 05-16-2014 09:26

Re: [Help] 3rd View shoot accuracy (Not Solved)
 
1. Don't worry, i knew this laggy problem... This code is from Connor, fixed lag problem. it doesn't lag in ServerSide or ClientSide. You can try it
2. Can you edit my code?

.Dare Devil. 05-16-2014 12:35

Re: [Help] 3rd View shoot accuracy (Not Solved)
 
Quote:

Originally Posted by dias (Post 2138540)
1. Don't worry, i knew this laggy problem... This code is from Connor, fixed lag problem. it doesn't lag in ServerSide or ClientSide. You can try it
2. Can you edit my code?

wait so your code doenst lag at all? Like spectatoring other player?
Thats the most amazing thing ive ever heard. I can make so many stuff if this is true.
Anyway, i will edit your code when i get back home. I need to test it and etc...

Backstabnoob 05-16-2014 13:31

Re: [Help] 3rd View shoot accuracy (Not Solved)
 
Connor is setting the camera origin in its think, so it's still frame driven which will probably result in the same lag as others.

dias 05-16-2014 20:44

Re: [Help] 3rd View shoot accuracy (Not Solved)
 
Connor uses the original camera of Spectator... I tested in Server-Side, it doesn't lag like the other camera 3rd

meTaLiCroSS 05-16-2014 20:53

Re: [Help] 3rd View shoot accuracy (Not Solved)
 
Well, "don't know exactly" but things that are directly coded in a module works faster than doing it in a plugin, this is about execution time, that's why engine's custom cameras does not fully lag


All times are GMT -4. The time now is 09:37.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.