Raised This Month: $ Target: $400
 0% 

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


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
CodeMaster
Junior Member
Join Date: Dec 2008
Old 12-22-2008 , 15:04   [SOLVED?]Laser Beam - How to block it when it hits an object or entity?
Reply With Quote #1

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

Last edited by CodeMaster; 12-23-2008 at 13:50. Reason: Solved some stuff
CodeMaster is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 12-23-2008 , 00:52   Re: Laser Beam - How to block it when it hits an object or entity?
Reply With Quote #2

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.
__________________
stupok is offline
CodeMaster
Junior Member
Join Date: Dec 2008
Old 12-23-2008 , 06:00   Re: Laser Beam - How to block it when it hits an object or entity?
Reply With Quote #3

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

Last edited by CodeMaster; 12-23-2008 at 07:15.
CodeMaster is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 12-23-2008 , 07:14   Re: Laser Beam - How to block it when it hits an object or entity?
Reply With Quote #4

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;

__________________
stupok is offline
CodeMaster
Junior Member
Join Date: Dec 2008
Old 12-23-2008 , 07:19   Re: Laser Beam - How to block it when it hits an object or entity?
Reply With Quote #5

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
__________________
+karma me if you found me useful
[60% -- ||||||||||] Learning AMXModX functions for better adaption to AMXModX Pawn
[100% - ||||||||||] Pawn Readaptation

CodeMaster is offline
danielkza
AMX Mod X Plugin Approver
Join Date: May 2007
Location: São Paulo - Brasil
Old 12-23-2008 , 11:18   Re: Laser Beam - How to block it when it hits an object or entity?
Reply With Quote #6

Quote:
Originally Posted by CodeMaster View Post
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.
__________________

Community / No support through PM
danielkza is offline
CodeMaster
Junior Member
Join Date: Dec 2008
Old 12-23-2008 , 11:50   Re: Laser Beam - How to block it when it hits an object or entity?
Reply With Quote #7

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
__________________
+karma me if you found me useful
[60% -- ||||||||||] Learning AMXModX functions for better adaption to AMXModX Pawn
[100% - ||||||||||] Pawn Readaptation


Last edited by CodeMaster; 12-23-2008 at 11:57.
CodeMaster is offline
danielkza
AMX Mod X Plugin Approver
Join Date: May 2007
Location: São Paulo - Brasil
Old 12-23-2008 , 12:02   Re: Laser Beam - How to block it when it hits an object or entity?
Reply With Quote #8

Quote:
Originally Posted by CodeMaster View Post
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.
}
__________________

Community / No support through PM
danielkza is offline
CodeMaster
Junior Member
Join Date: Dec 2008
Old 12-23-2008 , 12:29   Re: Laser Beam - How to block it when it hits an object or entity?
Reply With Quote #9

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
__________________
+karma me if you found me useful
[60% -- ||||||||||] Learning AMXModX functions for better adaption to AMXModX Pawn
[100% - ||||||||||] Pawn Readaptation


Last edited by CodeMaster; 12-23-2008 at 13:51.
CodeMaster is offline
CodeMaster
Junior Member
Join Date: Dec 2008
Old 12-24-2008 , 18:01   Re: [SOLVED?]Laser Beam - How to block it when it hits an object or entity?
Reply With Quote #10

*Bump*

Does anyone know efficient way to "kill the beam" or shorten its life (shorter than 0.1s)?
__________________
+karma me if you found me useful
[60% -- ||||||||||] Learning AMXModX functions for better adaption to AMXModX Pawn
[100% - ||||||||||] Pawn Readaptation

CodeMaster is offline
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 09:19.


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