AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Retrieving strings using fake natives.....[Solved] (https://forums.alliedmods.net/showthread.php?t=132070)

abdul-rehman 07-11-2010 14:45

Retrieving strings using fake natives.....[Solved]
 
I tried many ways of retrieving strings using dynamic natives but i failed this is the main plugin that i was using:
Code:
#include <amxmodx> #include <amxmisc> public plugin_natives() {     register_native("get_persons_name", "_get_persons_name", 1) } public _get_persons_name(plugin, paramsnum) {     // No parameters passed     if(!paramsnum)         return -1         new name[32]     get_user_name(get_param(1), name, 30)     set_string(2, name, get_param(3))     return 1 }

sub plugin looks like this
i use the native to retrieve a persons name [Its just for testing purposes]
Code:
#include <amxmodx> #include <amxmisc> #include < name > public plugin_init() {     // Plugin registeration     register_plugin("-New","1.0","@bdul!")         register_clcmd("say test", "hook") } public hook(id) {     new name[32]     get_persons_name(id, name, charsmax(name))         client_print( id, print_chat, "******* Your Name : %s", name) }

Include file looks like this:
PHP Code:

#if defined _name_included
  #endinput
#endif
#define _name_included

native get_persons_nameid, const string[], len 

The Problem:
When i type test for checking i get this stupid run-time error:
PHP Code:

L 07/11/2010 23:27:57Wrong style of dynamic native
L 07
/11/2010 23:27:57: [AMXXRun time error 10 (plugin "example.amxx") (native "get_param") - debug not enabled!
L 07/11/2010 23:27:57: [AMXXTo enable debug modeadd "debug" after the plugin name in plugins.ini (without quotes).
L 07/11/2010 23:27:57Unhandled dynamic native error
L 07
/11/2010 23:27:57: [AMXXRun time error 10 (plugin "working.amxx") (native "get_persons_name") - debug not enabled!
L 07/11/2010 23:27:57: [AMXXTo enable debug modeadd "debug" after the plugin name in plugins.ini (without quotes). 

I dont know why these errors are occuring and due to this the native is not performing what it is supposed to do
So if please some one can help me then it would be great

Thnx in advance....

fysiks 07-11-2010 16:34

Re: Retrieving strings using fake natives.....I need Urgent Help PLZ
 
First of all you need to read this: "[AMXX] To enable debug mode, add "debug" after the plugin name in plugins.ini (without quotes)."

You are registering the native with style 1 but are actually using style 0.

There is also an error in the third param of get_user_nam(), it can't be hardcoded to work correclty.

abdul-rehman 07-11-2010 17:52

Re: Retrieving strings using fake natives.....I need Urgent Help PLZ
 
Quote:

Originally Posted by fysiks (Post 1235771)
First of all you need to read this: "[AMXX] To enable debug mode, add "debug" after the plugin name in plugins.ini (without quotes)."

You are registering the native with style 1 but are actually using style 0.

There is also an error in the third param of get_user_nam(), it can't be hardcoded to work correclty.

OK then i dont wont to enable debug mode and what should i do to make my native compatible with style 1 [If possible]

grimvh2 07-11-2010 19:53

Re: Retrieving strings using fake natives.....I need Urgent Help PLZ
 
at top of plugin_natives()

PHP Code:

register_library("includename"

and in include i use this

PHP Code:

#if defined _includename_included
    #endinput
#endif

#define _includename_included

#pragma reqlib includename 


fysiks 07-11-2010 20:24

Re: Retrieving strings using fake natives.....I need Urgent Help PLZ
 
Quote:

Originally Posted by abdul-rehman (Post 1235847)
OK then i dont wont to enable debug mode and what should i do to make my native compatible with style 1 [If possible]

If you don't want to enable debug mode then you obviously don't know what debug means.

Use style 0. If you want to use style 1 then you can find information about it the tutorials section (or elsewhere).

ConnorMcLeod 07-12-2010 01:28

Re: Retrieving strings using fake natives.....I need Urgent Help PLZ
 
Try this :

Code:

#include <amxmodx>

#define FIRST_PLAYER_ID 1

new g_iMaxPlayers
#define IsPlayer(%1)        ( FIRST_PLAYER_ID <= %1 <= g_iMaxPlayers )

#define CHECK_PLAYER(%1) \
        if( !IsPlayer(%1) ) \
        { \
                log_error(AMX_ERR_NATIVE, "Player out of range (%d)", %1); \
                return 0; \
        } \
        else if( !is_user_connected(%1) ) \
        { \
                log_error(AMX_ERR_NATIVE, "Invalid player (%d)", %1); \
                return 0; \
        }

public plugin_init()
{
        register_plugin("My Awesome Fake Native", "0.1", "ConnorMcLeod")

        g_iMaxPlayers = get_maxplayers()
}

public plugin_natives()
{
    register_native("get_persons_name", "get_persons_name", 0)
}

public get_persons_name(plugin, paramsnum) // get_persons_name(index, name[], len)
{
        if( paramsnum != 3 )
        {
                log_error(AMX_ERR_NATIVE, "Bad arguments num, expected 3, passed %d", paramsnum)
                return 0
        }

        new id = get_param(1)

        CHECK_PLAYER( id )   

        new name[32]
        get_user_name(id, name, charsmax(name))

        new len = get_param(3)
        name[len] = 0

        set_string(2, name, len)

        return 1
}


abdul-rehman 07-12-2010 02:49

Re: Retrieving strings using fake natives.....I need Urgent Help PLZ
 
Quote:

Originally Posted by ConnorMcLeod (Post 1236323)
Try this :

Code:

#include <amxmodx>

#define FIRST_PLAYER_ID 1

new g_iMaxPlayers
#define IsPlayer(%1)        ( FIRST_PLAYER_ID <= %1 <= g_iMaxPlayers )

#define CHECK_PLAYER(%1) \
        if( !IsPlayer(%1) ) \
        { \
                log_error(AMX_ERR_NATIVE, "Player out of range (%d)", %1); \
                return 0; \
        } \
        else if( !is_user_connected(%1) ) \
        { \
                log_error(AMX_ERR_NATIVE, "Invalid player (%d)", %1); \
                return 0; \
        }

public plugin_init()
{
        register_plugin("My Awesome Fake Native", "0.1", "ConnorMcLeod")

        g_iMaxPlayers = get_maxplayers()
}

public plugin_natives()
{
    register_native("get_persons_name", "get_persons_name", 0)
}

public get_persons_name(plugin, paramsnum) // get_persons_name(index, name[], len)
{
        if( paramsnum != 3 )
        {
                log_error(AMX_ERR_NATIVE, "Bad arguments num, expected 3, passed %d", paramsnum)
                return 0
        }

        new id = get_param(1)

        CHECK_PLAYER( id )   

        new name[32]
        get_user_name(id, name, charsmax(name))

        new len = get_param(3)
        name[len] = 0

        set_string(2, name, len)

        return 1
}


Conner one question...How can i make it compatible with style 1 if i want
if its possible then please tell me
btw thnks for your code i will use it as a backup...:up:

ConnorMcLeod 07-12-2010 06:57

Re: Retrieving strings using fake natives.....I need Urgent Help PLZ
 
from kz-arg

PHP Code:

public native_kz_get_configsdir(name[], len)
{
    
param_convert(1)
    
    new 
lalin[64]
    
get_localinfo("amxx_configsdir"lalin,63)
    
    return 
formatex(namelen"%s/%s"lalinKZ_DIR)



abdul-rehman 07-12-2010 11:57

Re: Retrieving strings using fake natives.....I need Urgent Help PLZ
 
Problem solved thnx to conner, fysiks and every one who responded to my thread.....i will give you credits in my next version of Zombie Plague Advance


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

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