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

Adding action in C++

Elime

OTServers.eu
Joined
Apr 11, 2013
Messages
263
Solutions
1
Reaction score
264
Location
Sweden
Hello!

I tried to add an action in c++. I'm using TFS 0.2.14

So I put this in actions.xml:
Code:
<action itemid="2559" function="toolAxe"/>

And in actions.h at the end I added toolAxe:
Code:
protected:
virtual std::string getScriptEventName();

static ActionFunction highscoreBook;
static ActionFunction increaseItemId;
static ActionFunction decreaseItemId;
static ActionFunction enterMarket;
static ActionFunction toolAxe;

And in actions.cpp I added toolaxe in loadFunction:

Code:
bool Action::loadFunction(const std::string& functionName)
{
std::string tmpFunctionName = asLowerCaseString(functionName);
if(tmpFunctionName == "increaseitemid")
	function = increaseItemId;
else if(tmpFunctionName == "decreaseitemid")
	function = decreaseItemId;
else if(tmpFunctionName == "highscorebook")
	function = highscoreBook;
else if(tmpFunctionName == "market")
	function = enterMarket;
else if(tmpFunctionName == "toolaxe")
        function = toolAxe;
else
{
	std::cout << "[Warning - Action::loadFunction] Function \"" << functionName << "\" does not exist." << std::endl;
	return false;
}

m_scripted = false;
return true;
}

And then I added a toolAxe function:
Code:
bool Action::toolAxe(Player* player, Item* item, const PositionEx& posFrom, const PositionEx& posTo, bool extendedUse, uint32_t creatureId)
{
    std::cout << "It's worknig!" << std::endl;
    return true;
}

But when I try out the action I get this error:
Code:
Lua Script Error: [Action Interface] 
(Unknown scriptfile)
attempt to call a nil value
stack traceback:
[C]: ?

I have no idea why. Even after staring at the code for quite some time! =P
Does somebody have any idea how I can solve this?

Thanks

Edit:

I found out it works if I change the itemid to something else. For some reason items which are used with crosshairs (like the axe) won't work. Does anyone know why?
 
Last edited:
Back
Top