AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   DispatchClass (https://forums.alliedmods.net/showthread.php?t=314206)

CrazY. 02-08-2019 10:35

DispatchClass
 
Hello, I wonder if it's possible to "implement" a class on a dummy entity (info_target).

Code:
new szClassName[32], pEdict; copy(szClassName, charsmax(szClassName), "info_target"); pEdict = create_entity(szClassName); if (!pEdict) {     server_print("create_entity: Couldn't create entity ^"%s^"", szClassName); } else {     DispatchClass(pEdict, "CBasePlayerWeapon");     // From there, CBasePlayerWeapon::ItemPostFrame (Ham_Item_PostFrame) for example, would be called in that entity }

E1_531G 02-08-2019 12:04

Re: DispatchClass
 
I think, internally it remains as "info_target" class. As far as you already have an entity index, it already has some classs.

klippy 02-08-2019 12:33

Re: DispatchClass
 
Why not create an entity that's linked to CBasePlayerWeapon instead of "info_target" in the first place?

CrazY. 02-08-2019 12:39

Re: DispatchClass
 
I noticed that it inherits CBasePlayerItem/CBasePlayerWeapon members, but not the functions. Anyway, probably this would be useless, I was thinking to "hack" info_target entity and make custom weapons from it.

Somehow it's possible if you remove default CS weapons and work with a amxx "recoded" version of weapons.cpp:

Code:
new m_pActiveItem[MAX_PLAYERS+1]; public client_PostThink(this) {     if (!is_user_alive(this))         return;     if (m_pActiveItem[this] != -1)     {         // Call "fake" post frame (Whatever_PostFrame)         ExecuteForward(ForwardPostFrame, _, m_pActiveItem[this]);     } } public Whatever_PostFrame(this) {     static pPlayer;     pPlayer = get_ent_data_entity(this, "CBasePlayerItem", "m_pPlayer");     if (pev(pPlayer, pev_button) & IN_ATTACK)     {         // Call "fake" primary attack (Whatever_PrimaryAttack)         ExecuteForward(ForwardPrimaryAttack, _, this);     } } public Whatever_PrimaryAttack(this) {     // Do primary attack }

But, many lines would have to be made and probably would be required orpheu or reapi to work with ApplyMultiDamage, AddMultiDamage, FireBullets3, etc. It's a idea to think about, since the only method that developers know and have nowadays it's "override" weapons. I'm not sure what're the good and bad points of my idea. If anyone wants to comment, feel free.


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

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