AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Help Me Optimize? (https://forums.alliedmods.net/showthread.php?t=294630)

hellmonja 03-03-2017 22:33

Help Me Optimize?
 
1 Attachment(s)
Hi everyone. This has been a project of mine for more than a year now and I humbly seek help optimizing it. It adds an extra weapon in CS 1.6, no surprise there. But I wanted it to behave like a real CS weapon in every way. Now that it's working smoothly in-game I wanted to get it as optimized as possible, something I'm not good at. It's a mish-mash of code I've found around the net so that's why its pretty non-efficient so I hope you could help me.

Please bear with me. I'm not a very good coder and I might ask you to explain things further. For that I apologize in advance.

I think the first order of business is getting rid of fakemeta_util. I know, f*ck me, right? But there's a ton of code relying on that module and I have no idea what to replace some if them with...

edon1337 03-04-2017 04:07

Re: Help Me Optimize?
 
Moving on from fakemeta_util is like the best and easiest choice.

Code:
FM_UTIL                      |   FUN          |     ENGINE             |      FAKEMETA                                          |    HAMSANWICH                                  |                |                        |                                                        |     fm_give_item                 |   give_item    |     \                  |      \                                                 |    ExecuteHam(Ham_Item_AddToPlayer..) fm_get_user_weapon_entity    |   \            |      \                 |       \                                                 |    get_pdata_cbase [OFFSET: m_pActiveItem]   fm_find_ent_by_owner         |    \           |     find_ent_by_owner  |      engfunc(EngFunc_FindEntityByString..) + pev_owner |     \

There's obviously a way to convert give_item to engine and Fakemeta but it's harder.

hellmonja 03-04-2017 05:08

Re: Help Me Optimize?
 
Did I do it right?

From:
PHP Code:

static weaponweapon fm_find_ent_by_owner(-1weapon_bizonentity

To:
PHP Code:

static weapon;
new 
entstrtypeclassname;
weapon engfunc(EngFunc_FindEntityByStringentstrtypeclassname

From:
PHP Code:

static entent fm_get_user_weapon_entity(idCSW_BIZON

To:
PHP Code:

const m_pActiveItem 373;
...
static 
ent;
ent get_pdata_cbase(idm_pActiveItem); 

give_item is pretty easy so I didn't include it...

edon1337 03-04-2017 05:16

Re: Help Me Optimize?
 
Quote:

Originally Posted by hellmonja (Post 2500615)
PHP Code:

static weaponweapon fm_find_ent_by_owner(-1weapon_bizonentity

To:
PHP Code:

static weapon;
new 
entstrtypeclassname;
weapon engfunc(EngFunc_FindEntityByStringentstrtypeclassname

From:

I'd suggest engine but anyways.
Code:
engfunc(EngFunc_FindEntityByString, entity, "classname", weapon_bizon)

hellmonja 03-04-2017 05:31

Re: Help Me Optimize?
 
Thanks. So that's why it can't change the world model. Would engine be a lot better? Someone told me the fewer modules I use the better.

Hmm, when I switch weapons thirdperson, the Bizon player model doesn't go away. Like if I switch to my knife my player holds both knife and bizon. Same goes with pistols etc...

edon1337 03-04-2017 05:34

Re: Help Me Optimize?
 
Quote:

Originally Posted by hellmonja (Post 2500628)
Thanks. So that's why it can't change the world model. Would engine be a lot better? Someone told me the fewer modules I use the better.

No difference in performance, you tell me, would you rather type
PHP Code:

engfunc(EngFunc_FindEntityByStringentity"classname"weapon_bizon

instead of just
PHP Code:

find_ent_by_class 

Quote:

Originally Posted by hellmonja (Post 2500628)
Hmm, when I switch weapons thirdperson, the Bizon player model doesn't go away. Like if I switch to my knife my player holds both knife and bizon. Same goes with pistols etc...

It's because m_pActiveItem checks only the weapon you're using. Try with find_ent_by_owner.

hellmonja 03-04-2017 06:34

Re: Help Me Optimize?
 
Hey it works! Player model is now in order. So I guess I'll be using engine as well.

Will come back after dinner. There's still a couple of codes that needs replacing in order for me to get rid of fakemeta_util. All of them with prefix "xs_"...

edon1337 03-04-2017 06:34

Re: Help Me Optimize?
 
Quote:

Originally Posted by hellmonja (Post 2500646)
Hey it works! Player model is now in order. So I guess I'll be using engine as well.

Will come back after dinner. There's still a couple of codes that needs replacing in order for me to get rid of fakemeta_util. All of them with prefix "xs_"...

xs_ natives are from xs module not fakemeta_util.

hellmonja 03-04-2017 07:10

Re: Help Me Optimize?
 
1 Attachment(s)
Quote:

Originally Posted by edon1337 (Post 2500647)
xs_ natives are from xs module not fakemeta_util.

Waw. That was stupid of me. Thanks! I removed fakemeta_util and did a quick test and it works fine.

I guess the next stage is the flow of the plugin itself.

Just curious: What's up with fakemeta_util? Why does it have some functions of other modules and why is it avoided like the plague?...

edon1337 03-04-2017 07:59

Re: Help Me Optimize?
 
Quote:

Originally Posted by hellmonja (Post 2500654)
Just curious: What's up with fakemeta_util? Why does it have some functions of other modules and why is it avoided like the plague?...

Because it uses the existing natives to do the same thing just in a fakemeta way. So you're basically using 2 natives instead of 1.


All times are GMT -4. The time now is 20:48.

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