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

C++ What function in tfs 0.4?

Adix910

New Member
Joined
Aug 14, 2015
Messages
37
Reaction score
1
Hi, yesterday i found the script:

lua_register(m_luaState, "selfAttackCreature", NpcScriptInterface::luaActionAttackCreature);

int32_t NpcScriptInterface::luaActionAttackCreature(lua_State* L){
int id=(int)lua_tonumber(L, -1);
Npc* npc = getNpc(popNumber(L));
if(npc)
npc->doAttack(id);
return 0;
}

The code is to create functions for attacking creatures by npc
and so there was an error in the compilation

[2648] npc.cpp `getNpc' was not declared in this scope

How to fix it?
 
Where did you take that function from?

NPC's can't attack other creatures in TFS 0.4. Its reserved only for monsters and players.

The function would look this:
Code:
int32_t NpcScriptInterface::luaActionAttackCreature(lua_State* L) {
    //selfAttackCreature(cid)
    ScriptEnviroment* env = getEnv();
    Npc* npc = env->getNpc();
    if(!npc)
        return 0;

    Creature* creature = env->getCreatureByUID(popNumber(L));
    if(creature)
        creature->doAttack(id);

    return 0;
}

The problem is, there is no doAttack(id) function in TFS 0.4. So the code won't work, but I gave you an example how to do such a function.
 
@slawkens
Thank you,
So you'll be able to help me do this?
doAttack

drreoNF.png
 
@Adix910
You are going wrong way about it;

post where did you find that function in your first post. Ideally it should be part of sources, which will contain everything you need to implement it into your engine. Since its a new function it may not be just copy-paste.
 
you can make a workaround inside npc as such; (this is just example, but you can make more advanced, randomized attacks, literally to behave like a monster.)

local guardCondition = Condition(CONDITION_FIRE, CONDITIONID_COMBAT)
guardCondition:setParameter(CONDITION_PARAM_DELAYED, 10)
guardCondition:addDamage(10, 3000, -10)

player:getPosition():sendMagicEffect(CONST_ME_HITBYFIRE)
player:addCondition(guardCondition)
npc:getPosition():sendDistanceEffect(player:getPosition(), CONST_ANI_FIRE)

inside npc_name.xml you can also specify if you want this npc to be attackable by players.

or further it up within creaturescripts and events to transform;
 
then its even easier... just spawn monsters... no need for npc to do any kind of attacks.

local creatures = { 'Monster1', 'Monster2' }

for i = 1, #creatures do
Game.createMonster(creatures, Npc():getPosition())
end
 
What if I would like to do it in this example?

Code:
local function doSummonPokemon(npc)
    local this = npc
    if not isCreature(this) then return true end
    if #getCreatureSummons(this) >= 1 or focus == 0 then return true end
    local it = pokemons[battle_turn]
    doSummonMonster(this, it.name)
    local summon = getCreatureSummons(this)[1]
    local balleffect = pokeballs["normal"].effect
        if it.ball and pokeballs[it.ball] then
            balleffect = pokeballs[it.ball].effect
        end
    doSendMagicEffect(getThingPos(summon), balleffect)
    setPlayerStorageValue(summon, 10000, balleffect)
    setPlayerStorageValue(summon, 10001, gobackmsgs[math.random(#gobackmsgs)].back:gsub("doka", it.nick ~= "" and it.nick or it.name))
    setPlayerStorageValue(summon, 1007, it.nick ~= "" and it.nick or it.name)
    doSetMonsterGym(summon, focus)
    local name = it.nick ~= "" and it.nick or getCreatureName(this).."s "..it.name
    setWildPokemonLevel(summon, it.level, getPokemonStatus(it.name, (it.extralevel + it.level)), name, 1.5)
    doCreatureSay(this, gobackmsgs[math.random(#gobackmsgs)].go:gsub("doka", getPlayerStorageValue(summon, 1007)), 1)
    fighting = true
    battle_turn = battle_turn + 1
end
 
its pretty much same thing as orc king was doing

but i'd recommend doing it through events and creaturescripts, to script the encounters. NPC would only activate certain event so you get turns once other monster is defeated
 
Back
Top