Raised This Month: $12 Target: $400
 3% 

Laser gun TRACER angel to vector


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
vres
Junior Member
Join Date: Dec 2023
Location: Turkey
Old 02-21-2024 , 11:00   Laser gun TRACER angel to vector
Reply With Quote #1

Hello everyone, I am trying to create a laser weapon. I can create an effect line or use laserbeam.spr, but I want to use TE_TRACER. I set the start of the tracer as the player’s position and tried to convert the player’s view angle to a vector for the end, but I failed. I tried many functions, even Ent_Add_AimingVec in the entlib include, but it never worked the way I wanted.

I am leaving the codes of the plugin below. You may see many absurd codes or unnecessary methods, I am a novice in this matter. You can improve every stage of this plugin, I leave it to you.

Right now, the only thing I need is for the tracer to work properly.

Thanks in advance.

Code:
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <hamsandwich>
#include <fakemeta>
#include <fakemeta_util>
#include <fakemeta_stocks>
#include <xs>
#include <engine>
#include <fun>

#define VectorMA(%0,%1,%2,%3) ( %3[0] = %0[0] + %1 * %2[0], %3[1] = %0[1] + %1 * %2[1], %3[2] = %0[2] + %1 * %2[2] )

new bool:isLaserActive[MAX_PLAYERS+1];
new laserOrigin[32][3]

// ... geri kalan kodunuz 
public plugin_init()
{
	register_clcmd("+laser","activateLaser")
	register_clcmd("-laser","deactivateLaser")
	RegisterHam(Ham_Spawn, "player", "fwHamPlayerSpawnPost", 1);
}


public fwHamPlayerSpawnPost(iPlayer) {
        if (is_user_alive(iPlayer)) {
                strip_user_weapons(iPlayer)
        }
} 

public activateLaser(playerId)
{
	if( !is_user_alive(playerId) )
		return PLUGIN_HANDLED
 
	get_user_origin(playerId,laserOrigin[playerId],3)
	isLaserActive[playerId] = true
	drawLaserBeam(playerId)
 
	return PLUGIN_HANDLED
}

public deactivateLaser(playerId)
{
	if( !is_user_alive(playerId) )
		return PLUGIN_HANDLED
 
	isLaserActive[playerId] = false
	removeLaserBeam(playerId)
 
	return PLUGIN_HANDLED
}

public client_PreThink(playerId) 
{
	if(!is_user_alive(playerId))
	{
		removeLaserBeam(playerId);
		return PLUGIN_CONTINUE;
	}

	if(isLaserActive[playerId]) 
	{
		get_user_origin(playerId,laserOrigin[playerId],3); // continuously update player's position

		removeLaserBeam(playerId); // remove old laser beam
		
		drawLaserBeam(playerId); // draw new laser beam

		// Check if the laser beam hits an enemy player
		new aimedPlayerId, bodyPart;
		get_user_aiming(playerId, aimedPlayerId, bodyPart);
		if(is_user_alive(aimedPlayerId) && (cs_get_user_team(playerId) != cs_get_user_team(aimedPlayerId)))
		{
			// Apply fixed damage to the enemy player
			new damage = (bodyPart == 1) ? 9500 : 1; // If headshot, damage is 2. Else, damage is 1.
			if (damage == 9500){
				fm_fakedamage(aimedPlayerId, "", float(damage), DMG_BLAST);
				effecths(aimedPlayerId)
			}else{
				fm_fakedamage(aimedPlayerId, "", float(damage), DMG_BULLET);
			}



			// Create a spark at the point of impact
			new Float:aimOrigin[3], Float:angles[3], Float:dir[3];
			pev(playerId, pev_v_angle, angles);
			xs_anglevectors(angles, dir, Float:{0.0, 0.0, 0.0}, Float:{0.0, 0.0, 0.0});
			VectorMA(laserOrigin[playerId], 0.1, dir, aimOrigin);

			new trace;
			engfunc(EngFunc_TraceLine, laserOrigin[playerId], aimOrigin, DONT_IGNORE_MONSTERS, playerId, trace);
			get_tr2(trace, TR_vecEndPos, aimOrigin);
			Sparks(aimOrigin);
		}
	}
	
	return PLUGIN_CONTINUE;
}

