Raised This Month: $ Target: $400
 0% 

Improve plugin and fix something


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Advanced
Junior Member
Join Date: Oct 2012
Old 08-21-2013 , 04:14   Improve plugin and fix something
Reply With Quote #1

This plugin displays sprites on players HUD (using AddToFullPack and creating a new entity in front of a player). Please tell me how can I improve the code and fix one existing bug. When you go forward or back, entity is following you too slow, like its speed is too slow, so it is not fixed on your screen, when you go forward, you dont see the entity, when you stop and wait for 1s it shows again, like I have to increase entity's speed somehow. Please HELP!

PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <xs>

// Distance at which the sprite is placed from the users screen
// DO NOT EDIT UNNECESSARILY!
#define DISTANCE     12

new g_player_ent[33], g_bit_connected_userg_stop_frame[33]

// Connected players macros
#define player_is_connected(%1)        (g_bit_connected_user |=  (1 << (%1 & 31)))
#define player_disconnected(%1)        (g_bit_connected_user &= ~(1 << (%1 & 31)))
#define is_player_connected(%1)        ((1 <= %1 <= 32) && (g_bit_connected_user & (1 << (%1 & 31))))

public plugin_init() 
{
    
// Register the plugin and the main forward
    
register_plugin("[ZP] Addon: Sprites On HUD""1.0""@bdul!");
    
register_forward(FM_AddToFullPack"fm_add_to_fullpack"1)
}

public 
plugin_natives()
{
    
// Lets register some natives
    
register_native("DisplayHudSprite""native_display_hud_sprite"1)
    
register_native("RemoveHudSprite""native_remove_hud_sprite"1)
}

public 
fm_add_to_fullpack(eseenthosthost_flagsplayerp_set)
{
    
// Valid player ?
    
if (!is_player_connected(host))
        return 
FMRES_IGNORED;
    
    
// Player haves a valid sprite entity
    
if (ent == g_player_ent[host])
    {
        static 
Float:origin[3], Float:forvec[3], Float:voffsets[3]
        
        
// Retrieve player's origin
        
pev(hostpev_originorigin)
        
pev(hostpev_view_ofsvoffsets)
        
xs_vec_add(originvoffsetsorigin)
        
        
// Get a forward vector in the direction of player's aim
        
velocity_by_aim(hostDISTANCEforvec)
        
        
// Set the sprite on the new origin
        
xs_vec_add(originforvecorigin)
        
engfunc(EngFunc_SetOriginentorigin)
        
set_es(esES_Originorigin)
        
        
// Make the sprite visible
        
set_es(esES_RenderModekRenderNormal)
        
set_es(esES_RenderAmt200)
        
        
// Sprite animation already stopped ?
        
if (!g_stop_frame[host])
            return 
FMRES_IGNORED
        
        
// Stop the animation at the desired frame
        
if (pev(entpev_frame) == g_stop_frame[host])
        {
            
set_pev(entpev_framerate0.0)
            
g_stop_frame[host] = 0
        
}
    }
    
    
// Stupid compiler !!
    
return FMRES_IGNORED
}

public 
client_putinserver(id)
{
    
// Player connected
    
player_is_connected(id)
    
    
// Marks bots as disconnected players (so sprites are'nt displayed to them)
    
if (is_user_bot(id)) player_disconnected(id)
    
    
// Remove sprite entity if present
    
if (pev_valid(g_player_ent[id]))
        
remove_sprite_entity(id)
}

public 
client_disconnect(id)
{
    
// Player disconnected
    
player_disconnected(id)
    
    
// Remove sprite entity if present
    
if (pev_valid(g_player_ent[id]))
        
remove_sprite_entity(id)
}

