Veteran Member
Join Date: Mar 2012
Location: Solar System/Earth/Belgi
03-25-2012
, 14:54
Re: [HOWTO] Spawn Sprites
#16
Quote:
Originally Posted by
ConnorMcLeod
PHP Code:
message_begin ( MSG_BROADCAST , SVC_TEMPENTITY ); write_coord ( start [ 0 ]); // x
Where is the temp entity TYPE ? it's missing.
what do you mean?
I had it compiled but when i went in the game to test it,
when a player was going to die (but not dead yet) the server had overflow or crash not sure and it kicked me out.
I mixed it into the distance meter plugin from SchlumPF
this is how the entire script looks like:
Spoiler
PHP Code:
#include <amxmodx> #include <engine> #include <fakemeta> #include <cstrike> #pragma semicolon 1 enum AttackType { STAB = 0 , SLASH }; enum TraceType { TRACELINE = 0 , TRACEHULL }; enum Sound { WICKEDSICK = 0 , GODLIKE }; enum HitData { AttackType : iAttack , Float : flDistance , iHitgroup , iAttacker , iVictim }; new g_szTraceType [ TraceType ][] = { "TraceLine" , "TraceHull" }; new g_szSound [ Sound ][] = { "misc/wickedsick.wav" , "misc/godlike.wav" }; new g_HitData [ HitData ]; new g_szHitgroup [ 8 ][] = { "Full Body" , "Head" , "Chest" , "Stomach" , "Left Arm" , "Right Arm" , "Left Leg" , "Right Leg" }; new bool : g_bKnifeHit ; new g_szNickname [ 33 ][ 32 ]; new g_pCVarFriendlyFire ; new g_pCVarSoundWickedSickStab ; new g_pCVarSoundGodlikeStab ; new g_pCVarSoundWickedSickSlash ; new g_pCVarSoundGodlikeSlash ; new g_pCVarHudColor ; new g_pCVarHudCoords ; new g_pCVarHudHoldtime ; new const g_szPluginPrefix [] = "Knife Mod" ; new g_iMaxPlayers ; #define FIRST_PLAYER_ID 1 #define IsPlayer(%1) (FIRST_PLAYER_ID <= %1 <= g_iMaxPlayers) new g_iMsgSayText ; new g_iSpriteLightning ; new g_iSpriteExplode ; new Float : modMeter = 32.00 ; public plugin_precache ( ) { precache_sound ( g_szSound [ WICKEDSICK ] ); precache_sound ( g_szSound [ GODLIKE ] ); g_iSpriteLightning = precache_model ( "sprites/lightning.spr" ); g_iSpriteExplode = precache_model ( "sprites/lm_explode.spr" ); precache_sound ( "sound/lightningbolt.wav" ); precache_sound ( "sound/frag_explode.wav" ); } public plugin_init ( ) { register_plugin ( "Knife Distance" , "0.4" , "SchlumPF" ); g_pCVarSoundWickedSickStab = register_cvar ( "kd_sound_wickedsick_stab" , "0.925" ); g_pCVarSoundGodlikeStab = register_cvar ( "kd_sound_godlike_stab" , "0.975" ); g_pCVarSoundWickedSickSlash = register_cvar ( "kd_sound_wickedsick_slash" , "1.385" ); g_pCVarSoundGodlikeSlash = register_cvar ( "kd_sound_godlike_slash" , "1.460" ); g_pCVarHudColor = register_cvar ( "kd_hud_color" , "140 250 0" ); g_pCVarHudCoords = register_cvar ( "kd_hud_coords" , "-0.75 -1.0" ); g_pCVarHudHoldtime = register_cvar ( "kd_hud_holdtime" , "8.0" ); g_iMaxPlayers = get_maxplayers (); g_iMsgSayText = get_user_msgid ( "SayText" ); register_forward ( FM_TraceLine , "FM_TraceLine_Post" , 1 ); register_forward ( FM_TraceHull , "FM_TraceHull_Post" , 1 ); register_event ( "Damage" , "eventDamage" , "b" ); g_pCVarFriendlyFire = get_cvar_pointer ( "mp_friendlyfire" ); } public FM_TraceLine_Post ( Float : vecSrc [ 3 ], Float : vecEnd [ 3 ], noMonsters , skipEnt , tr ) { if( ! is_user_alive ( skipEnt ) ) { return FMRES_IGNORED ; } if( get_user_weapon ( skipEnt ) != CSW_KNIFE ) { return FMRES_IGNORED ; } static button ; button = pev ( skipEnt , pev_button ); if( !( button & IN_ATTACK ) && !( button & IN_ATTACK2 ) ) { return FMRES_IGNORED ; } static Float : flFraction ; get_tr2 ( tr , TR_flFraction , flFraction ); if( flFraction >= 1.0 ) { return FMRES_IGNORED ; } static pHit ; pHit = get_tr2 ( tr , TR_pHit ); if( get_user_team ( skipEnt ) == get_user_team ( pHit ) && ! get_pcvar_num ( g_pCVarFriendlyFire ) ) { return FMRES_IGNORED ; } static Float : vecEndPos [ 3 ]; get_tr2 ( tr , TR_vecEndPos , vecEndPos ); static Float : distance ; distance = vector_distance ( vecSrc , vecEndPos ); static Float : range ; range = distance / flFraction ; // vector_distance( vecSrc, vecEnd ) if( 31.89 < range < 32.1 ) { GetTraceData ( tr , skipEnt , pHit , distance , STAB ); } else if( 47.89 < range < 48.1 ) { GetTraceData ( tr , skipEnt , pHit , distance , SLASH ); } return FMRES_IGNORED ; } public FM_TraceHull_Post ( Float : vecSrc [ 3 ], Float : vecEnd [ 3 ], noMonsters , hull , skipEnt , tr ) { if( ! is_user_alive ( skipEnt ) ) { return FMRES_IGNORED ; } if( get_user_weapon ( skipEnt ) != CSW_KNIFE ) { return FMRES_IGNORED ; } static Float : flFraction ; get_tr2 ( tr , TR_flFraction , flFraction ); if( flFraction >= 1.0 ) { return FMRES_IGNORED ; } static pHit ; pHit = get_tr2 ( tr , TR_pHit ); if( get_user_team ( skipEnt ) == get_user_team ( pHit ) && ! get_pcvar_num ( g_pCVarFriendlyFire ) ) { return FMRES_IGNORED ; } static Float : vecEndPos [ 3 ]; get_tr2 ( tr , TR_vecEndPos , vecEndPos ); static Float : distance ; distance = vector_distance ( vecSrc , vecEndPos ); static Float : range ; range = distance / flFraction ; // vector_distance( vecSrc, vecEnd ) if( 31.89 < range < 32.1 ) { GetTraceData ( tr , skipEnt , pHit , distance , STAB ); } else if( 47.89 < range < 48.1 ) { GetTraceData ( tr , skipEnt , pHit , distance , SLASH ); } return FMRES_IGNORED ; } public GetTraceData ( tr , attacker , victim , Float : distance , AttackType : attack ) { g_HitData [ iAttack ] = any : attack ; g_HitData [ flDistance ] = any : distance ; g_HitData [ iHitgroup ] = get_tr2 ( tr , TR_iHitgroup ); g_HitData [ iAttacker ] = attacker ; g_HitData [ iVictim ] = victim ; g_bKnifeHit = true ; } public eventDamage ( ) { if( g_bKnifeHit ) { g_bKnifeHit = false ; static victim ; victim = g_HitData [ iVictim ]; new origin [ 3 ]; new start [ 3 ]; if( !( 1 <= victim <= 32 ) ) { return PLUGIN_CONTINUE ; } static attacker ; attacker = g_HitData [ iAttacker ]; static Float : distance ; distance = g_HitData [ flDistance ]; static Float : health ; pev ( victim , pev_health , health ); static r , g , b ; GetHudColor ( r , g , b ); static Float : x , Float : y ; GetHudCoords ( x , y ); set_hudmessage ( r , g , b , x , y , 0 , 0.0 , get_pcvar_float ( g_pCVarHudHoldtime ), 0.0 , 0.0 , 1 ); if( g_HitData [ iAttack ] == STAB ) { show_hudmessage ( attacker , "Stab Stats (%s)^nDistance: %.3f meter (max: 1.0)^nHit: %s (%s)^nDamage: %i" \ , g_szTraceType [ TraceType :! g_HitData [ iHitgroup ]],\ ( distance / modMeter ), g_szNickname [ victim ],\ g_szHitgroup [ g_HitData [ iHitgroup ]], pev ( victim , pev_dmg_take ) ); if( health < 0.0 ) { fnColorPrint ( 0 , "^4%s ^1stabbed^3 %s ^1from^4 %.3f ^1meter ^3(%s)^1!" ,\ g_szNickname [ attacker ], g_szNickname [ victim ],\ ( distance / modMeter ), g_szHitgroup [ g_HitData [ iHitgroup ]] ); // ShowExplSprite get_user_origin ( victim , origin ); //ShowExplSprite(origin); // LightSprite entity_get_vector ( victim , EV_VEC_origin , Float : start ); //ShowLightSprite(start); ShowLightSprite ( start ); ShowExplSprite ( origin ); if( ( distance / modMeter ) >= get_pcvar_float ( g_pCVarSoundGodlikeStab ) ) { fnColorPrint ( 0 , "^4 %s ^1has made a GodLike %s-stab kill on^3 %s^1!" ,\ g_szNickname [ attacker ],\ g_szHitgroup [ g_HitData [ iHitgroup ]],\ g_szNickname [ victim ] ); client_cmd ( 0 , "spk %s" , g_szSound [ GODLIKE ] ); // ShowExplSprite get_user_origin ( victim , origin ); // LightSprite entity_get_vector ( victim , EV_VEC_origin , Float : start ); ShowLightSprite ( start ); ShowExplSprite ( origin ); } else if( ( distance / modMeter ) >= get_pcvar_float ( g_pCVarSoundWickedSickStab )) { fnColorPrint ( 0 , "^4 %s ^1has made a WickedSick %s-stab kill on^3 %s^1!" ,\ g_szNickname [ attacker ],\ g_szHitgroup [ g_HitData [ iHitgroup ]],\ g_szNickname [ victim ] ); client_cmd ( 0 , "spk %s" , g_szSound [ WICKEDSICK ] ); } } } else { show_hudmessage ( attacker , "Slash Stats (%s)^nDistance: %.3f meter (max: 1.5)^nHit: %s (%s)^nDamage: %i" \ , g_szTraceType [ TraceType :! g_HitData [ iHitgroup ]],\ ( distance / modMeter ), g_szNickname [ victim ],\ g_szHitgroup [ g_HitData [ iHitgroup ]], pev ( victim , pev_dmg_take ) ); if( health < 0.0 ) { fnColorPrint ( 0 , "^4%s ^1slashed^3 %s ^1from^4 %.3f ^1meter ^3(%s)!" ,\ g_szNickname [ attacker ],\ g_szNickname [ victim ],\ ( distance / modMeter ), g_szHitgroup [ g_HitData [ iHitgroup ]] ); /// ShowExplSprite get_user_origin ( victim , origin ); // LightSprite entity_get_vector ( victim , EV_VEC_origin , Float : start ); ShowLightSprite ( start ); ShowExplSprite ( origin ); if( ( distance / modMeter ) >= get_pcvar_float ( g_pCVarSoundGodlikeSlash ) ) { fnColorPrint ( 0 , "^4 %s ^1made a GodLike %s-slash kill on^3 %s^1!" ,\ g_szNickname [ attacker ],\ g_szHitgroup [ g_HitData [ iHitgroup ]],\ g_szNickname [ victim ] ); client_cmd ( 0 , "spk %s" , g_szSound [ GODLIKE ] ); // ShowExplSprite get_user_origin ( victim , origin ); // LightSprite entity_get_vector ( victim , EV_VEC_origin , Float : start ); ShowLightSprite ( start ); ShowExplSprite ( origin ); } else if( ( distance / modMeter ) >= get_pcvar_float ( g_pCVarSoundWickedSickSlash ) ) { fnColorPrint ( 0 , "^4 %s ^1has made a WickedSick %s-slash kill on^3 %s^1!" ,\ g_szNickname [ attacker ],\ g_szHitgroup [ g_HitData [ iHitgroup ]],\ g_szNickname [ victim ] ); client_cmd ( 0 , "spk %s" , g_szSound [ WICKEDSICK ] ); } } } } return PLUGIN_CONTINUE ; } public client_infochanged ( plr ) { static curName [ 32 ], newName [ 32 ]; get_user_name ( plr , curName , 31 ); get_user_info ( plr , "name" , newName , 31 ); if( ! equal ( newName , curName ) ) { copy ( g_szNickname [ plr ], 31 , newName ); } } public GetHudColor ( & r , & g , & b ) { static color [ 16 ], piece [ 5 ]; get_pcvar_string ( g_pCVarHudColor , color , 15 ); strbreak ( color , piece , 4 , color , 15 ); r = str_to_num ( piece ); strbreak ( color , piece , 4 , color , 15 ); g = str_to_num ( piece ); b = str_to_num ( color ); } public GetHudCoords ( & Float : x , & Float : y ) { static coords [ 16 ], piece [ 10 ]; get_pcvar_string ( g_pCVarHudCoords , coords , 15 ); strbreak ( coords , piece , 9 , coords , 15 ); x = str_to_float ( piece ); y = str_to_float ( coords ); } stock ShowLightSprite ( start [ 3 ]) { // coord coord coord (start position) // coord coord coord (end position) // short (sprite index) // byte 1(starting frame) // byte 2(frame rate in 0.1's) // byte 3(life in 0.1's) // byte 4(line width in 0.1's) // byte 5(noise amplitude in 0.01's) // byte,byte,byte 6-8(color) // byte 9(brightness) // byte 10(scroll speed in 0.1's) message_begin ( MSG_BROADCAST , SVC_TEMPENTITY ); write_coord ( start [ 0 ]); // x write_coord ( start [ 1 ]); // y write_coord ( start [ 2 ]); // z write_coord ( start [ 0 ]); // x Example end[0] = start[0] + 100 write_coord ( start [ 1 ]); // y Example end[1] = start[1] write_coord ( start [ 2 ]-= 15 ); // z write_short ( g_iSpriteLightning ); // Sprite index write_byte ( 1 ); //1 write_byte ( 1 ); //2 write_byte ( 30 ); //3 write_byte ( 5 ); //4 write_byte ( 10 ); //5 write_byte ( 255 ); //6 write_byte ( 140 ); //7 write_byte ( 0 ); //8 write_byte ( 255 ); //9 message_end (); } stock ShowExplSprite ( origin [ 3 ]) { // write_byte(TE_SPRITE) // write_coord(position.x) // write_coord(position.y) // write_coord(position.z) // write_short(sprite index) // write_byte(scale in 0.1's) // write_byte(brightness) message_begin ( MSG_BROADCAST , SVC_TEMPENTITY ); write_byte ( TE_SPRITE ); write_coord ( origin [ 0 ]); //x write_coord ( origin [ 1 ]); //y write_coord ( origin [ 2 ]) ; //z write_short ( g_iSpriteExplode ); // Sprite index write_byte ( 6 ); //scale write_byte ( 255 ); //brightness message_end (); } fnColorPrint ( index , const Msg [], any :...) { new Buffer [ 190 ], Buffer2 [ 192 ]; formatex ( Buffer2 , charsmax ( Buffer2 ), "^x04[%s] ^x01%s" , g_szPluginPrefix , Msg ); vformat ( Buffer , charsmax ( Buffer ), Buffer2 , 3 ); if (! index ) { for (new i = 1 ; i <= g_iMaxPlayers ; i ++) { if (! is_user_connected ( i )) continue; message_begin ( MSG_ONE_UNRELIABLE , g_iMsgSayText , _ , i ); write_byte ( i ); write_string ( Buffer ); message_end (); } } else { if (! is_user_connected ( index )) return; message_begin ( MSG_ONE , g_iMsgSayText , _ , index ); write_byte ( index ); write_string ( Buffer ); message_end (); } }