AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Creating env_beam problem (https://forums.alliedmods.net/showthread.php?t=98664)

hlstriker 07-27-2009 16:27

Creating env_beam problem
 
I'm trying to create an env_beam just like you would when making one in hammer editor. Using 3 ents - the start point, end point, and beam ent.

I've tried so many different things using both fakemeta and engine to get this working.

If you run the following code you will see it makes both end points and the beam sprite, but the beam sprite doesn't connect to the points (note: I made the end points a sprite just so I could see them).

PHP Code:

#include <amxmodx>
#include <fakemeta>

#define PLUGIN    "Create env_beam"
#define VERSION    "1.0"
#define AUTHOR    "hlstriker"

#define BEAM_SPRITE "sprites/laserbeam.spr"

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR);
    
register_clcmd("say /beam""CreateBeamEnts");
}

public 
plugin_precache()
{
    
precache_model(BEAM_SPRITE);
}

public 
CreateBeamEnts(iClient)
{
    
CreateEntStart(iClient);
    
CreateEntEnd(iClient);
    
set_task(0.5"CreateBeam"iClient);
}

CreateEntStart(iClient)
{
    new 
Float:flOrigin[3];
    
GetFrontOrigin(iClient50flOrigin);
    
    new 
iEnt engfunc(EngFunc_CreateNamedEntityengfunc(EngFunc_AllocString"info_target"));
    
set_keyvalue(iEnt"targetname""startbeam");
    
dllfunc(DLLFunc_SpawniEnt);
    
dllfunc(DLLFunc_ThinkiEnt);
    
set_pev(iEntpev_solidSOLID_BBOX);
    
//set_pev(iEnt, pev_targetname, "startbeam");
    
engfunc(EngFunc_SetOriginiEntflOrigin);
    
engfunc(EngFunc_SetModeliEntBEAM_SPRITE);
    
engfunc(EngFunc_SetSizeiEntFloat:{-4.0, -4.00.0}, Float:{4.04.08.0});
    
    
client_print(0print_chat"START: [%f] - [%f] - [%f]"flOrigin[0], flOrigin[1], flOrigin[2]);
}

CreateEntEnd(iClient)
{
    new 
Float:flOrigin[3];
    
GetFrontOrigin(iClient300flOrigin);
    
    new 
iEnt engfunc(EngFunc_CreateNamedEntityengfunc(EngFunc_AllocString"info_target"));
    
set_keyvalue(iEnt"targetname""endbeam");
    
dllfunc(DLLFunc_SpawniEnt);
    
dllfunc(DLLFunc_ThinkiEnt);
    
set_pev(iEntpev_solidSOLID_BBOX);
    
//set_pev(iEnt, pev_targetname, "endbeam");
    
engfunc(EngFunc_SetOriginiEntflOrigin);
    
engfunc(EngFunc_SetModeliEntBEAM_SPRITE);
    
engfunc(EngFunc_SetSizeiEntFloat:{-4.0, -4.00.0}, Float:{4.04.08.0});
    
    
client_print(0print_chat"END: [%f] - [%f] - [%f]"flOrigin[0], flOrigin[1], flOrigin[2]);
}

public 
CreateBeam(iClient)
{
    new 
Float:flOrigin[3];
    
GetFrontOrigin(iClient150flOrigin);
    
    new 
iEnt engfunc(EngFunc_CreateNamedEntityengfunc(EngFunc_AllocString"env_beam"));
    
set_keyvalue(iEnt"Radius""256");
    
set_keyvalue(iEnt"StrikeTime""10");
    
set_keyvalue(iEnt"TextureScroll""100");
    
set_keyvalue(iEnt"texture"BEAM_SPRITE);
    
set_keyvalue(iEnt"BoltWidth""8");
    
set_keyvalue(iEnt"rendermode""5");
    
set_keyvalue(iEnt"rendercolor""255 0 0");
    
set_keyvalue(iEnt"renderamt""125");
    
set_keyvalue(iEnt"LightningEnd""endbeam");
    
set_keyvalue(iEnt"LightningStart""startbeam");
    
set_keyvalue(iEnt"spawnflags""1");
    
//set_keyvalue(iEnt, "classname", "env_beam");
    
dllfunc(DLLFunc_SpawniEnt);
    
dllfunc(DLLFunc_ThinkiEnt);
    
set_pev(iEntpev_solidSOLID_BBOX);
    
engfunc(EngFunc_SetOriginiEntflOrigin);
    
engfunc(EngFunc_SetModeliEntBEAM_SPRITE);
    
engfunc(EngFunc_SetSizeiEntFloat:{-4.0, -4.00.0}, Float:{4.04.08.0});
    
    
client_print(0print_chat"BEAM: [%f] - [%f] - [%f]"flOrigin[0], flOrigin[1], flOrigin[2]);
}

stock GetFrontOrigin(iEntiDistanceFloat:flReturnOrigin[3])
{
    static 
Float:flOrigin[3], Float:flAngles[3];
    
pev(iEntpev_originflOrigin);
    
pev(iEntpev_v_angleflAngles);
    
flAngles[0] = 0.0;
    
    
angle_vector(flAnglesANGLEVECTOR_FORWARDflReturnOrigin);
    
flReturnOrigin[0] = flOrigin[0] + flReturnOrigin[0] * iDistance;
    
flReturnOrigin[1] = flOrigin[1] + flReturnOrigin[1] * iDistance;
    
flReturnOrigin[2] = flOrigin[2];
}

stock set_keyvalue(iEntszKey[], szValue[])
{
    new 
szClassname[32];
    
pev(iEntpev_classnameszClassnamesizeof(szClassname)-1);
    
set_kvd(0KV_ClassNameszClassname);
    
set_kvd(0KV_KeyNameszKey);
    
set_kvd(0KV_ValueszValue);
    
set_kvd(0KV_fHandled0);
    
    
dllfunc(DLLFunc_KeyValueiEnt0);


Here is a screen shot of what that produces:
[img]http://img190.**************/img190/7384/beamk.jpg[/img]

Here is what I want it to produce:
[img]http://img212.**************/img212/2069/goodbeam.jpg[/img]

Anyone have any ideas how to make this?

ConnorMcLeod 07-27-2009 16:38

Re: Creating env_beam problem
 
This could help you : http://svn.alliedmods.net/viewvc.cgi...p&root=amxmodx

Arkshine 07-27-2009 16:45

Re: Creating env_beam problem
 
Let me search few minutes, I have what you want somewhere in my computer.

Arkshine 07-27-2009 17:38

Re: Creating env_beam problem
 
1 Attachment(s)
Here. You just need, FX_BeamPoints() and UTIL_RelinkBeam(). Life is infinite, it means you need to execute just one time the code. To remove the beam, just kill the beam. Since you will probably check if someone passes the beam, I would suggest to add a check if the beam (entity) is still then the redraw it, because on specific situations the beam could be removed. Btw, "beam" is not the same as "env_beam". "beam" is more a simplified version of env_beam but allowing to use different type of beam : Point -> Point, Point -> Entity, Entity -> Entity, Point -> Direction and there are no spawn flags. "env_beam" seems to be only between entity name, with more options and spawn flags. In your case you should use "beam". If you want to use "env_beam" and the provided options, you would need to create 2 entities like "info_target", setting the right origin and targetname.

hlstriker 07-27-2009 18:14

Re: Creating env_beam problem
 
Alright thanks a lot both Arkshine and Connor :)

I never knew entity "beam" even existed, maybe I should look around the hl1 source more ;)


All times are GMT -4. The time now is 18:24.

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