public 
native_display_hud_sprite(id, const sprite_name[], Float:sprite_sizesprite_stopframeFloat:sprite_framerate)
{
    
// Invalid player ?
    
if (!is_player_connected(id))
        return -
1;
    
    
// Already haves a sprite on his hud
    
if (g_player_ent[id])
        return -
1;
    
    
// Strings passed byref
    
param_convert(2)
    
    
// Invalid sprite ?
    
if (!sprite_name[0])
        return -
1;
    
    
// Create an entity for the player
    
g_player_ent[id] = engfunc(EngFunc_CreateNamedEntityengfunc(EngFunc_AllocString"env_sprite"))
    
    
// Invalid entity ?
    
if (!pev_valid(g_player_ent[id]))
        return -
1;
    
    
// Set some basic properties
    
set_pev(g_player_ent[id], pev_takedamage0.0)
    
set_pev(g_player_ent[id], pev_solidSOLID_NOT)
    
set_pev(g_player_ent[id], pev_movetypeMOVETYPE_NONE)
    
    
// Set the sprite model
    
engfunc(EngFunc_SetModelg_player_ent[id], sprite_name)
    
    
// Set the rendering on the entity
    
set_pev(g_player_ent[id], pev_rendermodekRenderTransAlpha)
    
set_pev(g_player_ent[id], pev_renderamt0.0)
    
    
// Set the sprite size
    
set_pev(g_player_ent[id], pev_scalesprite_size)
    
    
// Update sprite's stopping frame
    
g_stop_frame[id] = sprite_stopframe
    
    
// Allow animation of sprite ?
    
if (g_stop_frame[id] && sprite_framerate 0.0)
    {
        
// Set the sprites animation time, framerate and stop frame
        
set_pev(g_player_ent[id], pev_animtimeget_gametime())
        
set_pev(g_player_ent[id], pev_frameratesprite_framerate)
        
        
// Spawn the sprite entity (necessary to play the sprite animations)
        
set_pev(g_player_ent[id], pev_spawnflagsSF_SPRITE_STARTON)
        
dllfunc(DLLFunc_Spawng_player_ent[id])
    }
    
    return 
g_player_ent[id];
}

public 
native_remove_hud_sprite(id)
{
    
// Invalid player ?
    
if (!is_player_connected(id))
        return -
1;
    
    
// Doesnt haves any sprite on his screen ?
    
if (!pev_valid(g_player_ent[id]))
        return -
1;
    
    
// Remove sprite entity
    
remove_sprite_entity(id)
    
    return 
1;
}

