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

[l4d2] how to keep specific entity id when chapter changing


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
zonbarbar
Member
Join Date: Jul 2022
Old 01-26-2024 , 03:31   [l4d2] how to keep specific entity id when chapter changing
Reply With Quote #1

i want to make different status to every weapon entity, like damage or shooting speed, this is the only way i found to make this happen, question is the entity id will be change after finish of round.

Code: int iCurrentWeapon = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");

PrintToChatAll("%d", iCurrentWeapon);

I use this to get entity id, is this the entity id?
zonbarbar is offline
zonbarbar
Member
Join Date: Jul 2022
Old 01-26-2024 , 03:39   Re: [l4d2] how to keep specific entity id when chapter changing
Reply With Quote #2

im trying this https://wiki.alliedmods.net/Entity_R...ces_(SourceMod)
zonbarbar is offline
zonbarbar
Member
Join Date: Jul 2022
Old 01-26-2024 , 03:47   Re: [l4d2] how to keep specific entity id when chapter changing
Reply With Quote #3

ok i dont know how to use ref
zonbarbar is offline
101
Member
Join Date: Nov 2023
Old 01-26-2024 , 09:23   Re: [l4d2] how to keep specific entity id when chapter changing
Reply With Quote #4

Quote:
Originally Posted by zonbarbar View Post

PHP Code:
public void OnEntityCreated(int entity, const char[] classname)
{
    if(
StrContains(classname"weapon_"false) != -1)
        
CreateTimer0.1 Timer_entity EntIndexToEntRef(entity) );
}

public 
Action:Timer_entity(Handle:timerany:entity)
{
    
entity EntRefToEntIndex(entity);
    
    if (!
IsValidEntity(entity)) return;        //it had been removed somehow
    
    /* The entiy Now Is Valid And it's name contains "weapon_"
    You Can Then Modify Any Weapon . For Example :
    If You Want To Replace All Medkits By pill bottles In L4d , See The Example Below :
    */    

Replace Entities :

PHP Code:
#include <sdktools>
#include <sdkhooks>

float Angles[3],Location[3];

public 
void OnEntityCreated(int entity, const char[] classname)        //This Requires sdkhooks
{
    if(
StrContains(classname"first_aid_kit"false) != -1)
    {
        
CreateTimer0.1 Timer_Replace_entity EntIndexToEntRef(entity) );
    }
}

