viewing paste Function Collection | Athena

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
/*
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", "<npc::OnEvent"> or <function>.
// 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", <array>, <1= raise 2= lower>, <position to raise/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}"[...]>}, {<gm level[...]>};
// 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", <value>.
// 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", <var>;
// returns 1 if the value is int.
function    script  is_int  {
 
    return ( getarg ( 0 ) == ( getarg ( 0 ) + 00 ) ) ;
}
 
// callfunc "is_map", "<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","<map>", <mapflag>{...}
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", <value>.
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", <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", "<array>", <place to start>, <value to search>.
// 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","<map>", {<mapflag>[...]};
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", <id>.
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", <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", <variable 1>, <variable 2>;
// 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 ;
    
}
Viewed 942 times, submitted by Guest.