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

Itutorial's Scripting Service TFS 0.3.6-0.4-1.x

Itutorial

Legendary OT User
Joined
Dec 23, 2014
Messages
2,339
Solutions
68
Reaction score
1,024
As the title says.

Format:
-Distro
-explination of code needed as detailed as possible
-Pictures if required of map set up for code

I don't usually mess with C++ but if I know I can do something that you request I will.
 
As the title says.

Format:
-Distro
-explination of code needed as detailed as possible
-Pictures if required of map set up for code

I don't usually mess with C++ but if I know I can do something that you request I will.

Hi! Can u help me?
I need a script, which for example has 3 players attacking me, when I use Spell, they lose the target on me.
TFS 0.4

I have tried
doCreatureSetTarget(cid, target) -- but doesnt work
(attempt to call global 'doCreatureSetTarget' (a nil value))
 
Last edited:
The script of roriscrave said, is on my wish list too, so, now have 2 request for it. ^_^
It can be do with doCombatAreaDispel or doTargetCombatDispel?
 
Actually they only want their attackers to lose target.
On spell cast set a storage to caster
Code:
if self:isPlayer() and target:isPlayer() then
if target:getStorageValue(xxx) == 1 then
return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
end
end
 
That would work for TFS 1.x+. I am looking at source edits right now for 0.4 for this. I am trying to find the libraries for compiling it so I can test it before I release the code.
 
Alright guys:

Luascript.cpp

Find
Code:
lua_register(m_luaState, "doMonsterSetTarget", LuaInterface::luaDoMonsterSetTarget);

add under

Code:
lua_register(m_luaState, "doPlayerCancelTarget", LuaInterface::luaDoPlayerCancelTarget);

find

Code:
int32_t LuaInterface::luaDoMonsterSetTarget(lua_State* L)
{
    //doMonsterSetTarget(cid, target)
    uint32_t targetId = popNumber(L);
    ScriptEnviroment* env = getEnv();
    Creature* creature = env->getCreatureByUID(popNumber(L));
    if(!creature)
    {
        errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
        lua_pushboolean(L, false);
        return 1;
    }
    Monster* monster = creature->getMonster();
    if(!monster)
    {
        errorEx(getError(LUA_ERROR_MONSTER_NOT_FOUND));
        lua_pushboolean(L, false);
        return 1;
    }
    Creature* target = env->getCreatureByUID(targetId);
    if(!target)
    {
        errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
        lua_pushboolean(L, false);
        return 1;
    }
    if(!monster->isSummon())
        lua_pushboolean(L, monster->selectTarget(target));
    else
        lua_pushboolean(L, false);
    return 1;
}

add under

Code:
int32_t LuaInterface::luaDoPlayerCancelTarget(lua_State* L)
{
    //doPlayerCancelTarget(cid, target)
    ScriptEnviroment* env = getEnv();
    Player* player = env->getCreatureByUID(popNumber(L));
    if(!player)
    {
        errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
        lua_pushboolean(L, false);
        return 1;
    }
  
    player->sendCancelTarget();
    lua_pushboolean(L, true);
    return 1;
}

Luascript.h

find

Code:
static int32_t luaDoMonsterSetTarget(lua_State* L);

add under

Code:
static int32_t luaDoPlayerCancelTarget(lua_State* L);

Then spell

Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_HEALING)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, false)
function onCastSpell(cid, var)
    if isPlayer(cid) then
        local spectators = getSpectators(getPlayerPosition(cid), 9, 9, false)
        for i, v in ipairs(spectators) do
            local target = spectators[v]
            if target then
                if getCreatureName(getCreatureTarget(target)) == getCreatureName(cid) then
                    doPlayerCancelTarget(target)
                end
            end
        end
    end
    return doCombat(cid, combat, var)
end
 
Got a question: Do you do all kind of scripts? As explain: Creature scripts, spells, monsters etc? or just special one as explain spells?
 
Alright guys:

Luascript.cpp

Find
Code:
lua_register(m_luaState, "doMonsterSetTarget", LuaInterface::luaDoMonsterSetTarget);

add under

Code:
lua_register(m_luaState, "doPlayerCancelTarget", LuaInterface::luaDoPlayerCancelTarget);

find