public Sparks(Float:Origin[3])
{
	message_begin(MSG_BROADCAST,SVC_TEMPENTITY)
	write_byte(TE_ARMOR_RICOCHET)
	engfunc(EngFunc_WriteCoord, Origin[0])
	engfunc(EngFunc_WriteCoord, Origin[1])
	engfunc(EngFunc_WriteCoord, Origin[2])
	write_byte(2)	
	message_end()
}



public removeLaserBeam(playerId)
{
	message_begin(MSG_BROADCAST,SVC_TEMPENTITY)
	write_byte(99) // TE_KILLBEAM
	write_short(playerId)
	message_end()
	return true; // laser beam removed
}

public effecths(id)
{
    static Float:origin[3]
    pev(id, pev_origin, origin)
    
    engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, origin, 0)
    write_byte(TE_IMPLOSION) // TE ID
    engfunc(EngFunc_WriteCoord, origin[0])
    engfunc(EngFunc_WriteCoord, origin[1])
    engfunc(EngFunc_WriteCoord, origin[2] + 20.0)
    write_byte(50) // Radius
    write_byte(50) // Count
    write_byte(1) // Duration
    message_end()  
} 

public drawLaserBeam(playerId)
{
    new origin[3], end[3];
    get_user_origin(playerId, origin, 3);
 
	// coding angels vectors end

    // Lazeri çizin
    message_begin(MSG_BROADCAST, SVC_TEMPENTITY);
    write_byte(6); // TE_TRACER
    write_coord(origin[0]);
    write_coord(origin[1]);
    write_coord(origin[2]);
    write_coord(end[0]);
    write_coord(end[1]);
    write_coord(end[2]);
    message_end();
}
vres is offline
georgik57
Veteran Member
Join Date: Oct 2008
Location: 🎧Music World
Old 02-24-2024 , 05:47   Re: Laser gun TRACER angel to vector
Reply With Quote #2

I made this plugin some time ago which forces CS bots to shoot breakables when they're aiming at them because sometimes they would fail. Would probably be useful for your case. Uncomment and enable the sprite message to visualize the start and end position of the trace.
PHP Code:
#include <amxmodx>
//#include <engine>
#include <fakemeta>
#include <hamsandwich>

#include <cs_ham_bots_api>

#include <bitsums>
//#include <D7Debug>



new g_iBsShoot;//g_iIDSpriteDot, 
/*
public plugin_precache()
    g_iIDSpriteDot = precache_model("sprites/dot.spr");*/

public plugin_init()
{
    
register_plugin("D7 Bot shoot breakables""0.0.2""D7")
    
    
register_forward(FM_CmdStart"fwFmCmdStartPre")
    
    
//RegisterHam(Ham_Spawn, "player", "fwHamSpawnPlayer", 1)
    //RegisterHam(Ham_Killed, "player", "fwHamKilledPlayer", 1)
    
    #if defined _cs_ham_bots_api_included
    
RegisterHamBots(Ham_Spawn"fwHamSpawnPlayer"1)
    
RegisterHamBots(Ham_Killed"fwHamKilledPlayer"1)
    
#endif
}

public 
client_putinserver(iID)
    
bitsum_del(g_iBsShootiID)

public 
client_disconnect(iID)
{
    if (!
is_user_bot(iID))
        return;
    
    
bitsum_del(g_iBsShootiID)
    
    
remove_task(iID)
}

public 
fwHamSpawnPlayer(const iID)
{
    
bitsum_del(g_iBsShootiID)
    
    if (!
is_user_alive(iID) || !is_user_bot(iID))
        return;
    
    
remove_task(iID)
    
set_task(0.1"fwTaskBreakable"iID__"b")
}

public 
fwHamKilledPlayer(const iID)//, iIDAttacker, iShouldGib
{
    
bitsum_del(g_iBsShootiID)
    
    
remove_task(iID)
}

ftFmVelocityByAim(const iID, const Float:fAmountFloat:fVecTemp[3])
{
    
pev(iIDpev_v_anglefVecTemp)
    
angle_vector(fVecTempANGLEVECTOR_FORWARDfVecTemp)
    
    
fVecTemp[0] *= fAmount;
    
fVecTemp[1] *= fAmount;
    
fVecTemp[2] *= fAmount;
}

