summaryrefslogblamecommitdiff
path: root/npc/functions/main.txt
blob: 3659437420f8e93a8d75a958221ded183a3e296a (plain) (tree)
1
2
3
4
5
6
7
8
              



                  
               
               
                                   








                                         
                                 

                                                                                       


           











                                                                                      





                                                                                   





























                                                 
                                   









                                                                                        
                                 
                                   


           
















































































































                                                                      
                                                                  

























                                                                                                      









                                                                                                 


                                         
                                                                                                              


                      


















                                                 
// TMW2 Script
// Evol functions.
// Authors:
//    4144
//    Travolta
//    Jesusalva
// Description:
//    Built-in essential functions.

function	script	menuimage	{
    return getarg(0) + "|" + getarg(1);
}

function	script	menuaction	{
    return "[" + getarg(0) + "]";
}

function	script	setq1	{
    //   Quest,     val1     , val2            , val3            , time
    setq getarg(0), getarg(1), getq2(getarg(0)), getq3(getarg(0)), getqtime(getarg(0));
    return;
}

function	script	setq2	{
    //   Quest,     val1           , val2     , val3            , time
    setq getarg(0), getq(getarg(0)), getarg(1), getq3(getarg(0)), getqtime(getarg(0));
    return;
}

function	script	setq3	{
    //   Quest,     val1           , val2            , val3     , time
    setq getarg(0), getq(getarg(0)), getq2(getarg(0)), getarg(1), getqtime(getarg(0));
    return;
}

function	script	setqtime	{
    //   Quest,     val1           , val2            , val3     , time
    setq getarg(0), getq(getarg(0)), getq2(getarg(0)), getq3(getarg(0)), getarg(1);
    return;
}

function	script	mesn	{
    if (getargcount() > 0)
    {
        .@s$ = "[" + getarg(0) + "]";
    }
    else
    {
        .@s$ = "[" + strnpcinfo(1) + "]";
    }
    mes .@s$;
    return;
}

function	script	mesq	{
    mes "\"" + getarg(0)+  "\"";
    return;
}

function	script	g	{
    return Sex == 0 ? getarg(0) : getarg(1);
}

function	script	col	{
    .@color = getarg(1);
    if (.@color < 0) .@color = 0;
    if (.@color > 9) .@color = 9;
    return "##" + .@color + getarg(0) + "##0";
}

function	script	adddefaultskills	{
    if (getskilllv(NV_BASIC) < 6) {
        skill NV_BASIC, 6, 0;
    }
    return;
}

function	script	addremovemapmask	{
    setmapmask getarg(0), (getmapmask(getarg(0)) | (getarg(1) + getarg(2))) ^ getarg(2);
    return;
}

function	script	mesc	{
    mes col(getarg(0),getarg(1,9));
    return;
}

// Function to show narrator text. Accepts string args.
// If first arg is a number N, then it represents bit flags.
// Bit flags :
//   0x1 -- blank line at beginning
//   0x2 -- blank line at the end
//   0x4 -- use last "next;"
//   0x8 -- don't use first "mesn;"
function	script	narrator	{
    .@start = 0;
    .@argc = getargcount();
    .@flags = 0;

    if (.@argc > 1 && !isstr(getarg(0)))
    {
        .@start = 1;
        .@flags = getarg(0);
    }

    if (.@flags & 0x1)
        mes "";

    if (!(.@flags & 0x8))
        mesn l("Narrator");

    for (.@i = .@start; .@i < .@argc; .@i++)
    {
        mes col(getarg(.@i), 9);
        if (.@i < .@argc - 1)
            next;
    }

    if (.@flags & 0x4)
        next;
    else if (.@flags & 0x2)
        mes "";

    return;
}

// Function to show NPC speech. Accepts string args.
// If first arg is a number N, then it represents bit flags.
// Bit flags :
//   0x1 -- blank line at beginning
//   0x2 -- blank line at the end
//   0x4 -- use last "next;"
//   0x8 -- don't use first "mesn;"
function	script	speech	{
    .@start = 0;
    .@argc = getargcount();
    .@flags = 0;

    if (.@argc > 1 && !isstr(getarg(0)))
    {
        .@start = 1;
        .@flags = getarg(0);
    }

    if (.@flags & 0x1)
        mes "";

    if (!(.@flags & 0x8))
        mesn;

    for (.@i = .@start; .@i < .@argc; .@i++)
    {
        mesq getarg(.@i);

        if (.@i < .@argc - 1)
            next;
    }

    if (.@flags & 0x4)
        next;
    else if (.@flags & 0x2)
        mes "";

    return;
}

// Show debug message if .debug variable of NPC is set to 1
function	script	npcdebug	{
    if (getvariableofnpc(.debug, strnpcinfo(3)))
        debugmes strnpcinfo(3) + ": " + getarg(0);
    return;
}

function	script	askyesno	{
    return select(menuaction(l("Yes")),
        menuaction(l("No")));
}

// Argument:
//  0 Quest variable
//  1 Current value
//  2 Next value
function	script	compareandsetq	{
    if (getq(getarg(0)) == getarg(1))
    {
        setq getarg(0), getarg(2);
        return true;
    }
    return false;
}

// Use a delay to prevent spams from NPC that display text without the
// use of (a) close/next function(s).
// Argument:
//  0 Text to display
//  1 Lock delay (default = 1)
//  2 Message function:  (default = 0)
//      0 = npctalk3
//      1 = npctalk
//      2 = message
// TODO: Use temp player var, because NPC var affect other players
function	script	npctalkonce	{
    // lock mechanism
    switch (getarg(2, 0))
    {
    case 1:
        if (gettimetick(2) <= getvariableofnpc(.talk_lock, strnpcinfo(NPC_NAME_UNIQUE)))
            return false;
        set(getvariableofnpc(.talk_lock, strnpcinfo(NPC_NAME_UNIQUE)), gettimetick(2) + getarg(1, 1));
        break;
    default:
        if (gettimetick(2) <= @NPC_TALK_LOCK[getnpcid(0)])
            return false;
        @NPC_TALK_LOCK[getnpcid(0)] = gettimetick(2) + getarg(1, 1);
    }

    // talk mechanism
    switch (getarg(2, 0))
    {
    case 0: npctalk3(getarg(0)); break;
    case 1: npctalk(getarg(0)); break;
    case 2: message(strcharinfo(0), getarg(0));
    }

    return true;
}

function	script	isin	{
    if (getmapxy(.@mapName$, .@xpos, .@ypos, 0) != 0)
        return false;
    if (.@mapName$ != getarg(0))
        return false;
    if (.@xpos >= getarg(1) && .@xpos <= getarg(3) && .@ypos >= getarg(2) && .@ypos <= getarg(4))
        return true;
    return false;
}

// Get some acc id, even if offline
// ( Name )
function	script	gf_accid	{
    .@nb = query_sql("SELECT account_id FROM `char` WHERE name='"+escape_sql(getarg(0))+"' LIMIT 2", .@value);
    return .@value[0];
}

function	script	getquestlink	{
    return "[@@q" + getarg(0) + "|@@]";
}

function	script	getmonsterlink	{
    return "[@@m" + getarg(0) + "|@@]";
}

function	script	getpetlink	{
    return "[@@p" + getarg(0) + "|@@]";
}

function	script	getmercenarylink	{
    return "[@@M" + getarg(0) + "|@@]";
}

function	script	gethomunculuslink	{
    return "[@@h" + getarg(0) + "|@@]";
}