Jump to content
×
×
  • Create New...
  • 0

npc.get_ip for kill own character check error


.Avenue™

Question

  • Premium

questfunction:

    int npc_get_ip(lua_State* L)
    {
        LPCHARACTER npc = CQuestManager::instance().GetCurrentNPCCharacterPtr();
        lua_pushstring(L, npc->GetDesc()->GetHostName());
        return 1;
    }

 

error:

questlua_npc.cpp: In function 'int quest::npc_get_ip(lua_State*)':
questlua_npc.cpp:357: error: invalid use of incomplete type 'struct DESC'
typedef.h:4: error: forward declaration of 'struct DESC'

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0
	int pc_get_ip(lua_State* L)
	{
		LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
		
		if(!ch)
			return 0;
	 
		lua_pushstring(L, ch->GetDesc()->GetHostName());
		return 1;
	}
quest iptest begin
    state start begin
		when kill begin
			local vid = npc.get_vid()
			local old_pc = pc.select(vid)
			if old_pc != 0 then
				local e_ip = pc.get_ip()
				local e_name = pc.get_name()
				pc.select(old_pc)
				local m_ip = pc.get_ip()
				local m_name = pc.get_name()
				if e_ip == m_ip then
					syschat("same ip")
					syschat(""..e_name.." : "..e_ip.."")
					syschat(""..m_name.." : "..m_ip.."")
				else
					syschat("not same ip")
				end
			end
		end
    end
end

Try this one.

Link to comment
Share on other sites

  • 0
  • Premium

Find

#include "sectree_manager.h"

And add after:

#include "desc.h"

And I recommend you to use this function, otherwise your game may crash:

	int npc_get_ip(lua_State* L)
	{
		LPCHARACTER npc = CQuestManager::instance().GetCurrentNPCCharacterPtr();

		if (!npc || !npc->GetDesc())
		{
			lua_pushstring(L, "INVALID");
			return 1;
		}

		lua_pushstring(L, npc->GetDesc()->GetHostName());
		return 1;
	}

 

If the enemy is not a PC (if you forgot to check or you don't want to) or it's an invalid instance (kinda impossible) then the function will return "INVALID" and you may do a check in your quest (if pc.get_ip() == "INVALID" then).

Tell me if that works.

  • Love 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.