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

Avesta 7.4 NPC Spell Teacher?

Kungenn

Veteran OT User
Joined
Jun 10, 2007
Messages
1,625
Reaction score
283
Location
USA California
Using Jiddo's Advanced NPC System 3.0

Anyone got an npc example that works?

Or got any clue on how to make one?

I've been giving it my best for several hours now and it just won't work :/

Right now I'm getting
Code:
merlin.lua:94: attempt to call global 'PlayerLearnInstantSpell' (a nil value)
stack traceback:
 merlin:94: in function 'callback'
npchandler.lua:299: in function 'onCreatureSay'
merlin.lua:7: in function <data/npc/script/merlin.lua:7>

Appreciate any help ;)
 
Code:
      if (msgcontains(msg, 'Find') and msgcontains(msg, 'Person')) then
           if (getPlayerVocation(cid) == 3 or getPlayerVocation(cid) == 7) then
			spell = "Find Person"
			level = 1
			money = 80
			npcHandler:say('You want to buy the spell '.. spell ..' for '.. money ..' gold?')
			talkState[talkUser] = 1
	else
                        npcHandler:say("Sorry, I only sell spells to Paladins.",cid)
                        talkState[talkUser] = 0
	end
	elseif (msgcontains(msg, 'yes')) and (talkState[talkUser] == 1) then
		if (getPlayerLearnedInstantSpell(cid,spell) ~= TRUE) then
			if (getPlayerLevel(cid) >= level) then
				if (doPlayerRemoveMoney(cid,money) == TRUE) then
					npcHandler:say("Here you are. Look in your spellbook for the pronunciation of this spell.",cid)
					doSendMagicEffect(getCreaturePosition(cid),12)
					playerLearnInstantSpell(cid,spell)
				else
					npcHandler:say("Oh. You do not have enough money.",cid)
                                        talkState[talkUser] = 0
				end
			else
				npcHandler:say('You have to be level '.. level ..' to learn this spell.')
                                talkState[talkUser] = 0
			end
		else
			npcHandler:say("You already know how to cast this spell.",cid)
                        talkState[talkUser] = 0
		end

Or you have no "PlayerLearnInstantSpell" function, try to change it.
 
if you can compile your distro then add this to ur sources

find this
Code:
lua_register(m_luaState, "getTilePzInfo", LuaScriptInterface::luaGetTilePzInfo);

under that add this
Code:
	//playerLearnInstantSpell(cid, name)
	lua_register(m_luaState, "playerLearnInstantSpell", LuaScriptInterface::luaPlayerLearnInstantSpell);

now find this
Code:
		reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND));
		lua_pushnumber(L, LUA_ERROR);
	}
	return 1;
}

under the last } add this
Code:
int LuaScriptInterface::luaPlayerLearnInstantSpell(lua_State *L)
{
	//playerLearnInstantSpell(cid, name)
	std::string spellName = popString(L);
	uint32_t cid = popNumber(L);

	ScriptEnviroment* env = getScriptEnv();

	Player* player = env->getPlayerByUID(cid);
	if(!player){
		reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND));
		lua_pushnumber(L, LUA_ERROR);
		return 1;
	}

	InstantSpell* spell = g_spells->getInstantSpellByName(spellName);
	if(!spell){
		std::string error_str = (std::string)"Spell \"" + spellName +  (std::string)"\" not found";
		reportErrorFunc(error_str);
		lua_pushnumber(L, LUA_ERROR);
		return 1;
	}

	player->learnInstantSpell(spell->getName());
	lua_pushnumber(L, LUA_TRUE);
	return 1;
}

now find this
Code:
	static int luaGetWorldType(lua_State *L);

under that add this
Code:
	static int luaPlayerLearnInstantSpell(lua_State *L);

then after adding that last code compile and test!

i hope this will help u;)
 
7.4 npc system in latest avesta is changed, take npc.cpp and npc.h from an older version and change it, also don't forget to change npc system (data/npc/script/lib/)
 
Back
Top