AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Code Snippets/Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=83)
-   -   [SNIPPET] Beampoints from a player's weapon tip (https://forums.alliedmods.net/showthread.php?t=53989)

XxAvalanchexX 04-14-2007 21:20

[SNIPPET] Beampoints from a player's weapon tip
 
1 Attachment(s)
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

http://avalanche.epherion.com/images...rson_small.jpg

http://avalanche.epherion.com/images...rson_small.jpg

This flag also works for TE_BEAMENTS, as shown below.

http://avalanche.epherion.com/images...uble_small.jpg

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.

JVC 04-14-2007 21:35

Re: [SNIPPET] Beampoints at the end of a player's weapon
 
Nice Snippet and good job.

Alka 04-15-2007 04:42

Re: [SNIPPET] Beampoints from a player's weapon tip
 
wow.I was looking for this!Gj Avalanche.

Dark Kingdom 04-15-2007 10:17

Re: [SNIPPET] Beampoints from a player's weapon tip
 
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.

VEN 04-15-2007 11:19

Re: [SNIPPET] Beampoints from a player's weapon tip
 
Only if you going to redraw that beam updating end point every time.

Alka 04-15-2007 12:54

Re: [SNIPPET] Beampoints from a player's weapon tip
 
@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 :lol: :P

VEN 04-15-2007 13:15

Re: [SNIPPET] Beampoints from a player's weapon tip
 
You should use get_players in other case server will crash if there are no 32 players.

Brad 04-15-2007 13:59

Re: [SNIPPET] Beampoints from a player's weapon tip
 
These two lines should be outside of the for loop.
Code:
  if(get_pcvar_num(toggle_plugin) == 1) {      new origin[3];

VEN 04-15-2007 15:02

Re: [SNIPPET] Beampoints from a player's weapon tip
 
Quote:

<=
should be
Quote:

<

XxAvalanchexX 04-15-2007 17:51

Re: [SNIPPET] Beampoints from a player's weapon tip
 
Hey, this is a code snippet thread, not a plugin help thread! ;) Now shoo!


All times are GMT -4. The time now is 07:54.

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