Code:
int32_t LuaInterface::luaDoMonsterSetTarget(lua_State* L)
{
    //doMonsterSetTarget(cid, target)
    uint32_t targetId = popNumber(L);
    ScriptEnviroment* env = getEnv();
    Creature* creature = env->getCreatureByUID(popNumber(L));
    if(!creature)
    {
        errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
        lua_pushboolean(L, false);
        return 1;
    }
    Monster* monster = creature->getMonster();
    if(!monster)
    {
        errorEx(getError(LUA_ERROR_MONSTER_NOT_FOUND));
        lua_pushboolean(L, false);
        return 1;
    }
    Creature* target = env->getCreatureByUID(targetId);
    if(!target)
    {
        errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
        lua_pushboolean(L, false);
        return 1;
    }
    if(!monster->isSummon())
        lua_pushboolean(L, monster->selectTarget(target));
    else
        lua_pushboolean(L, false);
    return 1;
}

add under

Code:
int32_t LuaInterface::luaDoPlayerCancelTarget(lua_State* L)
{
    //doPlayerCancelTarget(cid, target)
    ScriptEnviroment* env = getEnv();
    Player* player = env->getCreatureByUID(popNumber(L));
    if(!player)
    {
        errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
        lua_pushboolean(L, false);
        return 1;
    }
 
    player->sendCancelTarget();
    lua_pushboolean(L, true);
    return 1;
}

Luascript.h

find

Code:
static int32_t luaDoMonsterSetTarget(lua_State* L);

add under

Code:
static int32_t luaDoPlayerCancelTarget(lua_State* L);

Then spell

Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_HEALING)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, false)
function onCastSpell(cid, var)
    if isPlayer(cid) then
        local spectators = getSpectators(getPlayerPosition(cid), 9, 9, false)
        for i, v in ipairs(spectators) do
            local target = spectators[v]
            if target then
                if getCreatureName(getCreatureTarget(target)) == getCreatureName(cid) then
                    doPlayerCancelTarget(target)
                end
            end
        end
    end
    return doCombat(cid, combat, var)
end


Alright friend I tested it, and actually using the target's target magic, but the char continues to attack the other even without having the red symbol around it.
That is, only that red attack symbol canceled, but the character itself continues to attack.
 
Okay, try this out. If it doesn't work I will try another method.

luascript.cpp

Code:
int32_t LuaInterface::luaDoPlayerCancelTarget(lua_State* L)
{
    //doPlayerCancelTarget(cid, target)
    ScriptEnviroment* env = getEnv();
    Player* player = env->getCreatureByUID(popNumber(L));
    if(!player)
    {
        errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
        lua_pushboolean(L, false);
        return 1;
    }
   
    Creature* creature = env->getCreatureByUID(popNumber(L));
    if(!creature)
    {
        errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
        lua_pushboolean(L, false);
        return 1;
    }
   
    player->sendCancelTarget();
    player->sendCreatureDisappear(creature);
    player->sendCreatureAppear(creature);
    lua_pushboolean(L, true);
    return 1;
}

spell
Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_HEALING)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, false)
function onCastSpell(cid, var)
    if isPlayer(cid) then
        local spectators = getSpectators(getPlayerPosition(cid), 9, 9, false)
        for i, v in ipairs(spectators) do
            local target = spectators[v]
            if target then
                if getCreatureName(getCreatureTarget(target)) == getCreatureName(cid) then
                    doPlayerCancelTarget(target, cid)
                end
            end
        end
    end
    return doCombat(cid, combat, var)
end
 
Hello @Itutorial its me again xD, if you dont remember this post:
Teleport pad modalwindow

Well, the scripts works well but only with the first teleport on the code, the other 2, when player stepin on the "tile" it only shows the window with the title and description, it doesnt shows the "spots" here you can see how i edited it.

Creaturescripts.xml
Code:
  <event type="modalwindow" name="tp_pad" script="tp_pad.lua"/>

