• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Load npc by specific date!

chucky91

Advanced OT User
Joined
Apr 8, 2010
Messages
277
Solutions
9
Reaction score
152
Hello everyone, I bring here a modification for those who like nostalgia TFS 1.2 by @Ezzz .
I created this script to determine a specific date to load the Npc on server startup.
In npc.h
C++:
int startMonth = -1, startDay = -1, endMonth = -1, endDay = -1;
In npc.cpp
C++:
bool Npc::load()
{
    if (loaded) {
        return true;
    }

    reset();

    ScriptReader script;
    if (!script.open(filename)) {
        return false;
    }

    while (true) {
        script.nextToken();

        if (script.Token == ENDOFFILE) {
            break;
        }

        if (script.Token != IDENTIFIER) {
            script.error("identifier expected");
            return false;
        }

        std::string ident = script.getIdentifier();
        script.readSymbol('=');

        if (ident == "startmonth") {
            startMonth = script.readNumber();
        }
        else if (ident == "startday") {
            startDay = script.readNumber();
        }
        else if (ident == "endmonth") {
            endMonth = script.readNumber();
        }
        else if (ident == "endday") {
            endDay = script.readNumber();
        }
        else if (ident == "name") {
            name = script.readString();
        }
        else if (ident == "outfit") {
            script.readSymbol('(');
            uint8_t* c;
            currentOutfit.lookType = script.readNumber();
            script.readSymbol(',');
            if (currentOutfit.lookType > 0) {
                c = script.readBytesequence();
                currentOutfit.lookHead = c[0];
                currentOutfit.lookBody = c[1];
                currentOutfit.lookLegs = c[2];
                currentOutfit.lookFeet = c[3];
            }
            else {
                currentOutfit.lookTypeEx = script.readNumber();
            }
            script.readSymbol(')');
        }
        else if (ident == "home") {
            script.readCoordinate(masterPos.x, masterPos.y, masterPos.z);
        }
        else if (ident == "radius") {
            masterRadius = script.readNumber();
        }
        else if (ident == "behaviour") {
            if (behaviourDatabase) {
                script.error("behaviour database already defined");
                return false;
            }

            behaviourDatabase = new BehaviourDatabase(this);
            if (!behaviourDatabase->loadDatabase(script)) {
                return false;
            }
        }
    }

    time_t t = time(nullptr);
    tm* currentTime = localtime(&t);

    if (startMonth == -1 && startDay == -1 && endMonth == -1 && endDay == -1) {
        // NPC doesn't have a specific date.
        script.close();
        return true;
    }

    if (currentTime->tm_mon + 1 >= startMonth && currentTime->tm_mday >= startDay &&
        currentTime->tm_mon + 1 <= endMonth || currentTime->tm_mon + 1 == endMonth && currentTime->tm_mday <= endDay) {
        // Current date matches NPC date.
        std::cout << ">> Loading Npc " << name << " by calendar" << std::endl;
        script.close();
        return true;
    }

    // NPC is not supposed to appear at this time
    script.close();
    return false;
}

Then edit the Npc you would like such month and day and how long he would stay on the server.
# GIMUD - Graphical Interface Multi User Dungeon
# santaclaus.npc:
startmonth = 12 #December
startday = 10
endmonth = 1 #January
endday = 10

Name = "Santa Claus"
# Outfit = (looktype,head-body-legs-feet)
Outfit = (160,0-93-93-114)
Home = [32362,32207,7] #thais
Radius = 3

Behaviour = {
@"gen-santaclaus.ndb"
}
if you want it to always appear just put nothing or comment the lines.
#startmonth = 12 #December
#startday = 10
#endmonth = 1 #December
#endday = 10

1673041133246.png

good enjoy.
 
Last edited:
Back
Top