/* attach_all: attach all the players and them call a func or doevent. change_pos: Change the position in an array, you can raise the position or lower. delete_arrayfrom: delete the values specified by the start and end. delete_arrayindex: Delete the indexes indicated in the func. dyamic_menu:: Make a dynamic menu with an array or arguments. get_decimal: Get the decimals of the given numbers, you can set the number of decimals you can get. get_bitvarl: get a bitwise var position. is_int: Check if the var is int or not. is_map: Chech if the map given is a map or doesn't. is_sql: returns 1 if the server is sql. rand_color: Make a random hex color. random_array: make a random array. remove_mapflags: Remove the mapflags of a map. search_array: Search the value in an array. set_vitvar: set a bitwise rand position. set_mapflags: Set the mapflags in a map. show_hat: show a hat (CS). sort_array: Sort an array, asc or desc. swap_pos: Swap two positions in an array. walktonpc: Walk to a npc. */ // Do attachrid to all players. // callfunc "attach_all", " or . // Return the online players amount. function script attach_all { while ( ( .@a + 2000000 ) <= 2010000 ) { if ( attachrid ( .@a + 2000000 ) ) { set .@b, .@b + 1; if ( compare ( getarg ( 1 ), "On" ) ) doevent getarg ( 1 ) ; else callfunc getarg ( 1 ) ; } set .@a, .@a + 1; sleep2 ( ! ( .@a % 200 ) ) ; } return .@b ; } // callfunc "change_pos", , <1= raise 2= lower>, ; // i.e: // array .X = 5,9,11; // callfunc "change_pos", .X, 1, 2 ; -> .X = 5,11,9. // return -1 if there was any error (lower latest, raise first...). function script change_pos { if ( ( getarg ( 1 ) == 0 && getarg ( 2 ) == 1 ) || ( getarg ( 1 ) == ( getarraysize ( getarg ( 0 ) ) - 1 ) && getarg ( 2 ) == 2 ) ) return -1; set .@a, getelementofarray ( getarg ( 0 ), getarg ( 1 ) ); set .@b, getelementofarray ( getarg ( 0 ), getarg ( 1 ) + ( ( getarg ( 2 ) == 1 ) ? -1 : 1 ) ); set getelementofarray ( getarg ( 0 ), getarg ( 1 ) + ( ( getarg ( 2 ) == 1 ) ? -1 : 1 ) ), .@a; set getelementofarray ( getarg ( 0 ), getarg ( 1 ) ), .@b; return ; } // callfunc "dyamic_menu", {<"{option or array}"[...]>}, {}; // returns the menu choosen. function script dynamic_menu { if ( getd ( getarg ( 0 ) +"[0]" ) ) { set .@c, callfunc ( "is_int", getd ( getarg ( 0 ) +"[0]" ) ); set .@b, 1; } for ( ; ( ( .@b ) ? getelementofarray ( getarg ( 0 ), .@a ) : getarg ( .@a, ( ( .@c ) ? "" : 0 ) ) ) ; set .@a, .@a + 1 ) if ( getgmlevel ( ) >= getarg ( .@a + 1 ) && ! .@c ) set .@menu$, .@menu$ + ( ( .@b ) ? getelementofarray ( getarg ( 0 ), .@a ) : getarg ( .@a, "" ) ) +":"; return select ( .@menu$ ) ; } // callfunc "get_bitvar", "variable", . // returns 1 if the var has a value. function script get_bitvar { if ( getd ( getarg ( 0 ) +""+ ( getarg ( 1, 0 ) / 31 ) ) & ( 1 << ( getarg ( 1 ) % 31 ) ) ) set .@a, 1; return .@a ; } // callfunc "get_decimal", dividend, divisor, decimales to get. // returns the final result and decimals. function script get_decimal { setarray .@a[0], getarg ( 0 ), getarg ( 1 ); set .@a, .@a[0] / .@a[1]; set .@b, .@a[0] % .@a[1]; while ( .@d < getarg ( 2, 1 ) ) { set .@d, .@d + 1; if ( .@d > 1 ) set .@b, .@b % .@a[1]; if ( .@b ) { while ( .@b < .@a[1] ) set .@b, .@b * 10; set .@c, .@b / .@a[1]; set .@a$, .@a +","+ .@c; } else break ; } if ( .@a$ == "" ) set .@a$, .@a; return .@a$; } // callfunc "is_int", ; // returns 1 if the value is int. function script is_int { return ( getarg ( 0 ) == ( getarg ( 0 ) + 00 ) ) ; } // callfunc "is_map", ""; // returns 1 if the map is a real map. function script is_map { return ( getmapmobs ( getarg ( 0 ) ) >= 0 ) ; } // callfunc "is_sql"; // returns 1 if the server is sql. // (Extracted from PollSystem). function script is_sql { return ( query_sql ( "select 1", .@a ) > 0 ) ; } // callfunc "rand_color"; // returns a hex rand color code. function script rand_color { setarray .@base$[0], "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"; while ( getstrlen ( .@a$ ) < 6 ) set .@a$, .@a$ + .@base$[rand ( getarraysize ( .@base$ ) )]; return .@a$ ; } // callfunc "remove_mapflags","", {...} function script remove_mapflags { for ( set .@a, 1; getarg ( .@a, 999 ) != 999 ; set .@a, .@a + 1 ) if ( getd ( "$@mapflag"+ getarg ( .@a ) +"_"+ getarg ( 0 ) ) ) removemapflag getarg ( 0 ), getarg ( .@a ); return ; } // callfunc "set_bitvar", "variable", . function script set_bitvar { if ( getd ( getarg ( 0 ) +""+ ( getarg ( 1, 0 ) / 31 ) ) &~ ( 1 << ( getarg ( 1 ) % 31 ) ) ) setd getarg ( 0 ) +""+ ( getarg ( 1, 0 ) / 31 ), getd ( getarg ( 0 ) +""+ ( getarg ( 1, 0 ) / 31 ) ) + ( 1 << ( getarg ( 1 ) % 31 ) ); return ; } // callfunc "random_array", . function script random_array { set .@size, getarraysize ( getarg ( 0 ) ); for ( ; .@a < .@size ; set .@a, .@a + 1 ) set .@b[.@a], getelementofarray ( getarg ( 0 ), .@a ); for ( set .@a, 0; .@a < .@size ; set .@a, .@a + 1 ) { set .@c, rand ( getarraysize ( .@b ) ); set getelementofarray ( getarg ( 0 ), .@a ), .@b[.@c]; deletearray .@b[.@c], 1 ; sleep2 ( ! ( .@a % 100 ) ) ; } return ; } // callfunc "search_array", "", , . // returns the position that has the value. // returns -1 if the array hasn't the value. function script search_array { set .@size, getarraysize ( getarg ( 0 ) ); for ( set .@a, getarg ( 1, 0 ) ; .@a < .@size ; set .@a, .@a + 1 ) if ( getelementofarray ( getarg ( 0 ), .@a ) == getarg ( 2 ) ) return .@a; return -1 ; } // callfunc "set_mapflags","", {[...]}; function script set_mapflags { for ( set .@a, 1; getarg ( .@a, 999 ) != 999 ; set .@a, .@a + 1 ) if ( ! getmapflag ( getarg ( 0 ), getarg ( .@a ) ) ) { setmapflag getarg ( 0 ), getarg ( .@a ) ; setd "$@mapflag"+ getarg ( .@a ) +"_"+ getarg ( 0 ), 1; } return ; } // callfunc "show_hat", . function script show_hat { set .@equip, getiteminfo ( getarg ( 0 ), 5 ); set .@view, getiteminfo ( getarg ( 0 ), 11 ); setarray .@a[1], 9, 8; setarray @a[1], getlook ( 3 ), getlook ( 4 ), getlook ( 5 ); if ( .@equip >= 0 && .@view > 0 ) for ( set .@b, 1; .@b < =3 ; set .@b, .@b + 1 ) if ( .@equip & ( 1 << .@a[.@b] ) ) changelook 2 + .@b, .@view; addtimer 2000, "show_hat_2::OnRemove" ; return ; } - script show_hat_2 -1,{ OnRemove: for ( set .@a, 1; .@a <= 3 ; set .@a, .@a + 1 ) changelook 2 + .@a, @a[.@a]; } // callfunc "sort_array", , <0 = DESC 1 = ASC>; // ASC = 1, 2, 3. DESC = 3,2,1. function script sort_array { set .@a, getarg ( 1, -1 ); set .@size, getarraysize ( getarg ( 0 ) ); for ( set .@b, 0; .@b < .@size ; set .@b, .@b + 1 ) { for ( set .@c, 0; .@c < .@size ; set .@c, .@c + 1 ) if ( ( getelementofarray ( getarg ( 0 ), .@b ) * .@a ) < ( getelementofarray ( getarg ( 0 ), .@c ) * .@a ) ) callfunc "swap_var", getelementofarray ( getarg ( 0 ), .@b ), getelementofarray ( getarg ( 0 ), .@c ); sleep2 ( ! ( .@b % 100 ) ) ; } return ; } // callfunc "swap_var", , ; // I dunno if this works with strings :P function script swap_var { set getarg ( 0 ), getarg ( 0 ) + getarg ( 1 ); set getarg ( 1 ), getarg ( 0 ) - getarg ( 1 ); set getarg ( 0 ), getarg ( 0 ) - getarg ( 1 ); return ; } // callfunc "walktonpc", <"name of the npc">; function script walktonpc { getmapxy .@m$, .@x1, .@y1, 0 ; getmapxy .@m$, .@x2, .@y2, 1, getarg ( 0 ); set .@d1, sqrt ( pow ( .@x1 - .@x2, 2 ) ); set .@d2, sqrt ( pow ( .@y1 - .@y2, 2 ) ); do { set .@b, .@b + 1; set .@x1, .@x1 + ( ( .@x1 < .@x2 ) ? 1 : -1 ); set .@y1, .@y1 + ( ( .@y1 < .@y2 ) ? 1 : -1 ); sleep2 ( ! ( .@b % 100 ) ) ; } while ( ! checkcell ( .@m$, .@x1, .@y1, cell_chkpass ) || .@b < .@d1 || .@b < .@d2 ) ; unitwalk getcharid ( 3 ), .@x1, .@y1 ; return ; }