public 
Action:Timer_Replace_entity(Handle:timer any:entity)
{
    
entity EntRefToEntIndex(entity);
    if (!
IsValidEntity(entity)) return;
    
    new 
entCreated CreateEntityByName("weapon_pain_pills");    //This Requires sdktools
    
    
if(entCreated != -1)    // This Is To Insure That the Entity Created Is Valid 
    
{
        
GetEntPropVector(entity Prop_Send "m_vecOrigin" Location);
        
GetEntPropVector(entity Prop_Send "m_angRotation" Angles);
        
        
/* You Should Take Care Of Angles ,
        Especially Those Who Are Located On Tables Or Cabinet*/
        
        
Angles[0]=0.0;
        
Angles[2]=0.0;
        
        
DispatchSpawn(entCreated);
        
TeleportEntity(entCreated Location Angles NULL_VECTOR);
        
SetEntityMoveType(entCreatedMOVETYPE_PUSH);
    }
    
AcceptEntityInput(entity,"Kill");

Another Method Of Saving References (Instead of Timers) , Which Is RequestFrame Function ,
And Here Is A Simple Example :

PHP Code:
public void OnEntityCreated(int entity, const char[] classname)
{
    if(
StrContains(classname"_rifle"false) != -1)
    {
        
RequestFrame(NextFrameCallback_Entity_Created EntIndexToEntRef(entity) )
    }
}

public 
void NextFrameCallback_Entity_Created(int entity)
{
    
entity EntRefToEntIndex(entity);
    
    if (!
IsValidEntity(entity)) return;        //it had been removed somehow
    
    // The entiy Now Is Valid And it's name contains : "_rifle"    

Another Method Of Saving References Which Is SDKHook ,

PHP Code:
public void OnEntityCreated(int entity, const char[] classname)
{
    if(
StrContains(classname"_any"false) != -1)
    {
        
SDKHook(entitySDKHook_SpawnPostOnEntityContains_anySpawnedCallBack); // This Will Save The Reference 
    
}
}

public 
OnEntityContains_anySpawnedCallBack(entityx)
{
    
//The entityx Is Valid And its Name Contains "_any"


Last edited by 101; 01-26-2024 at 10:38.
101 is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 01-26-2024 , 13:19   Re: [l4d2] how to keep specific entity id when chapter changing
Reply With Quote #5

I think he means when map transition/round ends (map transition from one chapter to another)
If you only need the player "equipped" weapons then you can store their slots in array and set again after map starts.
__________________
Marttt is offline
101
Member
Join Date: Nov 2023
Old 01-26-2024 , 14:47   Re: [l4d2] how to keep specific entity id when chapter changing
Reply With Quote #6

Quote:
Originally Posted by Marttt View Post
I think he means when map transition/round ends (map transition from one chapter to another)
If you only need the player "equipped" weapons then you can store their slots in array and set again after map starts.
Then he has to store their weapons class-name instead of weapons id , because networked entities should B destroyed during map/round end
101 is offline
101
Member
Join Date: Nov 2023
Old 01-27-2024 , 08:49   Re: [l4d2] how to keep specific entity id when chapter changing
Reply With Quote #7

PHP Code:
#include <sdkhooks>
#define STAR  "★ new ★"

char P_Weapons[MAXPLAYERS+1][7][32];    // 7 is a Fake value of weapon-slots Number (I don't Know How Many ur Game Supports)

public OnClientPostAdminCheck(P)
{
    
SDKHook(PSDKHook_WeaponEquipOn_WeaponEquiped);
}

public 
On_WeaponEquiped(P,Weapon
{
    
RequestFrame(NextFrameCallback_Weapon_Check P);
}

public 
void NextFrameCallback_Weapon_Check(P)
{
    
PrintToConsole(P,"\n--------------------------WeaponBagRefreshed--------------------------");
    
    
int Hand_Weapon GetEntPropEnt(PProp_Send"m_hActiveWeapon");
    
int CBagWeapons GetEntPropArraySize(P,Prop_Send"m_hMyWeapons");    //Number of Weapons in Client Bag 
    
int iWeapon;
    
    while(
CBagWeapons--)    // Loop To Check The Bag of Client
    
{                
        
iWeapon GetEntPropEnt(PProp_Send"m_hMyWeapons"CBagWeapons);    //The World [Weapon/Edict] index Ordered by :Current Bag Weapon Index
        
if(iWeapon 0// Is Valid In The "World" ? 
        
{
            
GetEdictClassname(iWeapon P_Weapons[P][CBagWeapons], 32);
            
PrintToConsole(P,"\nWeapon bag index %d Stored as name : %s [Edict index %d]    %s",CBagWeapons,P_Weapons[P][CBagWeapons],iWeapon iWeapon == Hand_Weapon STAR "");
        }
    }
    
PrintToConsole(P,"\n---------------------------------------------------------------------");

I didn't Check , U Can Do it , Also U can Store Those Weapons in array of integers , Then Use Hook OnEntityDestroyed to check If The Entity Destroyed Is Equal To Ur Weapon Index (That u stored In The Array).
Note : I didn't Create An Array Of Integers To Store Weapons IDs, Try It Urself , I believe they will be destroyed when map changed , Hint urself By LogMessage Or PrintToServer .

Last edited by 101; 01-27-2024 at 08:53.
101 is offline
zonbarbar
Member
Join Date: Jul 2022
Old 01-28-2024 , 01:28   Re: [l4d2] how to keep specific entity id when chapter changing
Reply With Quote #8

Quote:
Originally Posted by 101 View Post
PHP Code:
#include <sdkhooks>
#define STAR  "★ new ★"

char P_Weapons[MAXPLAYERS+1][7][32];    // 7 is a Fake value of weapon-slots Number (I don't Know How Many ur Game Supports)

public OnClientPostAdminCheck(P)
{
    
SDKHook(PSDKHook_WeaponEquipOn_WeaponEquiped);
}

public 
On_WeaponEquiped(P,Weapon
{
    
RequestFrame(NextFrameCallback_Weapon_Check P);
}

public 
void NextFrameCallback_Weapon_Check(P)
{
    
PrintToConsole(P,"\n--------------------------WeaponBagRefreshed--------------------------");
    
    
int Hand_Weapon GetEntPropEnt(PProp_Send"m_hActiveWeapon");
    
int CBagWeapons GetEntPropArraySize(P,Prop_Send"m_hMyWeapons");    //Number of Weapons in Client Bag 
    
int iWeapon;
    
    while(
CBagWeapons--)    // Loop To Check The Bag of Client
    
{                
        
iWeapon GetEntPropEnt(PProp_Send"m_hMyWeapons"CBagWeapons);    //The World [Weapon/Edict] index Ordered by :Current Bag Weapon Index
        
if(iWeapon 0// Is Valid In The "World" ? 
        
{
            
GetEdictClassname(iWeapon P_Weapons[P][CBagWeapons], 32);
            
PrintToConsole(P,"\nWeapon bag index %d Stored as name : %s [Edict index %d]    %s",CBagWeapons,P_Weapons[P][CBagWeapons],iWeapon iWeapon == Hand_Weapon STAR "");
        }
    }
    
PrintToConsole(P,"\n---------------------------------------------------------------------");

I didn't Check , U Can Do it , Also U can Store Those Weapons in array of integers , Then Use Hook OnEntityDestroyed to check If The Entity Destroyed Is Equal To Ur Weapon Index (That u stored In The Array).
Note : I didn't Create An Array Of Integers To Store Weapons IDs, Try It Urself , I believe they will be destroyed when map changed , Hint urself By LogMessage Or PrintToServer .
what kind of array do i neet to create , can i create a array of shooting speeds and then put some weapon in the array
zonbarbar is offline
101
Member
Join Date: Nov 2023
Old 02-05-2024 , 11:41   Re: [l4d2] how to keep specific entity id when chapter changing
Reply With Quote #9

Quote:
Originally Posted by zonbarbar View Post
what kind of array do i neet to create , can i create a array of shooting speeds and then put some weapon in the array
I have never tested weapons props , And i don't know how their props are changed in the game . unfortunately I didn't found any clear guide in sourcemod section or any helpful plugin that tracks weapons networked-props , especially in l4d . btw , I suggest you to keep the default weapons settings rather than downloading any custom plugin "I mean those that use OnWeaponFire hook or OnTakeDmg hook that forcing the game to duplicate the calculations twice sometimes " , and the most annoying thing is that they do a loop of checking for weapons names/IDs every f frame/bullet-fired (every millisecond) , But if u still intent to do so.. its up to you . Or , there will be two perfect solutions 4 u :

1) Edit the *.txt weapons files that located in scripts folder and change each weapon settings to match ur desire , But u still need to change those Cvars Values : sv_consistency 0 and sv_pure 0 , then restart ur server , This is a full guide :https://steamcommunity.com/sharedfil...?id=1060964738

2) while ur game is l4d then u r lucky to use this plugin that is safely recommended alternatively :
https://forums.alliedmods.net/showthread.php?p=2614626. this is perfect since it didn't check every frame to modify the weapons-attributes , It just reads their values from a cfg file and overwrites the original ones

Finally , The only thing that i can help u with in this field is : modifying the dmg dynamically during the gameplay based on : Weapons Types And Players Levels/Flags in The cheapest way possible ,I mean (less cpu usage) -still guess so -
101 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 11:23.


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