AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Camera Transparency help (https://forums.alliedmods.net/showthread.php?t=342429)

KerwinSweet2003 04-11-2023 04:03

Camera Transparency help
 
Hello,I have a 3d Camera switcher,which has a menu where you can enable/disable transparency,the problem is that the default value is to have transparency,and everytime the player needs to access the menu and to disable the transparency,so he/she can see their model(otherwise the model is invisible with transparency enabled).It is possible to make the default value "No Transparency"? so the players doesn't have to disable it everytime the map changes.Thank you

Code:

#include <amxmodx>
#include <fakemeta>
#include <reapi>
#include <nvault_array>
#include <xs>
#include <ze_vip>


public plugin_natives()
{
        register_native("camset_menu", "native_camset_menu", 1)
    register_native("cam_command", "native_cam_command", 1)
}

new const PLUGIN_VERSION[] = "0.2.5";

#define register_cmd_list(%0,%1,%2)            for (new i = 0; i < sizeof(%1); i++) register_%0(%1[i], %2)  // by fl0wer

new const CAMERA_CLASSNAME[]    = "trigger_camera";

new const VAULT_NAME[]          = "perfect_camera";

enum _:XYZ { Float:X, Float:Y, Float:Z };

enum _:PLAYER_ZOOM
{
    LARGE_AWP_ZOOM      = 10,
    LARGE_OTHER_ZOOM    = 15,
    SMALL_ZOOM          = 40,
    NO_ZOOM            = 90
};

enum _:CVARS
{
    Float:DEFAULT_DISTANCE,
    Float:MINIMUM_DISTANCE,
    Float:MAXIMUM_DISTANCE,
    NVAULT_PRUNE_DAYS,
    DEFAULT_TRANSPARENCY
};

new bool:g_bInThirdPerson[MAX_PLAYERS + 1];
new bool:g_bIsPlayerNoTransparent[MAX_PLAYERS + 1];
new bool:g_bCamAlwaysInThirdPerson[MAX_PLAYERS + 1];
new Float:g_flCamDistance[MAX_PLAYERS + 1];

new g_CvarValue[CVARS];
new g_iVautHandle = INVALID_HANDLE;

new g_iCameraEnt[MAX_PLAYERS + 1] = { NULLENT, ... };

public plugin_init()
{
    register_plugin("Perfect Camera", PLUGIN_VERSION, "Nordic Warrior");

    RegisterHookChain(RG_CBasePlayer_Spawn, "RG_PlayerSpawn_Post", true);
    RegisterHookChain(RG_CBasePlayer_Killed, "RG_PlayerKilled_Post", true);

    register_forward(FM_AddToFullPack, "FM_AddToFullPack_Post", true);

    register_message(get_user_msgid("SetFOV"), "message_SetFOV");

    CreateCvars();
    AutoExecConfig(true, "PerfectCamera");

    g_iVautHandle = nvault_open(VAULT_NAME);

    if(g_iVautHandle != INVALID_HANDLE)
    {
        nvault_prune(g_iVautHandle, 0, get_systime() - g_CvarValue[NVAULT_PRUNE_DAYS] * 86400);
    }
}

public OnConfigsExecuted()
{
    arrayset(g_flCamDistance, g_CvarValue[DEFAULT_DISTANCE], sizeof g_flCamDistance);

    register_cvar("PerfectCamera_version", PLUGIN_VERSION, FCVAR_SERVER|FCVAR_SPONLY|FCVAR_UNLOGGED);
}

public client_authorized(id, const szAuthID[])
{
    if(g_iVautHandle == INVALID_HANDLE)
        return;

    new Data[4];
    nvault_get_array(g_iVautHandle, szAuthID, Data, charsmax(Data));

    g_bIsPlayerNoTransparent[id] = bool:Data[0];
    g_bCamAlwaysInThirdPerson[id] = bool:Data[2];

    if(Data[1])
    {
        g_flCamDistance[id] = float(Data[1]);
    }

    if(g_bCamAlwaysInThirdPerson[id])
    {
        g_bInThirdPerson[id] = true;
    }
}

public client_disconnected(id)
{
    new szAuthID[MAX_AUTHID_LENGTH];
    get_user_authid(id, szAuthID, charsmax(szAuthID));

    new Data[4];

    Data[0] = g_bIsPlayerNoTransparent[id];
    Data[1] = floatround(g_flCamDistance[id]);
    Data[2] = g_bCamAlwaysInThirdPerson[id];

    if(g_iVautHandle != INVALID_HANDLE)
    {
        nvault_set_array(g_iVautHandle, szAuthID, Data, charsmax(Data));
    }

    RemoveCam(id, false);

    g_bInThirdPerson[id] = g_bIsPlayerNoTransparent[id] = g_bCamAlwaysInThirdPerson[id] = false;
    g_flCamDistance[id] = g_CvarValue[DEFAULT_DISTANCE];
}

public cmdToggleCam(const id)
{
    g_bInThirdPerson[id] = !g_bInThirdPerson[id];
    {
        if (g_bInThirdPerson[id])
        {
            client_printcolor(id, "!y[!gZE!y] Camera mode has been switched to : (!g3D person!y)");
            CreateCam(id);
            client_cmd(id, "stopsound");
        }
        else
        {
            client_printcolor(id, "!y[!gZE!y] Camera mode has been switched to : (!gFirst Person!y)");
            RemoveCam(id, true);
            client_cmd(id, "stopsound");
        }
    }
}

public cmdOpenCamMenu(const id)
{
    new iMenu = menu_create(fmt("Camera Settings \rv%s", PLUGIN_VERSION), "CamMenu_handler");

    menu_additem(iMenu, fmt("Transparent Model: \d[%s\d] ^n", g_bIsPlayerNoTransparent[id] ? "\rNo" : "\yYes"));

    menu_addtext(iMenu, fmt("\wCurrent distance: \d[\y%0.f\d]", g_flCamDistance[id]), .slot = 0);
    menu_additem(iMenu, "Further \d[\y+\d]");
    menu_additem(iMenu, "Closer \d[\r–\d]^n");

    //menu_additem(iMenu, fmt("3D View will always remain active: \d[%s\d]", g_bCamAlwaysInThirdPerson[id] ? "\yYes" : "\rNo"));
   
    menu_setprop(iMenu, MPROP_PERPAGE, 0);
    menu_setprop(iMenu, MPROP_EXIT, MEXIT_FORCE);

    menu_addblank2(iMenu);
    menu_addblank2(iMenu);
    menu_addblank2(iMenu);
    menu_addblank2(iMenu);
    menu_addblank2(iMenu);

    menu_setprop(iMenu, MPROP_EXITNAME, "Exit");

    menu_display(id, iMenu);
    return PLUGIN_HANDLED;
}

public CamMenu_handler(const id, iMenu, iItem)
{
    switch(iItem)
    {
        case MENU_EXIT:
        {
            menu_destroy(iMenu);
            return;
        }

        case 0: g_bIsPlayerNoTransparent[id] = !g_bIsPlayerNoTransparent[id];
        case 1: g_flCamDistance[id] = floatmin(g_CvarValue[MAXIMUM_DISTANCE], g_flCamDistance[id] + 5.0);
        case 2: g_flCamDistance[id] = floatmax(g_CvarValue[MINIMUM_DISTANCE], g_flCamDistance[id] - 5.0);
        case 3: g_bCamAlwaysInThirdPerson[id] = !g_bCamAlwaysInThirdPerson[id];
    }

    menu_destroy(iMenu);
    cmdOpenCamMenu(id);
}

public RG_PlayerSpawn_Post(const id)
{
    if(!is_user_alive(id))
        return;

    if(g_bInThirdPerson[id])
    {
        CreateCam(id);
    }
    else
    {
        RemoveCam(id, true);
    }
}

public RG_PlayerKilled_Post(const id)
{
    if(!is_user_connected(id))
        return;

    if(g_bInThirdPerson[id])
    {
        RemoveCam(id, true);
    }
}

CreateCam(const id)
{
    new iCameraEnt = rg_create_entity(CAMERA_CLASSNAME);

    if(is_nullent(iCameraEnt))
        return;

    static iModelIndex;

    if(!iModelIndex)
        iModelIndex = engfunc(EngFunc_ModelIndex, "models/hgibs.mdl");

    set_entvar(iCameraEnt, var_modelindex, iModelIndex);
    set_entvar(iCameraEnt, var_owner, id);
    set_entvar(iCameraEnt, var_movetype, MOVETYPE_NOCLIP);
    set_entvar(iCameraEnt, var_rendermode, kRenderTransColor);
   
    engset_view(id, iCameraEnt);

    set_entvar(iCameraEnt, var_nextthink, get_gametime() + 0.01);
    SetThink(iCameraEnt, "OnCamThink");

    g_iCameraEnt[id] = iCameraEnt;
}

RemoveCam(id, bool:bAttachViewToPlayer)
{
    if(bAttachViewToPlayer)
    {
        engset_view(id, id);
    }

    new iCameraEnt = MaxClients;

    while((iCameraEnt = rg_find_ent_by_class(iCameraEnt, CAMERA_CLASSNAME)))
    {
        if(!is_entity(iCameraEnt))
            continue;

        if(get_entvar(iCameraEnt, var_owner) == id && g_iCameraEnt[id] == iCameraEnt)
        {
            set_entvar(iCameraEnt, var_flags, FL_KILLME);

            g_iCameraEnt[id] = NULLENT;
            break;
        }
    }
}

public OnCamThink(iCameraEnt)
{
    new id = get_entvar(iCameraEnt, var_owner);

    if(!is_user_alive(id) || !is_entity(iCameraEnt))
        return;

    new Float:flPlayerOrigin[XYZ], Float:flCamOrigin[XYZ], Float:flVecPlayerAngles[XYZ], Float:flVecCamAngles[XYZ];

    get_entvar(id, var_origin, flPlayerOrigin);
    get_entvar(id, var_view_ofs, flVecPlayerAngles);

    flPlayerOrigin[Z] += flVecPlayerAngles[Z];

    get_entvar(id, var_v_angle, flVecPlayerAngles);

    angle_vector(flVecPlayerAngles, ANGLEVECTOR_FORWARD, flVecCamAngles);

    xs_vec_sub_scaled(flPlayerOrigin, flVecCamAngles, g_flCamDistance[id], flCamOrigin);

    engfunc(EngFunc_TraceLine, flPlayerOrigin, flCamOrigin, IGNORE_MONSTERS, id, 0);

    new Float:flFraction;
    get_tr2(0, TR_flFraction, flFraction);

    xs_vec_sub_scaled(flPlayerOrigin, flVecCamAngles, flFraction * g_flCamDistance[id], flCamOrigin);

    set_entvar(iCameraEnt, var_origin, flCamOrigin);
    set_entvar(iCameraEnt, var_angles, flVecPlayerAngles);

    set_entvar(iCameraEnt, var_nextthink, get_gametime() + 0.01);
}

public FM_AddToFullPack_Post(es, e, ent, host, hostflags, player, pset)
{
    if(ent == host && g_bInThirdPerson[ent] && !g_bIsPlayerNoTransparent[ent])
    {
        set_es(es, ES_RenderMode, kRenderTransTexture);
        set_es(es, ES_RenderAmt, g_CvarValue[DEFAULT_TRANSPARENCY]);
    }
    else if(g_bInThirdPerson[host] && get_es(es, ES_AimEnt) == host && !g_bIsPlayerNoTransparent[host])
    {
        set_es(es, ES_RenderMode, kRenderTransTexture);
        set_es(es, ES_RenderAmt, g_CvarValue[DEFAULT_TRANSPARENCY]);
    }
}

public message_SetFOV(iMsgID, iMsgDest, id)
{
    static const iMsgArg_FOV = 1;

    if(!g_bInThirdPerson[id] || !is_user_connected(id) || g_iCameraEnt[id] == NULLENT)
        return;

    new iPlayerFOV = get_msg_arg_int(iMsgArg_FOV);

    switch(iPlayerFOV)
    {
        case LARGE_AWP_ZOOM, LARGE_OTHER_ZOOM, SMALL_ZOOM: engset_view(id, id);
        case NO_ZOOM: engset_view(id, g_iCameraEnt[id]);
    }
}

CreateCvars()
{
    bind_pcvar_float(create_cvar("amx_cam_def_distance", "150.0",
        .description = "Default camera distance"),
        g_CvarValue[DEFAULT_DISTANCE]);

    bind_pcvar_float(create_cvar("amx_cam_min_distance", "50.0",
        .description = "Minimum camera distance"),
        g_CvarValue[MINIMUM_DISTANCE]);

    bind_pcvar_float(create_cvar("amx_cam_max_distance", "250.0",
        .description = "Maxium Camera Distance"),
        g_CvarValue[MAXIMUM_DISTANCE]);

    bind_pcvar_num(create_cvar("amx_cam_prune_days", "0",
        .description = "After how many days,player's settings will be deleted"),
        g_CvarValue[NVAULT_PRUNE_DAYS]);

    bind_pcvar_num(create_cvar("amx_cam_def_amt", "20",
        .description = "The % of the transparency"),
        g_CvarValue[DEFAULT_TRANSPARENCY]);
}

public plugin_end()
{
    if(g_iVautHandle != INVALID_HANDLE)
    {
        nvault_close(g_iVautHandle);
    }
}

stock client_printcolor(const id,const input[], any:...)
{
        new msg[191], players[32], count = 1; vformat(msg,190,input,3);
        replace_all(msg,190,"!g","^4");    // green
        replace_all(msg,190,"!y","^1");    // normal
        replace_all(msg,190,"!t","^3");    // team
       
        if (id) players[0] = id; else get_players(players,count,"ch");
       
        for (new i=0;i<count;i++)
        {
                if (is_user_connected(players[i]))
                {
                        message_begin(MSG_ONE_UNRELIABLE,get_user_msgid("SayText"),_,players[i]);
                        write_byte(players[i]);
                        write_string(msg);
                        message_end();
                }
        }
}

public native_camset_menu(id)
{
        cmdOpenCamMenu(id)
}

public native_cam_command(id)
{
        cmdToggleCam(id)
}

I tried to do it myself but with no success,if someone can just make the default value [NO Transparency]

This is the line on the menu where the player has to change the value from [Yes] to [No] to disable transparency

menu_additem(iMenu, fmt("Transparent Model: \d[%s\d] ^n", g_bIsPlayerNoTransparent[id] ? "\rNo" : "\yYes"));

Uzviseni Bog 04-11-2023 19:56

Re: Camera Transparency help
 
Brother, leave the 'include' part and please explain a little better what exactly you want, I don't understand you properly

KerwinSweet2003 04-12-2023 06:10

Re: Camera Transparency help
 
Quote:

Originally Posted by Uzviseni Bog (Post 2802590)
Brother, leave the 'include' part and please explain a little better what exactly you want, I don't understand you properly

The 3d camera that I use has the option to Enable and Disable Transparent Model,the plugin has it enabled by default,and when players type /cam,their model is invisible,and they have to go to the menu and disable "Transparent Model" to be able to see their model,what I want,is the default option to be Transparent Model [NO]
as you can see in the photos

https://imgur.com/a/9hAaAps

Uzviseni Bog 04-12-2023 06:27

Re: Camera Transparency help
 
Quote:

Originally Posted by KerwinSweet2003 (Post 2802610)
The 3d camera that I use has the option to Enable and Disable Transparent Model,the plugin has it enabled by default,and when players type /cam,their model is invisible,and they have to go to the menu and disable "Transparent Model" to be able to see their model,what I want,is the default option to be Transparent Model [NO]
as you can see in the photos

https://imgur.com/a/9hAaAps

Ok, give me include files

KerwinSweet2003 04-15-2023 04:49

Re: Camera Transparency help
 
Quote:

Originally Posted by Uzviseni Bog (Post 2802612)
Ok, give me include files

Sorry for late reply,I was busy these days,here you go:

https://files.fm/u/mz2wqtkzt

Thank you very much for your help my guy :)

JocAnis 04-15-2023 12:02

Re: Camera Transparency help
 
in:

Code:

public client_authorized(id, const szAuthID[])

change this line:
g_bIsPlayerNoTransparent[id] = bool:Data[0];

to:
g_bIsPlayerNoTransparent[id] = false;

if it doesnt work then put:
g_bIsPlayerNoTransparent[id] = true;
cuz we dont didnt code it so we dont know the logic of it

KerwinSweet2003 04-15-2023 17:40

Re: Camera Transparency help
 
Quote:

Originally Posted by JocAnis (Post 2802803)
in:

Code:

public client_authorized(id, const szAuthID[])

change this line:
g_bIsPlayerNoTransparent[id] = bool:Data[0];

to:
g_bIsPlayerNoTransparent[id] = false;

if it doesnt work then put:
g_bIsPlayerNoTransparent[id] = true;
cuz we dont didnt code it so we dont know the logic of it

Putting g_bIsPlayerNoTransparent[id] = true; worked perfectly ^^ Thank you both for your time : )


All times are GMT -4. The time now is 16:15.

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