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

[SNIPPET] Beampoints from a player's weapon tip


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 04-14-2007 , 21:20   [SNIPPET] Beampoints from a player's weapon tip
Reply With Quote #1

I figured out how to do this a couple of days ago, and I thought that I might as well archive it in case others are curious.

Overview

If you've used temp entities, you probably know what beampoints are. You may have also seen in HookMod and EntMod that it's possible to attach such beams to the tip of a player's weapon. To do this, you can't use TE_BEAMPOINTS, you will need to use TE_BEAMENTPOINT instead. The format for this temp entity is available in message_const.inc.

In order to get it to attach to the player's weapon (instead of his origin), you must attach the 0x1000 flag to the entity index in your write_short. Below is a screenshot of first- and third-person views. The red line is without the flag, and the blue line is with the flag. For example, these are the two different write_short's that you would use to get either line type.

Code:
write_short(id); // red line write_short(id | 0x1000); // blue line





This flag also works for TE_BEAMENTS, as shown below.



You can see the exact code that I used to generate these lines in the attached SMA.

Extra Details

The exact way this works is by using the position of a model's attachments. Take the attachment index of the attachment that you want to use, add one to it, and then the flag for that attachment would be 0xn000. For example, in gign.qc:

Code:
// 2 attachments
$attachment 0 "Bip01 R Hand" 10.855000 -0.416715 1.870680
$attachment 1 "Bip01 L Hand" 10.855000 -0.416715 1.870680
Attachment 0 is the right hand. Add one, put it into the flag "formula," and you get 0x1000. On the other hand (HA HA HA HA), the left hand is attachment 1. So if you wanted to position an effect there, you would use the flag 0x2000.

You can use these attachment flags for almost any message that takes an entity index, and you can use it on any entities that have attachments.
Attached Files
File Type: sma Get Plugin or Get Source (gunpoint.sma - 2099 views - 2.5 KB)
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS

Last edited by XxAvalanchexX; 04-24-2007 at 21:32.
XxAvalanchexX is offline
JVC
BANNED
Join Date: Apr 2007
Location: Indiana
Old 04-14-2007 , 21:35   Re: [SNIPPET] Beampoints at the end of a player's weapon
Reply With Quote #2

Nice Snippet and good job.
JVC is offline
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 04-15-2007 , 04:42   Re: [SNIPPET] Beampoints from a player's weapon tip
Reply With Quote #3

wow.I was looking for this!Gj Avalanche.
__________________
Still...lovin' . Connor noob! Hello
Alka is offline
Dark Kingdom
BANNED
Join Date: Apr 2007
Location: VT
Old 04-15-2007 , 10:17   Re: [SNIPPET] Beampoints from a player's weapon tip
Reply With Quote #4

Avalanche, would it be possible for you to make the beam follow the gunpoint like a tracer? Because when I tested this the point stayed on the floor and didn't move.
Dark Kingdom is offline
VEN
Veteran Member
Join Date: Jan 2005
Old 04-15-2007 , 11:19   Re: [SNIPPET] Beampoints from a player's weapon tip
Reply With Quote #5

Only if you going to redraw that beam updating end point every time.
VEN is offline
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 04-15-2007 , 12:54   Re: [SNIPPET] Beampoints from a player's weapon tip
Reply With Quote #6

@Dark Kingdom
PHP Code:
#include <amxmodx>
new sprite,toggle_plugin;
new 
redb,greenb,blueb;
public 
plugin_init() {
 
 
register_plugin("Laser Beam","","");
 
set_task(0.1,"show_beam2",0,"",0,"b"); 
 
 
toggle_plugin register_cvar("amx_showbeam","1");
 
 
redb register_cvar("amx_redbeam","255");
 
greenb register_cvar("amx_greenbeam","2");
 
blueb register_cvar("amx_bluebeam","0");
}
public 
plugin_precache()
{
 
sprite precache_model("sprites/laserbeam.spr");
}
public 
show_beam2()
{
 
 static 
iPlayers[32], iPlayerpNum;
 
get_playersiPlayerspNum"a" );
 new 
origin[3];
 
 if(
get_pcvar_num(toggle_plugin) == 1) {
 
  for(new 
i=0pNumi++)
  {
   
iPlayer iPlayers[i];
 
   
get_user_origin(iPlayer,origin,3);
 
   
message_begin(MSG_BROADCAST,SVC_TEMPENTITY);
   
write_byte(TE_BEAMENTPOINT);
   
write_short(iPlayer 0x1000);
   
write_coord(origin[0]);
   
write_coord(origin[1]);
   
write_coord(origin[2]);
   
write_short(sprite);
   
write_byte(0);
   
write_byte(0);
   
write_byte(1);
   
write_byte(10);
   
write_byte(0);
   
write_byte(get_pcvar_num(redb));
   
write_byte(get_pcvar_num(greenb));
   
write_byte(get_pcvar_num(blueb));
   
write_byte(200);
   
write_byte(1);
   
message_end();
  }
 }
 return 
PLUGIN_HANDLED;

Updated! Thanks VEN,Brad!
@Avalanche
__________________
Still...lovin' . Connor noob! Hello

Last edited by Alka; 04-16-2007 at 09:37.
Alka is offline
VEN
Veteran Member
Join Date: Jan 2005
Old 04-15-2007 , 13:15   Re: [SNIPPET] Beampoints from a player's weapon tip
Reply With Quote #7

You should use get_players in other case server will crash if there are no 32 players.
VEN is offline
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 04-15-2007 , 13:59   Re: [SNIPPET] Beampoints from a player's weapon tip
Reply With Quote #8

These two lines should be outside of the for loop.
Code:
  if(get_pcvar_num(toggle_plugin) == 1) {      new origin[3];
__________________
Brad is offline
VEN
Veteran Member
Join Date: Jan 2005
Old 04-15-2007 , 15:02   Re: [SNIPPET] Beampoints from a player's weapon tip
Reply With Quote #9

Quote:
<=
should be
Quote:
<
VEN is offline
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 04-15-2007 , 17:51   Re: [SNIPPET] Beampoints from a player's weapon tip
Reply With Quote #10

Hey, this is a code snippet thread, not a plugin help thread! ;) Now shoo!
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS
XxAvalanchexX 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 13:38.


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