public 
fwTaskBreakable(const iID)
{
    
bitsum_del(g_iBsShootiID)
    
    new 
Float:fVecOrigin[3], Float:fVecTemp[3];
    
pev(iIDpev_originfVecOrigin)
    
pev(iIDpev_view_ofsfVecTemp)
    
    
fVecOrigin[0] += fVecTemp[0];
    
fVecOrigin[1] += fVecTemp[1];
    
fVecOrigin[2] += fVecTemp[2];
    
    
ftFmVelocityByAim(iID150.0fVecTemp)
    
//velocity_by_aim(iID, 150, fVecTemp)
    //VelocityByAim(iID, 150, fVecTemp)
    
    
fVecTemp[0] += fVecOrigin[0];
    
fVecTemp[1] += fVecOrigin[1];
    
fVecTemp[2] += fVecOrigin[2];
    
    
    new 
iIDTrace create_tr2();
    
engfunc(EngFunc_TraceLinefVecOriginfVecTempIGNORE_MONSTERS IGNORE_MISSILEiIDiIDTrace);
    
    new 
iIDEnt get_tr2(iIDTraceTR_pHit);
    
    
free_tr2(iIDTrace)
/*    
    //engfunc(EngFunc_MessageBegin, MSG_PAS, SVC_TEMPENTITY, fVecOrigin, 0)
    engfunc(EngFunc_MessageBegin, MSG_BROADCAST, SVC_TEMPENTITY, fVecOrigin, 0)
    write_byte(TE_BEAMPOINTS);
    engfunc(EngFunc_WriteCoord, fVecOrigin[0]) // x
    engfunc(EngFunc_WriteCoord, fVecOrigin[1]) // y
    engfunc(EngFunc_WriteCoord, fVecOrigin[2]) // z
    engfunc(EngFunc_WriteCoord, fVecTemp[0]) // x
    engfunc(EngFunc_WriteCoord, fVecTemp[1]) // y
    engfunc(EngFunc_WriteCoord, fVecTemp[2]) // z
    write_short(g_iIDSpriteDot);
    write_byte(1);    // framestart 
    write_byte(1);    // framerate 
    write_byte(2);    // life in 0.1's 
    write_byte(5);    // width
    write_byte(0);    // noise 
    write_byte(255);    // r, g, b 
    write_byte(128);    // r, g, b 
    write_byte(0);    // r, g, b 
    write_byte(200);    // brightness 
    write_byte(0);    // speed 
    message_end();*/
    
    //ftD7Log("e", _, "iID: %d. iIDEnt: %d.", iID, iIDEnt)
    
    
if (iIDEnt 33 || !pev_valid(iIDEnt))
        return;
    else if (
pev(iIDEntpev_takedamage) < 1)
    {
        
//ftD7Log("e", _, "pev_takedamage: %d.", pev(iIDEnt, pev_takedamage))
        
        
return;
    }
    
    new 
szClassName[32];
    
pev(iIDEntpev_classnameszClassNamecharsmax(szClassName))
    
    if (
containi(szClassName"hostage") != -1)
    {
        
//ftD7Log("e", _, "pev_takedamage: %d.", pev(iIDEnt, pev_takedamage))
        
        
return;
    }
    
    
//ftD7Log("e", _, "pev_takedamage: %d. Forcing attack.", pev(iIDEnt, pev_takedamage))
    
    
bitsum_add(g_iBsShootiID)
    
    
//set_pev(iID, pev_oldbuttons, pev(iID, pev_oldbuttons) & ~IN_ATTACK)
    //set_pev(iID, pev_button, pev(iID, pev_button) | IN_ATTACK)
}

public 
fwFmCmdStartPre(const iID, const iIDUCHandle)
{
    if (!(
<= iID <= 32) || !bitsum_get(g_iBsShootiID))
        return;
    
    
set_uc(iIDUCHandleUC_Buttonsget_uc(iIDUCHandleUC_Buttons) | IN_ATTACK)

Attached Files
File Type: sma Get Plugin or Get Source (D7BotShootBreakables.sma - 9 views - 3.9 KB)
__________________
georgik57 is offline
Send a message via MSN to georgik57 Send a message via Yahoo to georgik57 Send a message via Skype™ to georgik57
Reply


Thread Tools
Display Modes

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 19:22.


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