// Removes a sprite entity from world
remove_sprite_entity(id)
{
    
engfunc(EngFunc_RemoveEntityg_player_ent[id])
    
    
g_player_ent[id] = 0
    g_stop_frame
[id] = 0

Also I am using Connors code for my ZP, it is working fine and nothing disapears, everything working perfect :
PHP Code:
#include <amxmodx>
#include <engine>
#include <fakemeta>
#include <hamsandwich>
#include <zombieplague>
#include <xs>

#pragma semicolon 1

#define PLUGIN "[ZP] Addon: Infect-Effect"
#define VERSION "2.0.2"

new const INFECT_EFFECT_MODEL[] = "sprites/infect-effect.spr";

new const 
INFECT_EFFECT_CLASS[] = "env_infect_effect";

new const 
ENV_SPRITE_CLASS[] = "env_sprite"// don't change

#define MaskEnt(%0)    ( 1<<(%0 & 31) )

new g_bitSpriteEffectsEnts[64];
#define MarkSpriteEffect(%0)    g_bitSpriteEffectsEnts[%0>>5] |=  MaskEnt(%0)
#define ClearSpriteEffect(%0)    g_bitSpriteEffectsEnts[%0>>5] &= ~MaskEnt(%0)
#define IsSpriteEffect(%0)        ( g_bitSpriteEffectsEnts[%0>>5] &   MaskEnt(%0) )

new cvar_scalecvar_showtimecvar_lightlevel;

new 
g_iPlayerEntEffectIndex[33];
new 
g_iszEnvSpriteg_iszCustomClassg_iszModel;

public 
plugin_init()
{
    
register_plugin(PLUGINVERSION"ConnorMcLeod");

    
cvar_scale register_cvar("zp_in-ef_scale""0.035");
    
cvar_showtime register_cvar("zp_in-ef_showtime""2.0");
    
cvar_lightlevel register_cvar("zp_in-ef_lightlevel""100");

    
g_iszEnvSprite engfunc(EngFunc_AllocStringENV_SPRITE_CLASS);
    
g_iszCustomClass engfunc(EngFunc_AllocStringINFECT_EFFECT_CLASS);
    
g_iszModel engfunc(EngFunc_AllocStringINFECT_EFFECT_MODEL);
    
register_think(INFECT_EFFECT_CLASS"Think_InfectEffect");

    
RegisterHam(Ham_Spawn"player""OnCBasePlayer_Spawn_P"true);
    
register_forward(FM_AddToFullPack"OnAddToFullPack"false);
    
RegisterHam(Ham_CS_RestartENV_SPRITE_CLASS"OnCSprite_Restart"false);
}

public 
plugin_precache()
{
    
precache_model(INFECT_EFFECT_MODEL);
}

public 
OnCBasePlayer_Spawn_P(id)
{
    new 
ent g_iPlayerEntEffectIndex[id];
    if( 
ent )
    {
        if( 
pev_valid(ent) )
        {
            
remove_entity(ent);
            
ClearSpriteEffect(ent);
        }
        
g_iPlayerEntEffectIndex[id] = 0;
    }
}

public 
zp_user_infected_post(idattacker)
{
    if(
is_user_alive(attacker))
    {
        new 
ent engfunc(EngFunc_CreateNamedEntityg_iszEnvSprite);
        if( 
ent <= )
        {
            return;
        }

        
set_pev_string(entpev_modelg_iszModel);
        
entity_set_int(entEV_INT_spawnflagsSF_SPRITE_STARTON);

        if( 
DispatchSpawn(ent) == -)
        {
            
remove_entity(ent);
        }
        
        
entity_set_int(entEV_INT_rendermodekRenderTransAdd);
        
entity_set_float(entEV_FL_renderamt200.0);
        
entity_set_float(entEV_FL_scaleget_pcvar_float(cvar_scale));
        
entity_set_int(entEV_INT_light_levelget_pcvar_num(cvar_lightlevel));

        
set_pev_string(entpev_classnameg_iszCustomClass);
        
entity_set_float(entEV_FL_nextthinkget_gametime() + get_pcvar_float(cvar_showtime));

        
MarkSpriteEffect(ent);
        
g_iPlayerEntEffectIndex[id] = ent;
        
entity_set_edict(entEV_ENT_euser1id);
    }
}

public 
OnAddToFullPack(eseentidhostflagsplayerpSet)
{
    if( 
player || !IsSpriteEffect(ent) )
    {
        return 
FMRES_IGNORED;
    }

    if( 
g_iPlayerEntEffectIndex[id] != ent )
    {
        
forward_return(0);
        return 
FMRES_SUPERCEDE;
    }

    static 
Float:origin[3], Float:v_forward[3], Float:angles[3];

    
velocity_by_aim(id10v_forward);

    
entity_get_vector(idEV_VEC_originorigin);
    
origin[2] += entity_get_int(idEV_INT_flags) & FL_DUCKING 12.0 18.0;

    
xs_vec_add(originv_forwardorigin);
    
engfunc(EngFunc_SetOriginentorigin);

    
entity_get_vector(idEV_VEC_anglesangles);
    
entity_set_vector(entEV_VEC_anglesangles);

    return 
FMRES_HANDLED;
}

public 
OnCSprite_Restartent )
{
    if( 
IsSpriteEffect(ent) )
    {
        
Think_InfectEffectent );
    }
}

public 
Think_InfectEffectent )
{
    new 
id entity_get_edict(entEV_ENT_euser1);
    
g_iPlayerEntEffectIndex[id] = 0;
    
remove_entity(ent);
    
ClearSpriteEffect(ent);
    return 
PLUGIN_HANDLED;

Advanced is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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