tp_pad.lua
Code:
local teleports = {
    [0x00] = {cost = 0, pos = {x = 314, y = 102, z = 7}},
    [0x01] = {cost = 0, pos = {x = 675, y = 245, z = 7}},
    [0x02] = {cost = 0, pos = {x = 765, y = 451, z = 7}},
    [0x03] = {cost = 0, pos = {x = 862, y = 598, z = 7}},
    [0x04] = {cost = 0, pos = {x = 846, y = 456, z = 6}},
    [0x05] = {cost = 0, pos = {x = 1387, y = 1798, z = 7}},
    [0x06] = {cost = 0, pos = {x = 69, y = 771, z = 7}},
    [0x07] = {cost = 0, pos = {x = 54, y = 711, z = 7}},
    [0x08] = {cost = 0, pos = {x = 73, y = 733, z = 6}},
    [0x09] = {cost = 0, pos = {x = 35, y = 791, z = 7}},
    [0x10] = {cost = 0, pos = {x = 86, y = 755, z = 7}},
    [0x11] = {cost = 0, pos = {x = 229, y = 689, z = 7}},
    [0x12] = {cost = 0, pos = {x = 276, y = 658, z = 7}},
    [0x13] = {cost = 0, pos = {x = 468, y = 448, z = 7}},
    [0x14] = {cost = 0, pos = {x = 950, y = 1082, z = 12}},
    [0x15] = {cost = 0, pos = {x = 872, y = 933, z = 6}},
    [0x16] = {cost = 0, pos = {x = 607, y = 603, z = 10}},
    [0x17] = {cost = 0, pos = {x = 586, y = 603, z = 10}},
    [0x18] = {cost = 0, pos = {x = 611, y = 637, z = 7}},
    [0x19] = {cost = 0, pos = {x = 554, y = 653, z = 7}},
    [0x20] = {cost = 0, pos = {x = 559, y = 589, z = 7}},
    [0x21] = {cost = 0, pos = {x = 367, y = 198, z = 7}},
    [0x22] = {cost = 0, pos = {x = 750, y = 451, z = 7}},
    [0x23] = {cost = 0, pos = {x = 827, y = 943, z = 4}},
    [0x24] = {cost = 0, pos = {x = 1351, y = 1789, z = 7}},
    [0x25] = {cost = 0, pos = {x = 858, y = 599, z = 7}},
    [0x26] = {cost = 0, pos = {x = 282, y = 419, z = 7}},
    [0x27] = {cost = 0, pos = {x = 488, y = 440, z = 6}},
    [0x28] = {cost = 0, pos = {x = 672, y = 241, z = 7}},
    [0x29] = {cost = 0, pos = {x = 871, y = 965, z = 12}},
    [0x30] = {cost = 0, pos = {x = 681, y = 487, z = 8}},
    [0x31] = {cost = 0, pos = {x = 700, y = 494, z = 7}},
    [0x32] = {cost = 0, pos = {x = 660, y = 426, z = 7}},
    [0x33] = {cost = 0, pos = {x = 599, y = 402, z = 6}},
    [0x34] = {cost = 0, pos = {x = 696, y = 478, z = 6}},
    [0x35] = {cost = 0, pos = {x = 274, y = 194, z = 6}},
    [0x36] = {cost = 0, pos = {x = 695, y = 360, z = 8}},
    [0x37] = {cost = 0, pos = {x = 827, y = 191, z = 7}},
    [0x38] = {cost = 0, pos = {x = 774, y = 449, z = 7}},
    [0x39] = {cost = 0, pos = {x = 846, y = 941, z = 6}},
    [0x40] = {cost = 0, pos = {x = 1366, y = 1799, z = 7}},
    [0x41] = {cost = 0, pos = {x = 856, y = 605, z = 7}},
    [0x42] = {cost = 0, pos = {x = 586, y = 400, z = 7}},
    [0x43] = {cost = 0, pos = {x = 953, y = 1089, z = 12}},
    [0x44] = {cost = 0, pos = {x = 472, y = 463, z = 7}},
    [0x45] = {cost = 0, pos = {x = 667, y = 251, z = 7}}


}
function onModalWindow(player, modalWindowId, buttonId, choiceId)
    if modalWindowId ~= 1860 then return true end
    if buttonId == 0x01 then return true end
    local CHOICE = teleports[choiceId]
    if not CHOICE then return true end
    if player:removeMoney(CHOICE.cost) then
        player:teleportTo(CHOICE.pos)
    else
        player:sendCancelMessage("This teleport costs "..CHOICE.cost.." to use.")
    end
return true
end

movements.xml
Code:
    <movevent event="StepIn" actionid="3402" script="tp_pad.lua"/>
    <movevent event="StepIn" actionid="3403" script="tp_pad.lua"/>
    <movevent event="StepIn" actionid="3404" script="tp_pad.lua"/>

