Raised This Month: $ Target: $400
 0% 

[SOLVED] Problem with a native that returns a string


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 10-23-2015 , 09:35   [SOLVED] Problem with a native that returns a string
Reply With Quote #1

PHP Code:
new const g_szNotFound[] = "Not Found"

new const g_szModels[][] = {
    
"weapon_mp5navy""Balrog Ethereal""models/iplay_furien/v_ethereal.mdl""models/iplay_furien/p_ethereal.mdl""models/iplay_furien/w_ethereal.mdl""models/w_mp5.mdl"
}

public 
plugin_natives()
{
    
register_library("furien_weapons")
    
register_native("furien_get_weaponname""_furien_get_weaponname")
}

public 
_furien_get_weaponname(szWeapon[])
{
    static 
szName[32]
    
    for(new 
0sizeof(g_szModels) - 5+= 6)
    {
        if(
equali(szWeapong_szModels[i]))
            
formatex(szNamecharsmax(szName), "%s"g_szModels[1])
    }
    
    
formatex(szNamecharsmax(szName), "%s"g_szNotFound)
    return 
szName

The result is this: http://i.imgur.com/13e4iNk.jpg
I'm using furien_get_weaponname("weapon_mp5navy"). I have no idea how I'm getting the last sound that was played, instead of the weapon's name, which in this case is "Balrog Ethereal".

Last edited by OciXCrom; 10-25-2015 at 10:54.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 10-23-2015 , 09:57   Re: [Help ASAP] Problem with a native that returns a string
Reply With Quote #2

Don't do that, pass string by reference.
__________________
Arkshine is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 10-23-2015 , 10:02   Re: [Help ASAP] Problem with a native that returns a string
Reply With Quote #3

By reference? Could you please explain, since I have no idea what that means?
OciXCrom is offline
Send a message via Skype™ to OciXCrom
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 10-23-2015 , 10:38   Re: [Help ASAP] Problem with a native that returns a string
Reply With Quote #4

Don't return a string, this was said 1000th times already, I am not sure why people keep doing this. It just stupid.

You have some natives called get_string/set_string, search for them. Also the loop looks silly, instead of it check if g_szModels[0] is the name that you get from the native(get_string) and use set_string with g_szModels[1].

Keep in mind that you are working with natives registered with style 0, so they don't pass the parameters. They only pass the plugin index and the param num. You have to use specific natives to get the params value(get_param/get_string etc).
__________________

Last edited by HamletEagle; 10-23-2015 at 10:42.
HamletEagle is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 10-23-2015 , 12:47   Re: [Help ASAP] Problem with a native that returns a string
Reply With Quote #5

PHP Code:
public _furien_get_weaponname(szWeapon[], szString)
{
    new 
i
    
    
for(0sizeof(g_szModels) - 3+= 4)
    {
        if(
equali(szWeapong_szModels[i]))
            
set_string(1g_szModels[1], get_param(2))
    }
    
    return 
1
}

native furien_get_weaponname(szWeapon[], szString[], const iMax)

public 
test(id)
{
    new 
szName[32]
    
furien_get_weaponname("weapon_mp5navy"szNamecharsmax(szName))
    
client_print(idprint_chat"%s"szName)

//Edit: The "test" function returns a blank string.

Last edited by OciXCrom; 10-23-2015 at 13:10.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 10-23-2015 , 15:22   Re: [Help ASAP] Problem with a native that returns a string
Reply With Quote #6

I told you, you don't have any of the native params passed in the function header(public _furien_get_weaponname(szWeapon[], szString) should be _furien_get_weaponname(PluginIndex, PluginParams)).

So this is wrong:
PHP Code:
if(equali(szWeapong_szModels[i])) 
Use get_string to retrieve the passed string. Also set_string(1,...) should be set_string(2,...), because the second param is your buffer.

But, what do you want to do ? The loop does not make sense. You want to return only the weapon name associated with weapon_* ?
__________________

Last edited by HamletEagle; 10-23-2015 at 15:24.
HamletEagle is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 10-23-2015 , 15:43   Re: [Help ASAP] Problem with a native that returns a string
Reply With Quote #7

I want to get the weapon name that corresponds to the given weapon, so if the weapon is "weapon_mp5navy", I would get "Balrog Ethereal". Ignore the other things in the array, because this isn't the full code of the plugin.

So, I changed it like this now:

PHP Code:
public _furien_get_weaponname(PluginIndexPluginParams)
{
    new 
szWeapon[32], i
    get_string
(PluginParamsszWeaponcharsmax(szWeapon))
    
    for(
0sizeof(g_szModels) - 3+= 4)
    {
        if(
equali(szWeapong_szModels[i]))
        {
            
set_string(2g_szModels[1], get_param(2))
            break
        }
    }
    
    return 
1

And the native is:

PHP Code:
native furien_get_weaponname(szWeapon[], szString[], const iMax
The test function:

PHP Code:
public test(id)
{
    new 
szName[32]
    
furien_get_weaponname("weapon_mp5navy"szNamecharsmax(szName))
    
client_print(idprint_chat"The name is %s"szName)

I'm still not getting the desired name.

This is what I'm trying to do - http://i.imgur.com/RS7k4sa.jpg
I made the image with a simple array of strings in the same plugin, but I want to add the name in my other plugin, where all the weapon models are.

Last edited by OciXCrom; 10-23-2015 at 15:46.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 10-23-2015 , 15:55   Re: [Help ASAP] Problem with a native that returns a string
Reply With Quote #8

PluginParams is the number of parameters. You pass the weapon name as the first argument, so it should be get_string(1,....).
__________________
HamletEagle is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 10-24-2015 , 08:26   Re: [Help ASAP] Problem with a native that returns a string
Reply With Quote #9

It works now. Thank you!
OciXCrom is offline
Send a message via Skype™ to OciXCrom
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 22:07.


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