Innos Posted February 3, 2012 Posted February 3, 2012 Hi, how is the best & easier way to show my Zeny in this format? Its a sql banker. currently i use a second row only for show with "FORMAT(`showzeny`,0)" and set showzeny,prozeny; i don't know how i can change in this format only in the npc. thanks. Quote
Terces Posted February 3, 2012 Posted February 3, 2012 if(.@value > 1000){ for(set .@x,1000; .@x < .@value; set .@x,.@x*1000){ set .@temp,.@value % .@x; if(.@newvalue$) set .@newvalue$,"."+.@newvalue; set .@newvalue$,.@temp+.@newvalue; } } else set .@newvalue$, .@value; I just made that up and I have no idea if it works the way I wanted it to....but it is an idea, nay? btw...".@value" is the value you want to format and ".@newvalue$" is the string you get out of it. Quote
KeyWorld Posted February 3, 2012 Posted February 3, 2012 @Terces I'm not sure since of your function (the modulo part isn't good I thing: for 12, it return "12" instead of "012" if I'm not wrong). Well, writing from scratch, but should work in theory (don't have my scripts right now). //callfunc( "int_format", 1055183018 ); // you can add a second argument for the separator, default ",". function script int_format { set .@int, getarg(0); set .@sep$, getarg(1,","); set .@str$, ""; if ( .@int < 0 ) { set .@int, -.@int; set .@neg, 1; } set .@len, getstrlen(.@int+"") - .@neg; for ( set .@i,0; .@i<.@len; set .@i,.@i+1 ) set .@str$, ( .@i % 3 == 2 && 1 < .@len-1 ? .@sep$ : "" ) + ( .@int / pow(10,.@i) ) % 10 + .@str$; return ( .@neg ? "-" : "" ) + .@str$; } Quote
Terces Posted February 3, 2012 Posted February 3, 2012 the modulo really isn't a clever choice, as I have noticed. Also....I noticed some typos and it won't work anyway. I wanted to create an easy and short version, that didn't require a special function....failed at that, it seems. Quote
KeyWorld Posted February 3, 2012 Posted February 3, 2012 Maybe better (if I'm not wrong how insertchar() works): function script int_format { set .@int$, getarg(0)+""; set .@sep$, getarg(1,","); set .@l, getstrlen(.@sep$); set .@len, getstrlen(.@int$); for ( set .@i,.@len-3; .@i>0; set .@i, .@i-3-.@l ) set .@int$, insertchar( .@int$, .@sep$, .@i ); return .@int$; } 1 Quote
Innos Posted February 3, 2012 Author Posted February 3, 2012 (edited) Thanks. i have testing , but i mean i'm to stupid for this ^^ Edited February 3, 2012 by InnosTM Quote
Emistry Posted February 3, 2012 Posted February 3, 2012 the script posted by KeyWorld has work... prontera,155,181,5 script Sample 757,{ set .@i$,callfunc( "int_format", 1055183018 ); mes .@i$; close; } function script int_format { set .@int, getarg(0); set .@sep$, getarg(1,","); set .@str$, ""; if ( .@int < 0 ) { set .@int, -.@int; set .@neg, 1; } set .@len, getstrlen(.@int+"") - .@neg; for ( set .@i,0; .@i<.@len; set .@i,.@i+1 ) set .@str$, ( .@i % 3 == 2 && 1 < .@len-1 ? .@sep$ : "" ) + ( .@int / pow(10,.@i) ) % 10 + .@str$; return ( .@neg ? "-" : "" ) + .@str$; } you have to pass the value into the function..... set .@i$,callfunc( "int_format", <Value> ); mes .@i$; Quote
KeyWorld Posted February 3, 2012 Posted February 3, 2012 (edited) mes callfunc("int_format", .@prozeny); Too late. Edited February 3, 2012 by KeyWorld Quote
Emistry Posted February 3, 2012 Posted February 3, 2012 but i found a problem when i pass a value of Zeny..like this set .@i$,callfunc( "int_format", Zeny ); the result show like this as you can see..there is 1 extra comma infront of the result.... Quote
KeyWorld Posted February 3, 2012 Posted February 3, 2012 typo error. 1 < .@len-1 It's .@i < .@len-1 1 Quote
Innos Posted February 3, 2012 Author Posted February 3, 2012 (edited) you have to pass the value into the function.... This was only a test ^^ xDOk, works. great. Made my day. Thanks ^^ Many thanks KeyWorld Edited February 3, 2012 by InnosTM Quote
Question
Innos
Hi, how is the best & easier way to show my Zeny in this format?
Its a sql banker. currently i use a second row only for show with "FORMAT(`showzeny`,0)" and set showzeny,prozeny;
i don't know how i can change in this format only in the npc.
thanks.
10 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.