Raised This Month: $51 Target: $400
 12% 

Solved read char by char from arguments (and other questions)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
nacknic
Senior Member
Join Date: Mar 2019
Old 03-24-2019 , 04:10   read char by char from arguments (and other questions)
Reply With Quote #1

its my third day of learning pawn/amxmodx... , and im new in this forum.

i want to read char by char from arguments, read_args()/read_argv() not helped.
after hour, found getarg(), and i think that`s what i needed, but when i print, instead of char, i get N, why ?

picture: https://imgur.com/a/9qt0dcq
Code:
 
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "nacknic"


public plugin_init() {
	register_plugin(PLUGIN, VERSION, AUTHOR)
	register_clcmd("say", "xmath")
}

public xmath(id)
{
	new args[51], len_args, i = 0, c[51]
	read_args(args, charsmax(args))
	len_args = strlen(args)
	while(i <= len_args)
	{
		client_print(id, print_chat, "%c", getarg(i))
		client_print(id, print_chat, "next char:")
		i++
	}	
}
next question: what setarg() do ? by name its set, but cant be true argumnets that somthing you get....

next question: if i want call function from function, how i do that ?
Code:
public fun1(id)
{
         new x, y
         fun2(x, y)
}

public fun2(x , y)
{
         z = x + y
}
last question: why it`s not write what the warning is ?
picture: https://imgur.com/a/tbqIdfN

Last edited by nacknic; 03-28-2019 at 08:04. Reason: add somthing
nacknic is offline
Airkish
AlliedModders Donor
Join Date: Apr 2016
Location: Lithuania
Old 03-24-2019 , 05:03   Re: read char by char from arguments (and other questions)
Reply With Quote #2

#1
PHP Code:
#include <amxmodx>
#include <amxmisc>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "nacknic"


public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_clcmd("say""xmath")
}

