Page 1 of 1

[REQ] FaceTarget() stops visual_state

Posted: Wed Oct 08, 2008 10:33 pm
by John Adams
When you Hail an NPC and they are doing something visually (menders for example are smithing), the NPC should turn to face the player and stop what they are doing until the player ignores them for a duration and FaceTarget() expires - then put the NPC back into it's original visual_state.
An example is a mender that is banging out iron, turns to face the player, still banging, says their PlayFlavor (yes, still banging) but sneaks in a bow or smile or wink emote, then immediately goes back to banging iron, spraying sparks and shards of metal all over the players nice magic robes. ;)

Posted: Thu Oct 09, 2008 9:41 am
by Jabantiz
I attempted to code this as well, in a coding mood today I guess, and again this works for me. Not sure if this is the best way or correct way to do it but have yet to crash or screw up my server with this code.
In Entity.cpp around line 341 find:

Code: Select all

if(GetHP() > 0 && target->IsPlayer() && !EngagedInCombat())
		GetZone()->AddHeadingTimer(this);
And replace with this:

Code: Select all

if(GetHP() > 0 && target->IsPlayer() && !EngagedInCombat()){
		GetZone()->AddHeadingTimer(this);
		SetTempVisualState(GetVisualState());
		SetVisualState(0);
	}
In ZoneServer.cpp around line 1509 find:

Code: Select all

if(itr->second->Check(false)){
				itr->first->SetHeading(itr->first->GetSpawnOrigHeading());
Right after it add this:

Code: Select all

itr->first->SetVisualState(itr->first->GetTempVisualState());
itr->first->SetTempVisualState(0);
I know these are rather small things but I hope it is helpful, and the correct way of doing this stuff.

Posted: Thu Oct 09, 2008 10:47 am
by John Adams
Hey man, every small thing adds to the completion of the emulator. Nice work! Can I ask you to create "patches" though instead of find/replace?
If you use TortoiseSVN, you can right-click on your checked out code and drill down to Create Patch, and it will compare your modified code with what is current SVN, and save to a *.patch file. Then all we have to do is apply that patch rather than hunt and peck for where the changes go.
Keep up the good work. I wish I could code, but I have yet to find that rosetta stone =)

Posted: Thu Oct 09, 2008 11:04 am
by Jabantiz
Is this what you need? Never did this stuff before.
ZoneServer.patch

Code: Select all

Index: zoneserver.cpp
===================================================================
--- zoneserver.cpp	(revision 151)
+++ zoneserver.cpp	(working copy)
@@ -1507,6 +1507,8 @@
 		for(itr = heading_timers.begin(); itr != heading_timers.end(); itr++){
 			if(itr->second->Check(false)){
 				itr->first->SetHeading(itr->first->GetSpawnOrigHeading());
+				itr->first->SetVisualState(itr->first->GetTempVisualState());
+				itr->first->SetTempVisualState(0);
 				safe_delete(itr->second);
 				heading_timers.erase(itr);
 				break;
Entity.patch

Code: Select all

Index: Entity.cpp
===================================================================
--- Entity.cpp	(revision 151)
+++ Entity.cpp	(working copy)
@@ -338,8 +338,11 @@
 	if(!target)
 		return;
 	FaceTarget(target->GetX(), target->GetZ());
-	if(GetHP() > 0 && target->IsPlayer() && !EngagedInCombat())
+	if(GetHP() > 0 && target->IsPlayer() && !EngagedInCombat()){
 		GetZone()->AddHeadingTimer(this);
+		SetTempVisualState(GetVisualState());
+		SetVisualState(0);
+	}
 }
 
 void Entity::SetHPRegen(int16 new_val){
Provided links incase you need the actual files. If this is what you needed I will do the same for my other post.

Posted: Thu Oct 09, 2008 12:12 pm
by John Adams
Yup, that's it. What you can do though (sorry I wasn't clear) right-click on the World folder itself, and all changes will be included into a single patch file.
This is good though, just FYI for future patching. I'll give your code a try! Thanks again.

Posted: Thu Oct 09, 2008 12:18 pm
by Jabantiz
Yea I noticed you could do that but figured I should post only the changes relative to this topic, will post links for the other changes I made in its respective post. Also I didn't want to group it all together in case I screwed up on one of them.
**EDIT**
Edited my last post in the Race vs Race_Type thread and added the patch files.

Posted: Sat Oct 11, 2008 6:20 am
by LethalEncounter
Added to code as slightly different than your implementation, but the same general concept. Great work though :)

Posted: Tue Oct 14, 2008 12:53 am
by John Adams
LE, should this code be working on the Dev SVN? If so, it's not. Ajarn, the Shieldsmith in Nettleville still hammering away when he's talking to me.

Posted: Tue Oct 14, 2008 2:32 pm
by LethalEncounter
Did you have him face you first?

Posted: Tue Oct 14, 2008 2:43 pm
by John Adams
FaceTarget() is always our first command.
He does appear to stop for a moment while performing ihs emote, but soon as the emote expires, he's back to pounding.

Posted: Tue Oct 14, 2008 3:11 pm
by LethalEncounter
Ahh, because it is an action state, not a visual state. I'll have to fix it.

Posted: Tue Oct 14, 2008 3:21 pm
by John Adams
I'm sorry, that was my mistake. It is action_state, not visual_state. Oops =) I guess I knew that, just typed the wrong thing... doh.
Thanks