AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   String manipulation (https://forums.alliedmods.net/showthread.php?t=61008)

[ --<-@ ] Black Rose 09-18-2007 15:06

String manipulation
 
So, rose is back... -_-'

Anyway..
I've got a problem and I must be fucking slow or something but no matter how much i try i can't solve it...
Script
Code:
#include <amxmodx> #include <amxmisc> #define prefix 1 #define g_len2 15 new g_string[1024] new g_len new g_file[128] = "addons/amxmodx/d2overhead.txt" new g_outfile[128] = "addons/amxmodx/d2overhead.ini" public plugin_init() {     register_plugin("D2 Overhead", "1.0", "[ --<-@ ]")         read_file(g_file, 0, g_string, 1023, g_len)         for ( new i = prefix ; i < g_len + 2 ; i++ ) {                 new putfile[64], k, l, m                 new len = formatex(putfile, 63, "%i=^"", i)                 for ( k = i ; k < g_len2 - i ; k++ )             len += formatex(putfile[len], 1, " ")                 for ( l = 0 ; l < g_len2 ; l++ )             len += formatex(putfile[len], 1, "%s", g_string[i + l - 1])                 for ( m = g_len2 - 1 ; m > g_len - i ; m-- )             len += formatex(putfile[len], 1, " ")                 formatex(putfile[len], 63-len, "^"")                 write_file(g_outfile, putfile)     } }

How it SHOULD look:
Code:

1="              O"
2="            O "
3="            O M"
4="          O Ma"
5="          O Mav"
6="        O Mavi"
7="        O Mavin"
8="      O Mavina"
9="      O Mavinas"
10="    O Mavinas "
11="    O Mavinas B"
12="  O Mavinas Bo"
13="  O Mavinas Bow"
14=" O Mavinas Bow,"
15="O Mavinas Bow, "
16=" Mavinas Bow, O"
17="Mavinas Bow, Oc"
18="avinas Bow, Occ"
19="vinas Bow, Occu"
20="inas Bow, Occu,"

How it DOES look:
Code:

1="            O Mavinas Bow, "
2="            Mavinas Bow, O"
3="        Mavinas Bow, Oc"
4="      avinas Bow, Occ"
5="    vinas Bow, Occu"
6="  inas Bow, Occu,"
7=" nas Bow, Occu, "
8="as Bow, Occu, T"
9="s Bow, Occu, Ta"
10=" Bow, Occu, Tal"
11="Bow, Occu, Tal "
12="ow, Occu, Tal O"
13="w, Occu, Tal Or"
14=", Occu, Tal Orb"
15=" Occu, Tal Orb "
16="Occu, Tal Orb +"
17="ccu, Tal Orb + "
18="cu, Tal Orb + M"
19="u, Tal Orb + Ma"
20=", Tal Orb + Mas"

So basicly, it works from line 8 and forward... But why the fuck is it doing 2 chars every line before that? And how could i limit the chars dependant och the spaces in front?





EDIT: Solved it, posting new script.
Code:
#include <amxmodx> #include <amxmisc> #define g_len2 15 new g_string[1024] new g_len new g_file[128] = "addons/amxmodx/d2overhead.txt" new g_outfile[128] = "addons/amxmodx/d2overhead.ini" public plugin_init() {     register_plugin("D2 Overhead", "1.0", "[ --<-@ ]")         new len     for ( new k ; k < g_len2 ; k++ )         len += formatex(g_string[len], 1023-len, " ")         read_file(g_file, 0, g_string[len], 1023-len, g_len)         len += g_len         for ( new m ; m < g_len2 - 1 ; m++ )         len += formatex(g_string[len], 1023-len, " ")         g_len += g_len2 + g_len2         for ( new i = 1 ; i < g_len - g_len2 + 1 ; i++ ) {                 new putfile[64]         new len2 = formatex(putfile, 63, "%i=^"", i)                 for ( new l = 0 ; l < g_len2 ; l++ )             len2 += formatex(putfile[len2], 1, "%s", g_string[i + l - 1])                 formatex(putfile[len2], 63-len2, "^"")                 write_file(g_outfile, putfile)     } }


All times are GMT -4. The time now is 16:13.

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