AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [SOLVED?]Laser Beam - How to block it when it hits an object or entity? (https://forums.alliedmods.net/showthread.php?t=82396)

CodeMaster 12-22-2008 15:04

[SOLVED?]Laser Beam - How to block it when it hits an object or entity?
 
First of all I'd like to say hi to the community since this is my first post.
I have quite experience in Pawn (SA-MP coding), but I'm not familiar with AMXModX reference and functionality.

I'm interested how could I stop laser beam from passing other entities and objects, so it'd be like a laser aim for some weapons. So all things I'd like to ask would be:
  1. How to make beam to stop on solids (pev_solid? Get end origin some how - the one that's at the solid?)
  2. How to make it be more "sustained" - to do TraceLine events faster?
  3. How to make it go from the top of the weapon barrel, 'cause I've noticed that it actually starts from player's eyes
Thanks in advance

Nidza

stupok 12-23-2008 00:52

Re: Laser Beam - How to block it when it hits an object or entity?
 
http://forums.alliedmods.net/showthread.php?t=53989

That'll get you started.

About #2, search for "prethink" or "postthink". Post any questions that come up, if you don't understand some functions, I'm willing to give some insight.

CodeMaster 12-23-2008 06:00

Re: Laser Beam - How to block it when it hits an object or entity?
 
I've already found that last night, still thanks for willing to help :)

I've considered using PreThink too, but I'm not sure will trace_line function call the event, 'cause I need it to get called since the beam manipulation is in the event hook.

Now only problem is making it refresh faster.

OK, I've did this, but it's still at low refresh rate:
Code:

public hook_prethink(id) {
    new Float:start_origin[3]
    new Float:end_origin[3]
    new Float:return_vec[3]
    pev(id,pev_origin,start_origin)
    pev(id,pev_endpos,end_origin)
    fm_trace_line(id,start_origin,end_origin,return_vec)
}

Cheers ;)

Nidza

stupok 12-23-2008 07:14

Re: Laser Beam - How to block it when it hits an object or entity?
 
Out of curiosity, I made a plugin to see how snappy the "laser pointer" would be.

In conclusion, it can't be made snappy enough. It'll always have some "lag", not really usable. You might want to try the metamod plugin that does the same thing, but I doubt that it'll be much quicker.

I included some extra code, feel free to ask questions:

PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <engine>
#include <xs>

new sprite;

public 
plugin_init()
{
    
register_plugin("Laser Beam""1.0""stupok")
    
    
register_forward(FM_PlayerPreThink"fw_playerprethink")
}

public 
plugin_precache()
{
    
sprite precache_model("sprites/laserbeam.spr");
}
/*
public server_frame()
{
    for(new i = 1; i < 33; i++)
    {
        if(is_user_alive(i))
        {
            show_beam2(i)
        }
    }
}
*/

/*
public fw_playerprethink(id)
{
    show_beam2(id)
}
*/

public show_beam2(id)
{
    static 
Float:fStart[3], Float:fEnd[3];
    static 
tr;
    
    
// This block is interchangeable with get_user_origin(id,origin,3)
    
pev(idpev_originfStart)
    
    
pev(idpev_v_anglefEnd)
    
engfunc(EngFunc_MakeVectorsfEnd)
    
global_get(glb_v_forwardfEnd)
    
xs_vec_mul_scalar(fEnd9999.0fEnd)
    
xs_vec_add(fStartfEndfEnd)
    
    
tr create_tr2()
    
engfunc(EngFunc_TraceLinefStartfEndDONT_IGNORE_MONSTERSidtr)
    
get_tr2(trTR_vecEndPosfEnd)
    
free_tr2(tr)
    
//
    
    //get_user_origin(id,origin,3); // 3 - End position from eyes (hit point for weapon)
    
    
message_begin(MSG_BROADCAST,SVC_TEMPENTITY);
    
write_byte(TE_BEAMENTPOINT);
    
write_short(id 0x1000); // start entity
    
engfunc(EngFunc_WriteCoordfEnd[0])
    
engfunc(EngFunc_WriteCoordfEnd[1])
    
engfunc(EngFunc_WriteCoordfEnd[2])
    
//write_coord(origin[0]); // endposition.x
    //write_coord(origin[1]); // endposition.y
    //write_coord(origin[2]); // endposition.z
    
write_short(sprite); // sprite index
    
write_byte(0); // starting frame
    
write_byte(0); // frame rate in 0.1's
    
write_byte(1); // life in 0.1's
    
write_byte(10); // line wdith in 0.1's
    
write_byte(0); // noise amplitude in 0.01's
    
write_byte(0); // red
    
write_byte(0); // green
    
write_byte(255); // blue
    
write_byte(255); // brightness
    
write_byte(255); // scroll speed in 0.1's
    
message_end();
    
    return 
PLUGIN_HANDLED;



CodeMaster 12-23-2008 07:19

Re: Laser Beam - How to block it when it hits an object or entity?
 
Its all clear, except that part of getting end position...
Could you check my code and say did I got end origin well? Consider that I'm using this for FM_TraceLine.

Edit: is there any event, hook that could be handled on mouse movement?

Thanks

Nidza

danielkza 12-23-2008 11:18

Re: Laser Beam - How to block it when it hits an object or entity?
 
Quote:

Originally Posted by CodeMaster (Post 731921)
Its all clear, except that part of getting end position...
Could you check my code and say did I got end origin well? Consider that I'm using this for FM_TraceLine.

Edit: is there any event, hook that could be handled on mouse movement?

Thanks

Nidza

That's not how the HL engine works. The best way to do this would be to hook the Player_PreThink event using FakeMeta, and then get the user's aiming position and take appropriate action.

CodeMaster 12-23-2008 11:50

Re: Laser Beam - How to block it when it hits an object or entity?
 
I'm sorry dude, but I think its clear that the appropriate action is unknown (to me)...
Could you be more specific? I've made it to work fine, but I still need the end point...
Anyone could give me a hand? (I'm using fakemeta)

Thanks

Nidza

danielkza 12-23-2008 12:02

Re: Laser Beam - How to block it when it hits an object or entity?
 
Quote:

Originally Posted by CodeMaster (Post 732029)
I'm sorry dude, but I think its clear that the appropriate action is unknown...
Could you be more specific? I've made it to work fine, but I still need the end point...
Anyone could give me a hand? (I'm using fakemeta)

Thanks

Nidza

Code:

#include <fakemeta_util>

public plugin_init()
{
    register_forward(FM_PlayerPreThink, "fwPreThink", 0)
}
public fwPreThink(id)
{
    static Float:vOrigin[3]
    fm_get_aim_origin(id, vOrigin)
   
    // vOrigin will now be a vector point of the user aim end (the next wall/player/etc based on the angles of the aim). Do what you want with it.
}


CodeMaster 12-23-2008 12:29

Re: Laser Beam - How to block it when it hits an object or entity?
 
Thanks for your help!
+karma for both of you :)

EDIT: Does anyone know why TE_KILLBEAM won't actually work? Or could someone write proper usage?

Thanks

Nidza

CodeMaster 12-24-2008 18:01

Re: [SOLVED?]Laser Beam - How to block it when it hits an object or entity?
 
*Bump*

Does anyone know efficient way to "kill the beam" or shorten its life (shorter than 0.1s)?


All times are GMT -4. The time now is 09:19.

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