• 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!

Lua GuildMaster for TFS 0.3.6

filipus

Member
Joined
Dec 31, 2010
Messages
229
Reaction score
12
So, I've been wondering if anyone knows any "easy" way to create a GuildMaster NPC in 0.3.6
I know there are the talkaction things (even if I only have !create and !join, no idea why the rest isn't there haha), but I wanted an NPC.

I've picked up one from a 8.0 version but it seems 0.3.6 doesn't have LuaFunctions to create a guild (I have setPlayerGuildID/setPlayerGuildRank/etc.. but these don't seem to work that well).

My question is, is there any Guildmaster NPC already made? If not, does anyone know a way to do one without having to create new functions? I've tried to create one but since I'm new to all this it's kind of hard for me to code it. (not many examples to "copy" from)

Here's the one I've been working on, I copied from a old one so it obviously doesn't work (I've been changing things step by step): http://pastebin.com/a0AtJtxX <-- too big to post on the topic.


@Limos You are the programming genius, help mee! haha
 
Last edited:
Questions, how do I get the variables with the lua functions? The (L* state) or whatever is my variable? I think I read somewhere it works like a stack (you push and pop from the stack) so I would have to convert right?

Also, can I do a dbQuery on na NPC? That would solve everything.
 
TFS 0.3.6 V8.2 includes these methods
Code:
        static int32_t luaDoPlayerSetGuildId(lua_State* L);
        static int32_t luaDoPlayerSetGuildLevel(lua_State* L);
        static int32_t luaDoPlayerSetGuildNick(lua_State* L);
        static int32_t luaGetPlayerGuildId(lua_State* L);
        static int32_t luaGetPlayerGuildName(lua_State* L);
        static int32_t luaGetPlayerGuildRank(lua_State* L);
        static int32_t luaGetPlayerGuildRankId(lua_State* L);
        static int32_t luaGetPlayerGuildLevel(lua_State* L);
        static int32_t luaGetPlayerGuildNick(lua_State* L);
        static int32_t luaGetGuildId(lua_State* L);
        static int32_t luaGetGuildMotd(lua_State* L);

I think those are enough for your purposes, let me know how it goes.

Ignazio
 
TFS 0.3.6 V8.2 includes these methods
Code:
        static int32_t luaDoPlayerSetGuildId(lua_State* L);
        static int32_t luaDoPlayerSetGuildLevel(lua_State* L);
        static int32_t luaDoPlayerSetGuildNick(lua_State* L);
        static int32_t luaGetPlayerGuildId(lua_State* L);
        static int32_t luaGetPlayerGuildName(lua_State* L);
        static int32_t luaGetPlayerGuildRank(lua_State* L);
        static int32_t luaGetPlayerGuildRankId(lua_State* L);
        static int32_t luaGetPlayerGuildLevel(lua_State* L);
        static int32_t luaGetPlayerGuildNick(lua_State* L);
        static int32_t luaGetGuildId(lua_State* L);
        static int32_t luaGetGuildMotd(lua_State* L);

I think those are enough for your purposes, let me know how it goes.

Ignazio


yea I know, but I haven't been able to make them work. I still can't understand properly what Level/Nick represent, I looked inside the functions but it was a bit confusing.
Also, I'm not quite understanding the lua_State* L parameter, like, what can I input there? Anything? How do I get the values out of that? Is it a stack or something?
 
Bump de bump

Lol, completely missed the doPlayerCreateGuild haha. Ok, I'm having a error:

attempt to call global "doPlayerCreateGuild" <a nil value>

I'm doing this (after getting the guild name):
Code:
if TopicState[cid] == 1 then        -- get name of new guild
                  gname = msg
                doPlayerCreateGuild(cid, gname)


code for doPlayerCreateGuild():
Code:
int32_t LuaScriptInterface::luaDoPlayerCreateGuild(lua_State* L)
{
   
    Player* player = creature->getPlayer();

    if(player->getGuildId())
    {
        player->sendCancel("You are already in a guild.");
        lua_pushboolean(L, true);
    }

    std::string param_ = variantToString(L);
    trimString(param_);
    if(!isValidName(param_))
    {
        player->sendCancel("That guild name contains illegal characters, please choose another name.");
        return true;
    }

    const uint32_t minLength = g_config.getNumber(ConfigManager::MIN_GUILDNAME);
    const uint32_t maxLength = g_config.getNumber(ConfigManager::MAX_GUILDNAME);
    if(param_.length() < minLength)
    {
        player->sendCancel("That guild name is too short, please select a longer name.");
        return true;
    }

    if(param_.length() > maxLength)
    {
        player->sendCancel("That guild name is too long, please select a shorter name.");
        return true;
    }

    uint32_t guildId;
    if(IOGuild::getInstance()->getGuildId(guildId, param_))
    {
        player->sendCancel("There is already a guild with that name.");
        return true;
    }

    const uint32_t levelToFormGuild = g_config.getNumber(ConfigManager::LEVEL_TO_FORM_GUILD);
    if(player->getLevel() < levelToFormGuild)
    {
        char buffer[70 + levelToFormGuild];
        sprintf(buffer, "You have to be at least Level %d to form a guild.", levelToFormGuild);
        player->sendCancel(buffer);
        return true;
    }

    const int32_t premiumDays = g_config.getNumber(ConfigManager::GUILD_PREMIUM_DAYS);
    if(player->getPremiumDays() < premiumDays)
    {
        char buffer[70 + premiumDays];
        sprintf(buffer, "You need to have at least %d premium days to form a guild.", premiumDays);
        player->sendCancel(buffer);
        return true;
    }

    player->setGuildName(param_);
    IOGuild::getInstance()->createGuild(player);

    char buffer[50 + maxLength];
    sprintf(buffer, "You have formed guild \"%s\"!", param_.c_str());
    player->sendTextMessage(MSG_INFO_DESCR, buffer);
    return true;

Can't really see what I'm doing wrong, the parameters seem right and Im calling it correctly...

):

@Limos you sexy boy, help me!
 
Last edited by a moderator:
I'm not sure, but in TFS 0.3.6 Guild Master will not work. That why is command: !createguild and !joinguild

I can create edit the sources and create functions that recreate the !createguild command (using Io::guild create or something like that, I actually started coding it), my problem is that I'm not sure how variables work in lua so I can't really do it. I was also trying to do it with the normal functions, that way I could easily share the NPC here in Otland. The function I posted up there seems to work perfectly fine, I just can't make it work for me...
 
It's pretty easy to conjure up some simple functions in the source that is usable through LUA, rethinking it, I realized you might need one for creating guilds and one for creating ranks.

The functions I posted was an extract from the source. This function;
Code:
static int32_t luaGetPlayerGuildRankId(lua_State* L);

Is used in lua like this;
Code:
getPlayerGuildRankId(cid)

and so on, I hope you see the pattern.

I can help you more when I come home.

All the luck
Ignazio
 
It's pretty easy to conjure up some simple functions in the source that is usable through LUA, rethinking it, I realized you might need one for creating guilds and one for creating ranks.

The functions I posted was an extract from the source. This function;
Code:
static int32_t luaGetPlayerGuildRankId(lua_State* L);

Is used in lua like this;
Code:
getPlayerGuildRankId(cid)

and so on, I hope you see the pattern.

I can help you more when I come home.

All the luck
Ignazio


O yes, I know! I understand the idea between the functions and how to call them and all that. My problem is inside the functions.. Like, the variables and all that. I've noticed Lua uses a stack for the variables and then when you want to use one inside the function you pop it or something like that. The thing is, it's hard for me to understand how many parameters I can input in the function and all that. Per example, in the doPlayerCreateGuild() it does
Code:
std::string param_ = variantToString(L);
    trimString(param_);
to receive the guild name. Yet, it the description it says (cid, name) or something like that. Am I suppose to input the cid (so it recognizes the player?), how does variantToString work (if I also input cid, does it only read the last parameter or all of it?) etc etc... I don't understand why I receive a nill value when I do this doPlayerCreateGuild(cid, gname). It should work.

I just have a lot of different questions haha.

But thanks for trying to help!
 
I don't have it all in my head, but when you pop variables in the source (get them from lua), then you need to identify the type to begin with, popString, popNumber, popBool. I also recall that you read the last variable to the first, for instance:

I want to use my function with three variables like this (lua):
Code:
myFunction(damage, playerName, showDamage)

Then you need to pop these three variables from the last to the first defining type, like this (c++)
Code:
bool showDamage = popBoolean(L);
std::string playerName = popString(L);
int32_t damage = popNumber(L);

That should work.

Ignazio
 
O, interesting! So you have to define the type of variable when you pop... Cool!
Ill try to rework the script today and if it works ill post here.
 
So I've tried numerous variations of the parameters that are inputted into the doPlayerCreateGuild() function but still wasn't able to make it work.
Always get the
attempt to call global "doPlayerCreateGuild" <a nil value> error. The source code is in the posts above. Any tips?
 
Back
Top