This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

Solved [L4D2]How to get the drop weapon's position?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kazya3
Member
Join Date: Aug 2019
Location: CN
Old 12-20-2022 , 22:13   [L4D2]How to get the drop weapon's position?
Reply With Quote #1

I try to create a env_sprite when the weapon been dropped on the ground and set parent to the weapon.Here's some my code:
PHP Code:
public void OnClientPutInServer(int client)
{
    
SDKHook(clientSDKHook_WeaponDropOnWeaponDrop);
}

public 
void OnWeaponDrop(int clientint weapon)
{
    if (!
IsValidEntity(weapon) || GetClientTeam(client)!=2){return;}
    
int sprite CreateEntityByName("env_sprite");
    
float  VecOrigin[3];
    
GetEntPropVector(weaponProp_Send"m_vecOrigin"VecOrigin);//cant get the position...:cry:
    
DispatchKeyValueVector(sprite"origin"VecOrigin);
    if(
DEBUG)PrintToChatAll("[debug]origin: %.2f %.2f %.2f"VecOrigin[0], VecOrigin[1], VecOrigin[2]);//cant get the position...:cry:
    
DispatchKeyValue(sprite"model""sprites/light_glow03.vmt");
    
DispatchKeyValue(sprite"rendermode""9");
    
DispatchKeyValue(sprite"scale""0.8");
    
DispatchKeyValue(sprite"spawnflags""1");
    
DispatchKeyValue(sprite"fademaxdist""3000");
    
DispatchSpawn(sprite);
    
SetEntPropEnt(spriteProp_Send"m_hOwnerEntity"weapon);
    
SetVariantString("!activator");
    
AcceptEntityInput(sprite"SetParent"weapon);
    
SetVariantString("0 255 255");
    
AcceptEntityInput(sprite"Color");

How can i get the position correctly?thanks

Last edited by kazya3; 12-21-2022 at 06:44.
kazya3 is offline
HarryPotter
Veteran Member
Join Date: Sep 2017
Location: Taiwan, Asia
Old 12-20-2022 , 23:37   Re: [L4D2]How to get the drop weapon's position?
Reply With Quote #2

Try
PHP Code:
GetEntPropVector(entityProp_Data"m_vecAbsOrigin"VecOrigin); 
__________________
HarryPotter is offline
kazya3
Member
Join Date: Aug 2019
Location: CN
Old 12-21-2022 , 00:31   Re: [L4D2]How to get the drop weapon's position?
Reply With Quote #3

Quote:
Originally Posted by HarryPotter View Post
Try
PHP Code:
GetEntPropVector(entityProp_Data"m_vecAbsOrigin"VecOrigin); 
it works ,but the origin is a little strange. i think maybe because the weapon haven't been dropped when the event happens.
i tried the code:
PHP Code:
// 创建光晕
RequestFrame(NextFrameweapon);

public 
void NextFrame (int weapon)
{
    
float  VecOrigin[3];
    
GetEntPropVector(weaponProp_Send"m_vecOrigin"VecOrigin);
    if(
DEBUG)PrintToChatAll("[debug]origin: %.2f %.2f %.2f"VecOrigin[0], VecOrigin[1], VecOrigin[2]);
    
int sprite CreateEntityByName("env_sprite");;
    
DispatchKeyValueVector(sprite"origin"VecOrigin);
    
DispatchKeyValue(sprite"model""sprites/light_glow03.vmt");
    
DispatchKeyValue(sprite"rendermode""9");
    
DispatchKeyValue(sprite"scale""0.8");
    
DispatchKeyValue(sprite"spawnflags""1");
    
DispatchKeyValue(sprite"fademaxdist""3000");
    
DispatchSpawn(sprite);
    
SetEntPropEnt(spriteProp_Send"m_hOwnerEntity"weapon);
    
SetVariantString("!activator");
    
AcceptEntityInput(sprite"SetParent"weapon);
    
SetVariantString("0 255 255");
    
AcceptEntityInput(sprite"Color");

i get the weapon origin nextframe to confirm the weapon has left player's hand and maybe it's not the best way, but it works

Last edited by kazya3; 12-21-2022 at 00:32.
kazya3 is offline
HarryPotter
Veteran Member
Join Date: Sep 2017
Location: Taiwan, Asia
Old 12-21-2022 , 11:34   Re: [L4D2]How to get the drop weapon's position?
Reply With Quote #4

Quote:
Originally Posted by kazya3 View Post
it works ,but the origin is a little strange. i think maybe because the weapon haven't been dropped when the event happens.
i tried the code:
PHP Code:
// 创建光晕
RequestFrame(NextFrameweapon);

public 
void NextFrame (int weapon)
{
    
float  VecOrigin[3];
    
GetEntPropVector(weaponProp_Send"m_vecOrigin"VecOrigin);
    if(
DEBUG)PrintToChatAll("[debug]origin: %.2f %.2f %.2f"VecOrigin[0], VecOrigin[1], VecOrigin[2]);
    
int sprite CreateEntityByName("env_sprite");;
    
DispatchKeyValueVector(sprite"origin"VecOrigin);
    
DispatchKeyValue(sprite"model""sprites/light_glow03.vmt");
    
DispatchKeyValue(sprite"rendermode""9");
    
DispatchKeyValue(sprite"scale""0.8");
    
DispatchKeyValue(sprite"spawnflags""1");
    
DispatchKeyValue(sprite"fademaxdist""3000");
    
DispatchSpawn(sprite);
    
SetEntPropEnt(spriteProp_Send"m_hOwnerEntity"weapon);
    
SetVariantString("!activator");
    
AcceptEntityInput(sprite"SetParent"weapon);
    
SetVariantString("0 255 255");
    
AcceptEntityInput(sprite"Color");

i get the weapon origin nextframe to confirm the weapon has left player's hand and maybe it's not the best way, but it works

Since you are using RequestFrame, you should pass the entityRef to the function because sometimes the entity may become invalid on next frame (was destoryed by some other plugin for example).

PHP Code:
RequestFrame(NextFrameEntIndexToEntRef(weapon));


public 
void NextFrame (int entityRef)
{
    
int weaponEntRefToEntIndex(entityRef);

    if (
weapon== INVALID_ENT_REFERENCE)
        return;

    ...

Entity_References_(SourceMod)


when/why should i use EntRefToEntIndex/EntIndexToEntRef ?
__________________

Last edited by HarryPotter; 12-21-2022 at 11:41.
HarryPotter is offline
kazya3
Member
Join Date: Aug 2019
Location: CN
Old 12-22-2022 , 23:08   Re: [L4D2]How to get the drop weapon's position?
Reply With Quote #5

Quote:
Originally Posted by HarryPotter View Post
Since you are using RequestFrame, you should pass the entityRef to the function because sometimes the entity may become invalid on next frame (was destoryed by some other plugin for example).

PHP Code:
RequestFrame(NextFrameEntIndexToEntRef(weapon));


public 
void NextFrame (int entityRef)
{
    
int weaponEntRefToEntIndex(entityRef);

    if (
weapon== INVALID_ENT_REFERENCE)
        return;

    ...

Entity_References_(SourceMod)


when/why should i use EntRefToEntIndex/EntIndexToEntRef ?
learn a lot ,thank you.
kazya3 is offline
Reply



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 12:38.


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