AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   send string to native (https://forums.alliedmods.net/showthread.php?t=125793)

Min2liz 05-02-2010 12:06

send string to native
 
Hi,

can anyone explain what I'm doing wrong or maybe can give short script for noob how need to do this.

i have main plugin with natives and sub-plugin with command /test For now I want to debug what's really works and try to print everything what I send to native, but don't work.

Main plugin:

Code:

public plugin_natives() {
        register_native("up_get_info","naive_get_info");
}
public naive_get_info(iPlugin,iParam) {       
        new id = get_param(1);
        new key[64];
        get_string(2,key,63);
        new txt[255]
        formatex(txt,254,"Key: %s ID: %s",key,id);
        return txt;
}

upanel.inc:

Code:

native up_get_info(id,key[])
sub-plugin:

Code:

#include <amxmodx>
#include <amxmisc>
#include <upanel>

public plugin_init() {       
        register_clcmd("say /test", "cmd_test");
       
}
public cmd_test(id) {
        client_print(id,print_chat,"test: %s",up_get_info(id,"test"));       
}

and I get strange things here. Of course have no idea why :)

Code:

test: <
Min2liz :  /test


Arkshine 05-02-2010 12:20

Re: send string to native
 
if I'm right, To set a string into the param 2 "key", format then after use set_string()

Exolent[jNr] 05-02-2010 12:49

Re: send string to native
 
Code:

formatex(txt,254,"Key: %s ID: %s",key,id);
"id" is an integer, not a string.
You didn't format correctly.

Also, I don't think you can return strings through natives.
(I may be wrong. Let me go check.)

Min2liz 05-02-2010 16:26

Re: send string to native
 
At this poin is working:
main plugin:
Code:

public native_get_info(iPlugin,iParam) {       
        new id = get_param(1);
        new key[255]
        get_string(2,key,255);
        set_string(1,key,255);
}

sub-plugin:
Code:

#include <amxmodx>
#include <amxmisc>
#include <upanel>

public plugin_init() {       
        register_clcmd("say /test", "cmd_test");
       
}
public cmd_test(id) {
        new test[255];
        test = "Test";
        up_get_info(id,test)
        client_print(id,print_chat,"test: %s",test);       
}

Maybe it's silly code but it's working. But now, how to change in native this string to anything else. Like if sub-plugin send "test", native return "test2"?

I tryed:
Code:

public native_get_info(iPlugin,iParam) {       
        new id = get_param(1);
        new key[255], test[255]
        get_string(2,key,255);
        test = "Test2";
        set_string(1,test,255);
}

but still get old one string "Test"

Exolent[jNr] 05-03-2010 19:25

Re: send string to native
 
You are using set_string() wrong.
The first argument is the argument of the native.
You are using "1", which is the "id".

AntiBots 05-03-2010 20:14

Re: send string to native
 
Also make.

get_somethingstring( id, buffer[], len);


Also if you want to return Strings, you can search for a module that I make "StringX".

Just return the pointer to the structure.


All times are GMT -4. The time now is 03:41.

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