viewing paste mainfunctions | Text

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
//===== heRO Server =========================================================================================
//= Useful (?) Functions
//===== By ==================================================================================================
//= Gianluca
//===== Revision ============================================================================================
//= GM-Garr
//===== Version =============================================================================================
//= 1.0 - 
//===== Description: ========================================================================================
//= Just some math and bitmask functions that may be useful
//
//===== Variables used by the script ============================\\
//= 
//===== Functions ===============================================\\
//= Abs                     Return the absolute value of a number. e.g. Abs(3) = 3; Abs(-3) = 3;
//= popcount                Return the number of bits set on a value sent. e.g. popcount(5) = 2; //5 = 0b...00101
//= Logx                    Return the truncated value of logarithm on base x of a value sent. eg Logx(2,8) = 3;
//= Get_Rep                 Change player reputation on some faction.
//===============================================================
 
function    script  Abs {
    if(getarg(0) >= 0) return getarg(0);
    return (-getarg(0));
}
 
function    script  popcount    {
    for(.@i = 0; .@i < 32; ++.@i)
        .@v += ((getarg(0)&(1 << .@i)) != 0);
    return .@v;
}
 
function    script  Logx    {
    .@base = getarg(0,10);
    .@value = getarg(1);
    if(.@base < 2){
        debugmes "Error with Logx function. Attempt to use invalid base.";
        logmes "Error with Logx function. Attempt to use invalid base.";
        return -1;
    }
    if(.@value < 1){
        debugmes "Error with Logx function. Attempt to use invalid value.";
        logmes "Error with Logx function. Attempt to use invalid value.";
        return -1;
    }
    while((.@value/.@base) > 0){
        .@value /= .@base;
        ++.@result;
    }
    return .@result;
}
 
function    script  Get_Rep { //Get_Rep(Town Index, Value);
    setarray .@Towns$, "Porings", "Fairies", "Orcs", "Lutia People";
    .@index = getarg(0);
    .@value = getarg(1);
    Town_Rep[.@index] += .@value;
    if(Town_Rep[.@index] > 10000) Town_Rep[.@index] = 10000;
    if(Town_Rep[.@index] < -10000) Town_Rep[.@index] = -10000;
    dispbottom "You "+((.@value > 0)? "got":"lost")+" "+callfunc("Abs", .@value)+" reputation with the "+.@Towns$[.@index]+ ".";
    return;
}
 
 
 
 
 
 
 
 
 
Viewed 957 times, submitted by Guest.