Lua: Getting ID # of a traded item

Post Reply
masterurat
Posts: 81
Joined: Sat May 03, 2014 7:05 pm

Lua: Getting ID # of a traded item

Post by masterurat » Sat Jun 28, 2014 12:34 am

I want to create an onTrade script for an NPC, that will do something like this...

Code: Select all

onTrade()
    if (Totaltradeditems==5 and One of the items ID is >12107 and <12285 ) then 
//Its a piece of ebon type gear)

        ItemID= 12108 - (the itemID that is >12107 and <12285) //This value will be 0~179)

        ItemSlot = math.floor(ItemID/36)      //(0-4, 0=head,1=body,2=hands,3=legs,4=feet)


        ItemRank = ItemID - (ItemSlot * 36)// (Value 0~35)

I think my best way to do it is a for loop of x=0~179, and check if the player traded an item of ID 12107+x?

so maybe...

Code: Select all

for x=0 to 179 do
     if itemTraded(x+12107) then
          DoStuff()
     EndIf
Next
Or is there an easy way to fetch the IDs of all the items traded in our lua script?


Other questions:

Do we have lua functions to get all the data of an Item that was traded?

IE
OurItem = tradedItem[slot1]

Signature = OurItem->GetSignature()

What parts are we missing to do the above?


Finally, do we have a way to play animitations/effects through lua? If not, do we have easy functions to use in the source code to make a lua function for such a thing?

Just a simple Player->PlayEffect(x) so I could play effect x at player through code.

This would be great for custom game quests and effects and stuff.

User avatar
kjLotus
Special Guest
Posts: 1813
Joined: Sun Jul 22, 2012 2:16 pm

Re: Lua: Getting ID # of a traded item

Post by kjLotus » Sat Jun 28, 2014 12:47 am

look at other NPCs that have trades scripted - i don't think there's currently a way to get signature in trades, but you can write one (the item reference will be in the trade container)

last question, no, but you might be able to do it by making something similar to injectactionpacket though

masterurat
Posts: 81
Joined: Sat May 03, 2014 7:05 pm

Re: Lua: Getting ID # of a traded item

Post by masterurat » Sat Jun 28, 2014 2:02 am

Tried this code... It does something but Im not sure if it is doing anything...

Code: Select all

inline int32 CLuaBaseEntity::setAction(lua_State *L)
{
	DSP_DEBUG_BREAK_IF(m_PBaseEntity == NULL);

	DSP_DEBUG_BREAK_IF(lua_isnil(L, -1));

	DSP_DEBUG_BREAK_IF(!lua_isnumber(L, -1));

	uint16 ID = (uint8)lua_tointeger(L, -1);

	const int8* name = m_PBaseEntity->GetName();

	apAction_t Action;
	CCharEntity* m_PChar = (CCharEntity*)m_PBaseEntity;

	Action.animation = ID;
	Action.speceffect = SPECEFFECT_NONE;
	Action.reaction = REACTION_NONE;
	Action.ActionTarget = m_PChar;
	Action.messageID = 0;
	Action.knockback = 0;

	
	m_PChar->m_ActionList.push_back(Action);
	m_PChar->loc.zone->PushPacket(m_PChar, CHAR_INRANGE_SELF, new CActionPacket(m_PChar));

	return 0;
}
No errors, but no matter what value I do for ID, nothing happens except the character's target goes to themself (akin to F1ing yourself to target yourself)

No animation plays no matter what ID I use :(

Am I missing something important here?

User avatar
kjLotus
Special Guest
Posts: 1813
Joined: Sun Jul 22, 2012 2:16 pm

Re: Lua: Getting ID # of a traded item

Post by kjLotus » Sat Jun 28, 2014 2:49 am

the action packet depends on the users current AI state to determine which type of animation to look up (ACTION_WEAPONSKILL_FINISH etc)

masterurat
Posts: 81
Joined: Sat May 03, 2014 7:05 pm

Re: Lua: Getting ID # of a traded item

Post by masterurat » Sat Jun 28, 2014 4:46 am

All right, is there an easier way then all of this to send a packet for the player to just play an animation? I feel like there has to be.

Edit: Yeah as I was worried, doing this stuff actually makes the player use the ability, and the code will apply all the bonuses effects and etc. I just wanted the animation and not all the other stuff that goes with it.

I got it able to use the ability via the code below, but that isn't what I wanted at all :(

Code: Select all

inline int32 CLuaBaseEntity::setAction(lua_State *L)
{
	DSP_DEBUG_BREAK_IF(m_PBaseEntity == NULL);

	DSP_DEBUG_BREAK_IF(lua_isnil(L, -1));

	DSP_DEBUG_BREAK_IF(!lua_isnumber(L, -1));

	uint16 ID = (uint8)lua_tointeger(L, -1);

	const int8* name = m_PBaseEntity->GetName();

	apAction_t Action;
	CCharEntity* m_PChar = (CCharEntity*)m_PBaseEntity;
	CBattleEntity* m_BChar = (CBattleEntity*)m_PBaseEntity;


	Action.animation = ID;
	Action.speceffect = SPECEFFECT_HIT;
	Action.reaction = REACTION_HIT;
	Action.ActionTarget = m_PChar;
	Action.messageID = 0;
	Action.knockback = 0;
	
	m_BChar->PBattleAI->SetCurrentJobAbility(ID);
	m_BChar->PBattleAI->SetCurrentAction(ACTION_JOBABILITY_FINISH, m_BChar->id);


	m_PChar->m_ActionList.push_back(Action);

	m_BChar->PBattleAI->SetBattleSubTarget(m_BChar);


	uint16 jobability = m_BChar->PBattleAI->GetCurrentJobAbility()->getID(); // for testing


	m_PChar->pushPacket(new CActionPacket(m_PChar));
	return 0;
}
Im gonna delve in and figure out where the packet for the animation is.

Post Reply