tp_pad.lua on movements
Code:
local tiles = {
    [3402] = {
        title = "Wind Nation Spots",
        desc = "Select Destination:",
        teleports = {
            [0] = {id = 0x00, text = "Rotworms"},
            [1] = {id = 0x01, text = "Hero Fortress"},
            [2] = {id = 0x02, text = "Asura Palace"},
            [3] = {id = 0x03, text = "Mistrock"},
            [4] = {id = 0x04, text = "Yielothax"},
            [5] = {id = 0x05, text = "Roshamuul"},
            [6] = {id = 0x06, text = "Wind Temple"},
            [7] = {id = 0x07, text = "Wind Depot"},
            [8] = {id = 0x08, text = "Magic Shop"},
            [9] = {id = 0x09, text = "Distance Shop"},
            [10] = {id = 0x10, text = "Rashid"},
            [11] = {id = 0x11, text = "Wyrm"},
            [12] = {id = 0x12, text = "Behemoth"},
            [13] = {id = 0x13, text = "Neutral Nation"},
            [14] = {id = 0x14, text = "Glooth Bandit"},
            [15] = {id = 0x15, text = "Oramond"}
        }
    },
    [3404] = {
        title = "Earth Nation Spots",
        desc = "Select Destination:",
        teleports = {
            [30] = {id = 0x30, text = "Earth Temple"},
            [31] = {id = 0x31, text = "Earth Depot"},
            [32] = {id = 0x32, text = "Magic Shop"},
            [33] = {id = 0x33, text = "Distance Shop"},
            [34] = {id = 0x34, text = "Rashid"},
            [35] = {id = 0x35, text = "Rotworms"},
            [36] = {id = 0x36, text = "Medusa Tower"},
            [37] = {id = 0x37, text = "Serpent Spawn"},
            [38] = {id = 0x38, text = "Asura Palace"},
            [39] = {id = 0x39, text = "Oramond"},
            [40] = {id = 0x40, text = "Roshamuul"},
            [41] = {id = 0x41, text = "Mistrock"},
            [42] = {id = 0x42, text = "Earth Elemental"},
            [43] = {id = 0x43, text = "Glooth Bandits"},
            [44] = {id = 0x44, text = "Neutral Nation"},
            [45] = {id = 0x45, text = "Hero Fortress"}
        }
    },
    [3403] = {
        title = "Fire Nation Spots",
        desc = "Select Destination:",
        teleports = {
            [16] = {id = 0x16, text = "Fire Temple"},
            [17] = {id = 0x17, text = "Fire Depot"},
            [18] = {id = 0x18, text = "Magic Shop"},
            [19] = {id = 0x19, text = "Distance Shop"},
            [20] = {id = 0x20, text = "Rashid"},
            [21] = {id = 0x21, text = "Rotworms"},
            [22] = {id = 0x22, text = "Asura Palace"},
            [23] = {id = 0x23, text = "Oramond"},
            [24] = {id = 0x24, text = "Roshamuul"},
            [25] = {id = 0x25, text = "Mistrock"},
            [26] = {id = 0x26, text = "Dragons"},
            [27] = {id = 0x27, text = "Neutral Nation"},
            [28] = {id = 0x28, text = "Hero Fortress"},
            [29] = {id = 0x29, text = "Glooth Bandits"}
        }
    }
}
function onStepIn(player, item, position, fromPosition)
    local TILE = tiles[item:getActionId()]
    if not TILE then return true end
    if not player:isPlayer() then return true end
    local window = ModalWindow(1860, TILE.title, TILE.desc)
    for i = 1, #TILE.teleports do
        window:addChoice(TILE.teleports[i].id, TILE.teleports[i].text)
    end
    window:addButton(0x00, "Teleport")
    window:addButton(0x01, "Close")
    window:setDefaultEnterButton(0x00)
    window:sendToPlayer(player)
return true
end

think thats all, idk whats wrong...
thank you man you have help me a lot.
 
Oh your problem is the tables value shouldnt be:

[30] = {xx}

All new tile teleports table should start at 1 and end at what ever is the last

So each teleport should be:

1
2
3
4
5
6

not

30
31
32
33
34

Only the 0x30 should be as it is


so

