Raised This Month: $ Target: $400
 0% 

Is it possible to show integer from string?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
KiLLeR.
Senior Member
Join Date: Jul 2014
Location: Bulgaria
Old 12-23-2014 , 10:13   Is it possible to show integer from string?
Reply With Quote #1

PHP Code:
new const str[] = "%i text...";
new 
integer 5;

formatex(textcharsmax(text), "%s"strinteger
Output is "%i text...", but I want to be "5 text...", this is impossible?

Sorry if the title is wrong!

Last edited by KiLLeR.; 02-26-2016 at 08:48.
KiLLeR. is offline
zmd94
Veteran Member
Join Date: Nov 2013
Location: Malaysia (9w2zow).
Old 12-23-2014 , 10:25   Re: It is possible to show integer from string?
Reply With Quote #2

Yes, you can.
PHP Code:
new const szString[] = "5 text" 
zmd94 is offline
KiLLeR.
Senior Member
Join Date: Jul 2014
Location: Bulgaria
Old 12-23-2014 , 10:36   Re: It is possible to show integer from string?
Reply With Quote #3

Quote:
Originally Posted by zmd94 View Post
Yes, you can.
PHP Code:
new const szString[] = "5 text" 
No, no, no, this will not help me, because integer variable never has the same value. Just i gave above code for example.
KiLLeR. is offline
Old 12-23-2014, 10:25
Arkshine
This message has been deleted by Arkshine. Reason: nvm
zmd94
Veteran Member
Join Date: Nov 2013
Location: Malaysia (9w2zow).
Old 12-23-2014 , 10:43   Re: It is possible to show integer from string?
Reply With Quote #5

Then, maybe I misunderstood you. Actually, what you want to do?
zmd94 is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 12-23-2014 , 10:45   Re: It is possible to show integer from string?
Reply With Quote #6

Quote:
Originally Posted by KiLLeR. View Post
PHP Code:
new const str[] = "%i text...";
new 
integer 5;

formatex(textcharsmax(text), "%s"strinteger
Output is "%i text...", but I want to be "5 text...", this is impossible?

Sorry if the title is wrong!

formatex(text, charsmax(text), str, integer)
__________________
Arkshine is offline
zmd94
Veteran Member
Join Date: Nov 2013
Location: Malaysia (9w2zow).
Old 12-23-2014 , 11:16   Re: It is possible to show integer from string?
Reply With Quote #7

Quote:
formatex(text, charsmax(text), str, integer)
Alright, now I got it.

Then, is it right, if I do such below?
PHP Code:
new const str[] = "%i text %i text %i text %i text";
new 
integer1 1
new integer2 2
new integer3 3
new integer4 4

formatex
(textcharsmax(text), strinteger1integer2integer3integer4
So, the output is "1 text 2 text 3 text 4 text".

Last edited by zmd94; 12-23-2014 at 11:21.
zmd94 is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 12-23-2014 , 11:29   Re: It is possible to show integer from string?
Reply With Quote #8

looks right, did you try it?
jimaway is offline
zmd94
Veteran Member
Join Date: Nov 2013
Location: Malaysia (9w2zow).
Old 12-23-2014 , 12:20   Re: It is possible to show integer from string?
Reply With Quote #9

I have tested the code and it is working fine. Below is test code:
PHP Code:
#include <amxmodx>

new const str[] = "%i text %i text %i text %i text";
new 
integer1 1
new integer2 2
new integer3 3
new integer4 4

new text[101]

public 
plugin_init()
{
    
register_plugin("Test""1.0""zmd94")
    
    
register_clcmd("say /test""clcmd_test")
    
    
formatex(textcharsmax(text), strinteger1integer2integer3integer4
}

public 
clcmd_test(id)
{
    
client_print(idprint_chat"%s"text)

zmd94 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-23-2014 , 18:09   Re: It is possible to show integer from string?
Reply With Quote #10

zmd94, that code is totally fine.

FYI, you can do this instead of the "%s", as long as the variable you are passing is a string:

PHP Code:
client_print(idprint_chattext
__________________

Last edited by Bugsy; 12-23-2014 at 18:09.
Bugsy 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 15:17.


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