public 
xmath(id)
{
    new 
szText[64];
    
read_args(szTextcharsmax(szText));
    
remove_quotes(szText);
    new 
iLen strlen(szText);

    for(new 
iiLeni++) {
        
client_print(idprint_chat"Char #%d: %c"iszText[i]);
    }

#2
https://www.amxmodx.org/api/core/setarg

#3
PHP Code:
public funcToCaLlFrom(id)
{
         new 
xy;
         
funcToCall(xy);
}

public 
funcToCall(xy)
{
    new 
z;
    
y;

#4
Probably indentation (make sure you indent with tabs, not spaces).
__________________

Last edited by Airkish; 03-24-2019 at 05:04.
Airkish is offline
<VeCo>
Veteran Member
Join Date: Jul 2009
Location: Bulgaria
Old 03-24-2019 , 05:26   Re: read char by char from arguments (and other questions)
Reply With Quote #3

1.2. set/getarg are core natives for direct work with function arguments mostly for making APIs (specifically in case you have an unknown number of them), you'd probably never use them though. dhudmessage.inc uses them to parse multilingual strings, for example.

3. If you want to use that function to get the value of the sum, you can directly
PHP Code:
return 
4. Scroll up, lol. In your case, you got a warning because the c[51] array is never used.
__________________
<VeCo> is offline
nacknic
Senior Member
Join Date: Mar 2019
Old 03-24-2019 , 06:54   Re: read char by char from arguments (and other questions)
Reply With Quote #4

Quote:
Originally Posted by Airkish View Post
#1
PHP Code:
#include <amxmodx>
#include <amxmisc>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "nacknic"


public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_clcmd("say""xmath")
}

public 
xmath(id)
{
    new 
szText[64];
    
read_args(szTextcharsmax(szText));
    
remove_quotes(szText);
    new 
iLen strlen(szText);

    for(new 
iiLeni++) {
        
client_print(idprint_chat"Char #%d: %c"iszText[i]);
    }

#2
https://www.amxmodx.org/api/core/setarg

#3
PHP Code:
public funcToCaLlFrom(id)
{
         new 
xy;
         
funcToCall(xy);
}

public 
funcToCall(xy)
{
    new 
z;
    
y;

#4
Probably indentation (make sure you indent with tabs, not spaces).
thank you for answer me with real code (and not just explanation, pawn and amxmodx new to me so its really helps) i`m glad to be member in this support community.
i have more two very simple questions:
#5 how i write notes in other language //non-english (its give gibberish (unknown words)).
#6 how print in this command client_print(id, print_chat, " ") in other language

Last edited by nacknic; 03-24-2019 at 07:29. Reason: add
nacknic is offline
nacknic
Senior Member
Join Date: Mar 2019
Old 03-24-2019 , 06:59   Re: read char by char from arguments (and other questions)
Reply With Quote #5

Quote:
Originally Posted by nacknic View Post
thank you for answer me with real code (and not just explanation, pawn and amxmodx new to me so its really helps) i`m glad to be member in this support community.
ok, i never use get/setarg()... I will not bother to laern what they do.
so all native function not really useful ?

and about the example that i write fuction call function for sum, i know i can do it in one function,
but my real goal was to learn how call function from another function.

and thank you the command about warning to scroll LOL
nacknic is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 03-24-2019 , 07:26   Re: read char by char from arguments (and other questions)
Reply With Quote #6

PHP Code:
public fun1(id)
{
         new 
xy
         fun2
(xy)
}

public 
fun2(y)
{
         
y

Looks fine to me, what is the issue?
__________________
HamletEagle is offline
nacknic
Senior Member
Join Date: Mar 2019
Old 03-24-2019 , 07:32   Re: read char by char from arguments (and other questions)
Reply With Quote #7

Quote:
Originally Posted by HamletEagle View Post
PHP Code:
public fun1(id)
{
         new 
xy
         fun2
(xy)
}

public 
fun2(y)
{
         
y

Looks fine to me, what is the issue?
no issue its the part of answer he give me...
if here two questions please:
#5 how i write notes in other language //non-english (its give gibberish (unknown words)).
#6 how print in this command client_print(id, print_chat, " ") in other language
nacknic is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 03-24-2019 , 07:44   Re: read char by char from arguments (and other questions)
Reply With Quote #8

Quote:
#6 how print in this command client_print(id, print_chat, " ") in other language
Just write the message in another language?

Obviously there is a better way, the ML system which allows you to store messages in a file for multiple languages and it will automatically choose the right version for the player, but since you are a beginner I wouldn't bother with it for now.
__________________
HamletEagle is offline
Old 03-24-2019, 08:38
nacknic
This message has been deleted by nacknic.
Old 03-24-2019, 08:50
nacknic
This message has been deleted by nacknic. Reason: worng
nacknic
Senior Member
Join Date: Mar 2019
Old 03-24-2019 , 08:52   Re: read char by char from arguments (and other questions)
Reply With Quote #9

@HamletEagle
of course i checked before i ask, not work ;(
picture: https://imgur.com/a/YIBk7jO

Last edited by nacknic; 03-24-2019 at 08:53.
nacknic is offline
nacknic
Senior Member
Join Date: Mar 2019
Old 03-24-2019 , 09:18   Re: read char by char from arguments (and other questions)
Reply With Quote #10

Quote:
Originally Posted by Airkish View Post
#1
PHP Code:
#include <amxmodx>
#include <amxmisc>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "nacknic"


public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_clcmd("say""xmath")
}

public 
xmath(id)
{
    new 
szText[64];
    
read_args(szTextcharsmax(szText));
    
remove_quotes(szText);
    new 
iLen strlen(szText);

    for(new 
iiLeni++) {
        
client_print(idprint_chat"Char #%d: %c"iszText[i]);
    }

#2
https://www.amxmodx.org/api/core/setarg

#3
PHP Code:
public funcToCaLlFrom(id)
{
         new 
xy;
         
funcToCall(xy);
}

public 
funcToCall(xy)
{
    new 
z;
    
y;

#4
Probably indentation (make sure you indent with tabs, not spaces).
thanks to your help, i success what i want to do:
in your script you do loop and print string/sub-strings like chars by usin %c in print coomand.
i added format() because i want really change to chars to read and exam char by char:
Code:
#include <amxmodx>
#include <amxmisc>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "nacknic"


public plugin_init() {
    register_plugin(PLUGIN, VERSION, AUTHOR)
    register_clcmd("say", "xmath")
}

public xmath(id)
{
    new args[64], c[64];
    read_args(args, charsmax(args));
    remove_quotes(args);
    new iLen = strlen(args);

    for(new i; i < iLen; i++) {
    	format(c[i], charsmax(c), "%c", args[i]);
    }
    
    if(c[0] == '!' && c[1] == 'c') client_print(id, print_chat, "work");
    else client_print(id, print_chat, "didn't works");
}
is there efficient way , read char and not format to char like i do ?
nacknic 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:05.


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