• 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 NPC or ITEM with SQL INSERT

platano

Active Member
Joined
Jul 21, 2009
Messages
163
Solutions
1
Reaction score
38
Location
Mexico
Hello dear forum, I'm looking to create a simple script for an item or a NPC that allows me to INSERT into my PLAYERS table.

I was looking at the promotion.lua script of one of my NPCs is there anyway I can change the promotion value for HP / MP increase in exchange for gold?

Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid)                npcHandler:onCreatureAppear(cid)             end
function onCreatureDisappear(cid)             npcHandler:onCreatureDisappear(cid)         end
function onCreatureSay(cid, type, msg)         npcHandler:onCreatureSay(cid, type, msg)     end
function onThink()                             npcHandler:onThink()                         end
function onPlayerEndTrade(cid)                npcHandler:onPlayerEndTrade(cid)            end
function onPlayerCloseChannel(cid)            npcHandler:onPlayerCloseChannel(cid)        end

local node1 = keywordHandler:addKeyword({'promot'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I can promote you for 20000 gold coins. Do you want me to promote you?'})
    node1:addChildKeyword({'yes'}, StdModule.promotePlayer, {npcHandler = npcHandler, cost = 20000, level = 20, promotion = 1, text = 'Congratulations! You are now promoted.'})
    node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Alright then, come back when you are ready.', reset = true})

npcHandler:addModule(FocusModule:new())

So instead of promotion = 1, is there a way to increase their 'healthmax' and 'manamax' values using a NPC?
 
Solution
Probably something like this
Lua:
 local player = Player(cid)
 local maxHealth = player:getMaxHealth()
 local extraHealth = 200;
 player:setMaxHealth(maxHealth + extraHealth)
You can increase healthmax and manamax without querying.
Look into npcs/libs/modules.lua #~66 function StdModule.promotePlayer to see how the promotePlayer works, and you can figure out how the NPCs functions work
 
Lua:
    --Usage:
        -- local node1 = keywordHandler:addKeyword({'promot'}, StdModule.say, {npcHandler = npcHandler, text = 'I can promote you for 20000 brozne coins. Do you want me to promote you?'})
        --         node1:addChildKeyword({'yes'}, StdModule.promotePlayer, {npcHandler = npcHandler, cost = 20000, promotion = 1, level = 20}, text = 'Congratulations! You are now promoted.')
        --         node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, text = 'Alright then, come back when you are ready.'}, reset = true)
    function StdModule.promotePlayer(cid, message, keywords, parameters, node)
        local npcHandler = parameters.npcHandler
        if(npcHandler == nil) then
            print('[Warning - ' .. getCreatureName(getNpcId()) .. '] NpcSystem:', 'StdModule.promotePlayer - Call without any npcHandler instance.')
            return false
        end

        if(not npcHandler:isFocused(cid)) then
            return false
        end

        if(isPremium(cid) or not getBooleanFromString(getConfigValue('premiumForPromotion'))) then
            if(getPlayerPromotionLevel(cid) >= parameters.promotion) then
                npcHandler:say('You are already promoted!', cid)
            elseif(getPlayerLevel(cid) < parameters.level) then
                npcHandler:say('I am sorry, but I can only promote you once you have reached level ' .. parameters.level .. '.', cid)
            elseif(not doPlayerRemoveMoney(cid, parameters.cost)) then
                npcHandler:say('You do not have enough money!', cid)
            else
                doPlayerSetPromotionLevel(cid, parameters.promotion)
                npcHandler:say(parameters.text, cid)
            end
        else
            npcHandler:say("You need a premium account in order to get promoted.", cid)
        end

        npcHandler:resetNpc(cid)
        return true
    end


doPlayerSetPromotionLevel(cid, parameters.promotion)
doPlayerAddBlessing(cid, parameters.number)

I think this is the place I need to tweak but what would the syntax be "doPlayerAddMaxHealth" "doPlayerAddMaxMana" "doPlayerIncreaseMaxHealth" "doPlayerIncreaseMaxMana" what would it be lol
 
Im starting to understand how this all works asking a couple of questions but I do still feel very unexperienced lol.

TBH I dont know what distro I'm using, I downloaded it here , it is OTX 2.9 probably using TFS 1.2? Idk tbh sorry if it's wrong

Found what you asked me:


C++:
    //setCreatureMaxHealth(cid, health)
    lua_register(m_luaState, "setCreatureMaxHealth", LuaInterface::luaSetCreatureMaxHealth);
    //setCreatureMaxMana(cid, mana)
    lua_register(m_luaState, "setCreatureMaxMana", LuaInterface::luaSetCreatureMaxMana);

int32_t LuaInterface::luaSetCreatureMaxHealth(lua_State* L)
{
    //setCreatureMaxHealth(uid, health)
    uint32_t maxHealth = (uint32_t)popNumber(L);

    ScriptEnviroment* env = getEnv();
    if(Creature* creature = env->getCreatureByUID(popNumber(L)))
    {
        creature->changeMaxHealth(maxHealth);
        lua_pushboolean(L, true);
    }
    else
    {
        errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
        lua_pushboolean(L, false);
    }

    return 1;
}

int32_t LuaInterface::luaSetCreatureMaxMana(lua_State* L)
{
    //setCreatureMaxMana(uid, mana)
    uint32_t maxMana = (uint32_t)popNumber(L);

    ScriptEnviroment* env = getEnv();
    if(Creature* creature = env->getCreatureByUID(popNumber(L)))
    {
        creature->changeMaxMana(maxMana);
        lua_pushboolean(L, true);
    }
    else
    {
        errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
        lua_pushboolean(L, false);
    }

    return 1;
}
 
Probably something like this
Lua:
 local player = Player(cid)
 local maxHealth = player:getMaxHealth()
 local extraHealth = 200;
 player:setMaxHealth(maxHealth + extraHealth)
 
Solution
Back
Top