Raised This Month: $ Target: $400
 0% 

[amxx]write crosshair as a spr??


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
1pa1pb
Junior Member
Join Date: Jul 2014
Old 07-16-2014 , 04:54   [amxx]write crosshair as a spr??
Reply With Quote #1

hello there.

i modify a plugin that disable crosshair showing up, and add a few lines that can show a spr file (which has the crosshair) onto the screen,


but it can be only seen in one direction, there are afterimages when the player moves.



i want it to stay in the same location to replace the original crosshair,
what should i do? please help.

PHP Code:
#include <amxmodx> 
#include <amxmisc> 

#include <engine>
#include <fakemeta>
#include <fakemeta_util>
#include <hamsandwich>
#include <cstrike>

#define PLUGIN "1" 
#define VERSION "2" 
#define AUTHOR "3" 

#define HUD_HIDE_CROSS (1<<6)
new g_msgHideWeapon
new bool:g_bHideCross
new g_cvarHideCross

new g_ch_SprId

public plugin_init() 

    
register_plugin(PLUGINVERSIONAUTHOR
    
g_msgHideWeapon get_user_msgid("HideWeapon")
    
register_event("ResetHUD""onResetHUD""b")
    
register_message(g_msgHideWeapon"msgHideWeapon")
    
    
register_forward(FM_CmdStart"fw_CmdStart")
    
    
g_cvarHideCross register_cvar("ch_swai""1")

    
HudApplyCVars()


public 
plugin_precache()
{
    
g_ch_SprId engfunc(EngFunc_PrecacheModel"sprites/crosshairs_swai_1.spr")
}

public 
fw_CmdStart(iduc_handleseed)
{
    if(
is_user_alive(id)) {
    static 
Float:Origin[3], TE_FLAG
    get_position
(id80.00.0, -10.0Origin)
    
    
TE_FLAG |= TE_EXPLFLAG_NODLIGHTS
    TE_FLAG 
|= TE_EXPLFLAG_NOSOUND
    TE_FLAG 
|= TE_EXPLFLAG_NOPARTICLES
    
    engfunc
(EngFunc_MessageBeginMSG_ONE_UNRELIABLESVC_TEMPENTITYOriginid)
    
write_byte(TE_EXPLOSION)
    
engfunc(EngFunc_WriteCoordOrigin[0])
    
engfunc(EngFunc_WriteCoordOrigin[1])
    
engfunc(EngFunc_WriteCoordOrigin[2])
    
write_short(g_ch_SprId)
    
write_byte(3)        // if you can see here, i want to ask what
    
write_byte(20)        // are these two lines suppose to be? transparency?
    
write_byte(TE_FLAG)
    
message_end()
    }
}

public 
onResetHUD(id)
{
    
HudApplyCVars()
    new 
iHideFlags GetHudHideFlags()
    if(
iHideFlags)
    {
        
message_begin(MSG_ONEg_msgHideWeapon_id)
        
write_byte(iHideFlags)
        
message_end()
    }    
}

public 
msgHideWeapon()
{
    new 
iHideFlags GetHudHideFlags()
    if(
iHideFlags)
        
set_msg_arg_int(1ARG_BYTEget_msg_arg_int(1) | iHideFlags)
}

GetHudHideFlags()
{
    new 
iFlags

    
if( g_bHideCross )
        
iFlags |= HUD_HIDE_CROSS


    
return iFlags
}

HudApplyCVars()
{
    
g_bHideCross bool:get_pcvar_num(g_cvarHideCross)
}

stock get_position(id,Float:forwFloat:rightFloat:upFloat:vStart[])
{
    static 
Float:vOrigin[3], Float:vAngle[3], Float:vForward[3], Float:vRight[3], Float:vUp[3]
    
    
pev(idpev_originvOrigin)
    
pev(idpev_view_ofsvUp//for player
    
xs_vec_add(vOriginvUpvOrigin)
    
pev(idpev_v_anglevAngle// if normal entity ,use pev_angles
    
    
angle_vector(vAngle,ANGLEVECTOR_FORWARDvForward//or use EngFunc_AngleVectors
    
angle_vector(vAngle,ANGLEVECTOR_RIGHTvRight)
    
angle_vector(vAngle,ANGLEVECTOR_UPvUp)
    
    
vStart[0] = vOrigin[0] + vForward[0] * forw vRight[0] * right vUp[0] * up
    vStart
[1] = vOrigin[1] + vForward[1] * forw vRight[1] * right vUp[1] * up
    vStart
[2] = vOrigin[2] + vForward[2] * forw vRight[2] * right vUp[2] * up

Attached Files
File Type: zip crosshairs_swai_1.zip (629 Bytes, 132 views)

Last edited by 1pa1pb; 07-16-2014 at 04:54.
1pa1pb is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 07-16-2014 , 16:02   Re: [amxx]write crosshair as a spr??
Reply With Quote #2

How this works is that you print a shitload of sprites on the users screen. CmdStart is called on every server frame, let's say 200 times per second. The sprite have a predefined set of frames to be shown, let's say 1.

https://wiki.alliedmods.net/Temp_Ent...:_TE_EXPLOSION

Reading that gives you really only one parameter to mess with, framerate. The highest possible value is 255, which means 25.5 FPS. So if that sprite is drawn and has one frame it will not disappear until ~.039 seconds later. CmdStart will be called with a delay of .005 seconds meaning about 8 times in the lifetime of that sprite, creating new sprites. These are the ones you see.

You can mess with the server FPS to be 25.5 to try to line it up, but I don't think you want that.
Another option is to not call it on every frame, just every 8th for example (if server has 200FPS). But this would cause the crosshair to drag behind instead.
You might be able to tweak it but it will never be perfect. You will either have flickering if you show too few sprites or duplicates if you show too many.

The rotation doesn't seem to be editable in this kind of message.

There might be another way to achieve what you want, I have no idea. I just thought I would explain a part of the problem.
__________________
Black Rose is offline
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 07-16-2014 , 16:11   Re: [amxx]write crosshair as a spr??
Reply With Quote #3

what do we have here: https://forums.alliedmods.net/showthread.php?t=175632
You can also mess with the crosshair color by not doing the gray sprites.
You have to be pretty creative with colors in order to get the white one
.Dare Devil. is offline
1pa1pb
Junior Member
Join Date: Jul 2014
Old 07-17-2014 , 07:35   Re: [amxx]write crosshair as a spr??
Reply With Quote #4

Quote:
Originally Posted by Black Rose View Post
How this works is that you print a shitload of sprites on the users screen. CmdStart is called on every server frame, let's say 200 times per second. The sprite have a predefined set of frames to be shown, let's say 1.

https://wiki.alliedmods.net/Temp_Ent...:_TE_EXPLOSION

Reading that gives you really only one parameter to mess with, framerate. The highest possible value is 255, which means 25.5 FPS. So if that sprite is drawn and has one frame it will not disappear until ~.039 seconds later. CmdStart will be called with a delay of .005 seconds meaning about 8 times in the lifetime of that sprite, creating new sprites. These are the ones you see.

You can mess with the server FPS to be 25.5 to try to line it up, but I don't think you want that.
Another option is to not call it on every frame, just every 8th for example (if server has 200FPS). But this would cause the crosshair to drag behind instead.
You might be able to tweak it but it will never be perfect. You will either have flickering if you show too few sprites or duplicates if you show too many.

The rotation doesn't seem to be editable in this kind of message.

There might be another way to achieve what you want, I have no idea. I just thought I would explain a part of the problem.
Thank you for answering and the link, I am trying.

Quote:
Originally Posted by .Dare Devil. View Post
what do we have here: https://forums.alliedmods.net/showthread.php?t=175632
You can also mess with the crosshair color by not doing the gray sprites.
You have to be pretty creative with colors in order to get the white one
Thank you for suggestions, but how does the thread help me with the crosshair problems? ('cos i read it before when i was debugging extra weapon plugins.)
1pa1pb is offline
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 07-17-2014 , 08:07   Re: [amxx]write crosshair as a spr??
Reply With Quote #5

It helps you because it (probably) gives you the option to directly change the HUD sprite to what you want. Your way just spams sprites on the user's screen like Black Rose said, This method actually changes the sprite directly in the game.
Backstabnoob is offline
Reply



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 13:01.


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