Raised This Month: $ Target: $400
 0% 

help to return an array through a native


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
georgik57
Veteran Member
Join Date: Oct 2008
Location: 🎧Music World
Old 03-20-2011 , 06:13   help to return an array through a native
Reply With Quote #1

i get a svc_bad error when using this native
please help me fix it
PHP Code:
register_native("zpnm_get_user_class_name""native_get_user_class_name"1
PHP Code:
public native_get_user_class_name(id)
{
    static class[
32]
    
    if (
g_zombie[id]) // zombies
    
{
        if (
g_nemesis[id])
            
formatex(class, charsmax(class), "%L"id"CLASS_NEMESIS")
        else
            
copy(class, charsmax(class), g_zombie_classname[id])
    }
    else 
// humans
    
{
        if (
g_survivor[id])
            
formatex(class, charsmax(class), "%L"id"CLASS_SURVIVOR")
        if (
g_sniper[id])
            
formatex(class, charsmax(class), "%L"id"CLASS_SNIPER")
        if (!
g_survivor[id] && !g_sniper[id])
            
copy(class, charsmax(class), g_human_classname[id])
    }
    
    return class;

__________________
georgik57 is offline
Send a message via MSN to georgik57 Send a message via Yahoo to georgik57 Send a message via Skype™ to georgik57
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 03-20-2011 , 06:18   Re: help to return an array through a native
Reply With Quote #2

set_string()
__________________
Arkshine is offline
georgik57
Veteran Member
Join Date: Oct 2008
Location: 🎧Music World
Old 03-20-2011 , 06:27   Re: help to return an array through a native
Reply With Quote #3

like this? :D
Code:
public native_get_user_class_name(id, name[], len) {     if (g_zombie[id]) // zombies     {         if (g_nemesis[id])             formatex(name, charsmax(name), "%L", id, "CLASS_NEMESIS")         else             copy(name, charsmax(name), g_zombie_classname[id])     }     else // humans     {         if (g_survivor[id])             formatex(name, charsmax(name), "%L", id, "CLASS_SURVIVOR")         if (g_sniper[id])             formatex(name, charsmax(name), "%L", id, "CLASS_SNIPER")         if (!g_survivor[id] && !g_sniper[id])             copy(name, charsmax(name), g_human_classname[id])     } }
__________________
georgik57 is offline
Send a message via MSN to georgik57 Send a message via Yahoo to georgik57 Send a message via Skype™ to georgik57
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 03-20-2011 , 06:40   Re: help to return an array through a native
Reply With Quote #4

If you stick with native style 1 (deprecated), you should be right.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
sk@.@
Senior Member
Join Date: Feb 2010
Location: Hong Kong
Old 03-20-2011 , 06:51   Re: help to return an array through a native
Reply With Quote #5

this is ok?

Code:
public native_get_user_class_name(id, name[], len) 
{    
    if (!is_user_alive(id))
        return 0;

    param_convert(2)

     if (g_zombie[id]) // zombies     
    {        
         if (g_nemesis[id])             
            formatex(name, charsmax(name), "%L", id, "CLASS_NEMESIS")         
        else             
            copy(name, charsmax(name), g_zombie_classname[id])     
    }    
    else // humans     
    {        
        if (g_survivor[id])            
            formatex(name, charsmax(name), "%L", id, "CLASS_SURVIVOR")        
         if (g_sniper[id])            
             formatex(name, charsmax(name), "%L", id, "CLASS_SNIPER")        
        if (!g_survivor[id] && !g_sniper[id])             
            copy(name, charsmax(name), g_human_classname[id])     
    } 

    return 1;
}
__________________
This is my Game-Blog:
http://hsk-game.blogspot.hk/
sk@.@ is offline
Send a message via MSN to sk@.@
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 03-20-2011 , 06:59   Re: help to return an array through a native
Reply With Quote #6

PHP Code:
new const CLASSNAMES[][] =
{
    
"NEMESIS",
    
"ASSASSIN",
    
"ZOMBIE",
    
"SURVIVOR",
    
"SNIPER",
    
"HUMAN"
}

public 
native_zp_get_user_class_name(id)
{
    static 
x
    
    
if (g_zombie[id])
    {
        if (
g_nemesis[id])
            
0    // NEMESIS
        
        
if (g_assassin[id])
            
1    // ASSASSIN
        
        
else
            
2    // ZOMBIE
    
}
    
    else
    {
        if (
g_survivor[id])
            
3    // SURVIVOR
        
        
if (g_sniper[id])
            
4    // SNIPER
        
        
if (!g_survivor[id] && !g_sniper[id])
            
5    // HUMAN
    
}
    
    return 
CLASSNAMES[x]

__________________
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
georgik57
Veteran Member
Join Date: Oct 2008
Location: 🎧Music World
Old 03-20-2011 , 07:34   Re: help to return an array through a native
Reply With Quote #7

thank you all for replying
i found a way thanks to nihilanth
http://forums.alliedmods.net/showpos...71&postcount=8
so i tried with this method
is this correct?
PHP Code:
public native_get_user_class_name(idname[], len)
{
    
// ZP disabled
    
if (!g_pluginenabled)
        return -
1;
    
    if (!
is_user_valid_connected(id)
    || !
is_user_valid_alive(id))
        return 
0;
    
    
param_convert(2)
    
    if (
g_zombie[id]) // zombies
    
{
        if (
g_nemesis[id])
            return 
formatex(namelen"%L"id"CLASS_NEMESIS")
        else
            return 
copy(nameleng_zombie_classname[id])
    }
    else 
// humans
    
{
        if (
g_survivor[id])
            return 
formatex(namelen"%L"id"CLASS_SURVIVOR")
        if (
g_sniper[id])
            return 
formatex(namelen"%L"id"CLASS_SNIPER")
        if (!
g_survivor[id] && !g_sniper[id])
            return 
copy(nameleng_human_classname[id])
    }
    
    return 
1;

__________________
georgik57 is offline
Send a message via MSN to georgik57 Send a message via Yahoo to georgik57 Send a message via Skype™ to georgik57
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 03-20-2011 , 07:38   Re: help to return an array through a native
Reply With Quote #8

It is fine as long as you want to pass the string byref and that you want to return the string length, also your last return in that case should rather be -1 or 0
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
georgik57
Veteran Member
Join Date: Oct 2008
Location: 🎧Music World
Old 03-20-2011 , 07:50   Re: help to return an array through a native
Reply With Quote #9

i'll give a example showing how i want to use this string like
PHP Code:
client_print(0print_chat"Player's current class is %s"zpnm_get_user_class_name(Player)) 
can you please correct my code?
__________________
georgik57 is offline
Send a message via MSN to georgik57 Send a message via Yahoo to georgik57 Send a message via Skype™ to georgik57
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 03-20-2011 , 08:02   Re: help to return an array through a native
Reply With Quote #10

PHP Code:
new szClass[32]
zpnm_get_user_class_name(PlayerszClasscharsmax(szClass))
client_print(0print_chat"Player's current class is %s"szClass
You doesn't seem to understand what you do, try to learn bases first.
__________________
- 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 14:32.


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