Lua:
local tiles = {
    [3402] = {
        title = "Wind Nation Spots",
        desc = "Select Destination:",
        teleports = {
            [1] = {id = 0x00, text = "Rotworms"},
            [2] = {id = 0x01, text = "Hero Fortress"},
            [3] = {id = 0x02, text = "Asura Palace"},
            [4] = {id = 0x03, text = "Mistrock"},
            [5] = {id = 0x04, text = "Yielothax"},
            [6] = {id = 0x05, text = "Roshamuul"},
            [7] = {id = 0x06, text = "Wind Temple"},
            [8] = {id = 0x07, text = "Wind Depot"},
            [9] = {id = 0x08, text = "Magic Shop"},
            [10] = {id = 0x09, text = "Distance Shop"},
            [11] = {id = 0x10, text = "Rashid"},
            [12] = {id = 0x11, text = "Wyrm"},
            [13] = {id = 0x12, text = "Behemoth"},
            [14] = {id = 0x13, text = "Neutral Nation"},
            [15] = {id = 0x14, text = "Glooth Bandit"},
            [16] = {id = 0x15, text = "Oramond"}
        }
    },
    [3404] = {
        title = "Earth Nation Spots",
        desc = "Select Destination:",
        teleports = {
            [1] = {id = 0x30, text = "Earth Temple"},
            [2] = {id = 0x31, text = "Earth Depot"},
            [3] = {id = 0x32, text = "Magic Shop"},
            [4] = {id = 0x33, text = "Distance Shop"},
            [5] = {id = 0x34, text = "Rashid"},
            [6] = {id = 0x35, text = "Rotworms"},
            [7] = {id = 0x36, text = "Medusa Tower"},
            [8] = {id = 0x37, text = "Serpent Spawn"},
            [9] = {id = 0x38, text = "Asura Palace"},
            [10] = {id = 0x39, text = "Oramond"},
            [11] = {id = 0x40, text = "Roshamuul"},
            [12] = {id = 0x41, text = "Mistrock"},
            [13] = {id = 0x42, text = "Earth Elemental"},
            [14] = {id = 0x43, text = "Glooth Bandits"},
            [15] = {id = 0x44, text = "Neutral Nation"},
            [16] = {id = 0x45, text = "Hero Fortress"}
        }
    },
    [3403] = {
        title = "Fire Nation Spots",
        desc = "Select Destination:",
        teleports = {
            [1] = {id = 0x16, text = "Fire Temple"},
            [2] = {id = 0x17, text = "Fire Depot"},
            [3] = {id = 0x18, text = "Magic Shop"},
            [4] = {id = 0x19, text = "Distance Shop"},
            [5] = {id = 0x20, text = "Rashid"},
            [6] = {id = 0x21, text = "Rotworms"},
            [7] = {id = 0x22, text = "Asura Palace"},
            [8] = {id = 0x23, text = "Oramond"},
            [9] = {id = 0x24, text = "Roshamuul"},
            [10] = {id = 0x25, text = "Mistrock"},
            [11] = {id = 0x26, text = "Dragons"},
            [12] = {id = 0x27, text = "Neutral Nation"},
            [13] = {id = 0x28, text = "Hero Fortress"},
            [14] = {id = 0x29, text = "Glooth Bandits"}
        }
    }
}
function onStepIn(player, item, position, fromPosition)
    local TILE = tiles[item:getActionId()]
    if not TILE then return true end
    if not player:isPlayer() then return true end
    local window = ModalWindow(1860, TILE.title, TILE.desc)
    for i = 1, #TILE.teleports do
        window:addChoice(TILE.teleports[i].id, TILE.teleports[i].text)
    end
    window:addButton(0x00, "Teleport")
    window:addButton(0x01, "Close")
    window:setDefaultEnterButton(0x00)
    window:sendToPlayer(player)
return true
end

See each new teleports table starts at 1 even though its id = 0x30 or 0x00 or 0x16
 
Last edited:
Works now, how i setup it to when they choose the "spot" the window close? and send a message like monsters in orange?

thank you man
 
You want it to send a message to where? To the location they teleported? or send a message where they teleported from?
 
Code:
int32_t LuaInterface::luaDoPlayerCancelTarget(lua_State* L)
{
    //doPlayerCancelTarget(cid, target)
    ScriptEnviroment* env = getEnv();
    Player* player = env->getCreatureByUID(popNumber(L));
    if(!player)
    {
        errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
        lua_pushboolean(L, false);
        return 1;
    }
   
    uint32_t targetId = popNumber(L);
   
    Creature* target = env->getCreatureByUID(targetId);
    if(!target)
    {
        errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
        lua_pushboolean(L, false);
        return 1;
    }
   
    player->sendCancelTarget();
    player->sendCreatureDisappear(target, 1);
    player->sendCreatureAppear(target);
    lua_pushboolean(L, true);
    return 1;
}
 
Code:
int32_t LuaInterface::luaDoPlayerCancelTarget(lua_State* L)
{
    //doPlayerCancelTarget(cid, target)
    ScriptEnviroment* env = getEnv();
    Player* player = env->getCreatureByUID(popNumber(L));
    if(!player)
    {
        errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
        lua_pushboolean(L, false);
        return 1;
    }
   
    Player* target = env->getCreatureByUID(popNumber(L));
    if(!target)
    {
        errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
        lua_pushboolean(L, false);
        return 1;
    }
   
    player->sendCancelTarget();
    player->sendCreatureDisappear(target, 1);
    player->sendCreatureAppear(target);
    lua_pushboolean(L, true);
    return 1;
}
 
Back
Top