Raised This Month: $ Target: $400
 0% 

get_user_weapon or native?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
baneado
Veteran Member
Join Date: Dec 2012
Location: amxmodx-es.com
Old 11-06-2013 , 08:50   get_user_weapon or native?
Reply With Quote #1

I have a simple doubt, in a plugin there is a variable that contains the current weapon having a player.
This variable exists for prevent calling get_user_weapon many times, because would be called in events like takedamage, traceattack...

The variable works perfectly in the plugin, buy I have some subplugins that are using get_user_weapon in client_PreThink or other forwards, and the question is

What is more efficient method: calling get_user_weapon or make native with the main plugin to use it instead of get_user_weapon ?

I say get_user_weapon like an example, but the same with is_user_alive, is_user_connected...

Thanks
baneado is offline
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 11-06-2013 , 10:23   Re: get_user_weapon or native?
Reply With Quote #2

In case of get_user_weapon you allowed to cache using CurWeapon Event, and checking in takedamage or other events.

In case of is_user*, this need to be called when the function starts (takedamage, etc)

__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
alan_el_more
Veteran Member
Join Date: Jul 2008
Location: amxmodx-es.com
Old 11-06-2013 , 11:09   Re: get_user_weapon or native?
Reply With Quote #3

Quote:
Originally Posted by ^SmileY View Post
In case of get_user_weapon you allowed to cache using CurWeapon Event, and checking in takedamage or other events.

In case of is_user*, this need to be called when the function starts (takedamage, etc)

You don't answer his question.
He want to know which method is more efficient
__________________
alan_el_more is offline
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 11-06-2013 , 11:16   Re: get_user_weapon or native?
Reply With Quote #4

Quote:
Originally Posted by alan_el_more View Post
You don't answer his question.
He want to know which method is more efficient
Really? What do you think I mean by this post?
Who asked you surely know what I'm answering.
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
baneado
Veteran Member
Join Date: Dec 2012
Location: amxmodx-es.com
Old 11-06-2013 , 12:17   Re: get_user_weapon or native?
Reply With Quote #5

Quote:
Originally Posted by ^SmileY View Post
Really? What do you think I mean by this post?
Who asked you surely know what I'm answering.
No, you don't understand me.
baneado is offline
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 11-06-2013 , 17:32   Re: get_user_weapon or native?
Reply With Quote #6

For forwards, you need to make it to use with other plugins, i recommend to use using CurWeapon event, because it is only called when player really change bettwen weapons.

__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 11-07-2013 , 00:20   Re: get_user_weapon or native?
Reply With Quote #7

Quote:
Originally Posted by ^SmileY View Post
For forwards, you need to make it to use with other plugins, i recommend to use using CurWeapon event, because it is only called when player really change bettwen weapons.

No not really. CurWeapon is called every time the clip ammo is updated, which means every time you fire a shot or when you change weapons.

@Baneado its hard to say unless you show your code or explain what your trying to do otherwise its really going to be XY problem. However, I can't imagine why you would need to use get_user_weapon() inside client_PreThink.
hornet is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 11-07-2013 , 00:47   Re: get_user_weapon or native?
Reply With Quote #8

I second that.

Anyway, your question is abstract, we need to know exactly what you are doing in plugins with PreThink so we can tell you if there are alternatives or not.
For sure, PreThink is a bad function to hook in many situations.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
baneado
Veteran Member
Join Date: Dec 2012
Location: amxmodx-es.com
Old 11-08-2013 , 08:55   Re: get_user_weapon or native?
Reply With Quote #9

Quote:
Originally Posted by hornet View Post
@Baneado its hard to say unless you show your code or explain what your trying to do otherwise its really going to be XY problem. However, I can't imagine why you would need to use get_user_weapon() inside client_PreThink.
Quote:
Originally Posted by ConnorMcLeod View Post
I second that.

Anyway, your question is abstract, we need to know exactly what you are doing in plugins with PreThink so we can tell you if there are alternatives or not.
For sure, PreThink is a bad function to hook in many situations.
It's simple, I have got a variable in the main plugin, this variable saves the currentweapon of a player. (of course this variable it's used in the plugin, I don't use get_user_weapon)

I asked about what is more efficient method for a subplugin, make a native or use get_user_weapon.

Native would be something like this:
PHP Code:
public native_weapon(id)
{
       if (!
is_user_valid_connected(id))
       {
               
//log error in a file...
               
return;
       }

        return 
g_wpn_current[id];

Then, in the subplugin what it's better, use the new native
PHP Code:
public client_PreThink(id)
{
       if (!
g_alive[id] || my_new_native_getweapon(id) != CSW_KNIFE)
               return;

or get_user_weapon??
PHP Code:
public client_PreThink(id)
{
       if (!
g_alive[id] || get_user_weapon(id) != CSW_KNIFE)
               return;


Last edited by baneado; 11-08-2013 at 08:58.
baneado is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 11-08-2013 , 12:31   Re: get_user_weapon or native?
Reply With Quote #10

Quote:
Originally Posted by baneado View Post
It's simple, I have got a variable in the main plugin, this variable saves the currentweapon of a player. (of course this variable it's used in the plugin, I don't use get_user_weapon)

I asked about what is more efficient method for a subplugin, make a native or use get_user_weapon.

Native would be something like this:
PHP Code:
public native_weapon(id)
{
       if (!
is_user_valid_connected(id))
       {
               
//log error in a file...
               
return;
       }

        return 
g_wpn_current[id];

Then, in the subplugin what it's better, use the new native
PHP Code:
public client_PreThink(id)
{
       if (!
g_alive[id] || my_new_native_getweapon(id) != CSW_KNIFE)
               return;

or get_user_weapon??
PHP Code:
public client_PreThink(id)
{
       if (!
g_alive[id] || get_user_weapon(id) != CSW_KNIFE)
               return;

There is no problem with get_user_weapon.
But don't hook PreThink.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod 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 23:13.


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