NPC Movement

Discussions of the design and development of in-game content.

Moderator: Team Members

User avatar
Ememjr
Team Member
Posts: 975
Joined: Wed Mar 15, 2017 9:41 am
EQ2Emu Server: Perseverance

NPC Movement

Post by Ememjr » Wed Nov 01, 2017 2:17 pm

i need to move a NPC fom point a to point B following a specific route
i was able to do it with the movementloopadd location
but, it loops, and i dont want it to loop
i used 3 move to locations, but the npc doesnt follow the path it just runs into the wall as if i had only put the final movetolocation

what can you do to make the npc move via specific waypoints and have it be seemless no pauses between waypints

Jabantiz
Lead Developer
Posts: 2912
Joined: Wed Jul 25, 2007 2:52 pm
Location: California

Re: NPC Movement

Post by Jabantiz » Wed Nov 01, 2017 4:55 pm

MoveToLocation is going to be what you want to use, however that sets the destination location immediately so using them back to back will just overwrite the previous.

MoveToLocation does have optional parameters, one of them being a callback function for when they arrive at the location, if you set up a callback and put the next MoveToLocation in there then it should work how you want it to.

User avatar
Ememjr
Team Member
Posts: 975
Joined: Wed Mar 15, 2017 9:41 am
EQ2Emu Server: Perseverance

Re: NPC Movement

Post by Ememjr » Thu Nov 02, 2017 4:41 am

no luck maybe i missed something
goes to the first location and stops, does not appear to be getting to ingridmove2

Code: Select all

function ingridscript(NPC, Spawn)
	FaceTarget(NPC, Spawn)
	--PlayFlavor(Spawn, mp3_filename, text, emote, mp3_key1, mp3_key2, Player)
	PlayFlavor(NPC,"voiceover/english/captain_varlos/boat_06p_tutorial02_fvo_005.mp3","We are heading to the Island of Refuge.","",1602680439,2810422278,Spawn)
	PerformCameraShake(Spawn,52429,15948)
	local ingrid = GetSpawn(Spawn,270007)
	MoveToLocation(ingrid, -2.48, -1.78, -9.14, 4, "ingridmove2")
end

function ingridmove2(NPC, Spawn)
	local ingrid = GetSpawn(Spawn,270007)
	MoveToLocation(ingrid, -2.07, 1.21, -14.71, 4, "ingridmove3")
end

function ingridmove3(NPC, Spawn)
	local ingrid = GetSpawn(Spawn,270007)
	MoveToLocation(ingrid, 1.01, 1.19, 12.25, 4)
end

Jabantiz
Lead Developer
Posts: 2912
Joined: Wed Jul 25, 2007 2:52 pm
Location: California

Re: NPC Movement

Post by Jabantiz » Thu Nov 02, 2017 3:47 pm

The callback will be like MovementLoopAddLocation call backs so it will only have a single parameter. As you pass Ingrid as the spawn for MoveToLocation she will be the only parameter

Code: Select all

function ingridmove2(NPC)
	MoveToLocation(NPC, -2.07, 1.21, -14.71, 4, "ingridmove3")
end
Also I may be mistaken on this next part but I believe that when the callback is triggered it will actually look up the function in Ingrid's spawn script.

User avatar
Ememjr
Team Member
Posts: 975
Joined: Wed Mar 15, 2017 9:41 am
EQ2Emu Server: Perseverance

Re: NPC Movement

Post by Ememjr » Thu Nov 02, 2017 4:15 pm

i was playing around with it so in the callback if it only returns, usually the second parameter is the player, how do i access that after the callback

Code: Select all

--[[
	Script Name	: SpawnScripts/Farseas/Ingrid.lua
	Script Purpose	: Ingrid
	Script Author	: Ememjr
	Script Date		: 2017.10.30
	Script Notes	:
--]]
here is ingrid script, but it appears that ingridmove2 never gets hit either

function hailed(NPC, Spawn)
end
function ingridmove2(NPC)
	local varlos = GetSpawn(NPC,270008)
	Say(NPC,"Hellllllp")
	Say(varlos, "This is me talking again")
	--PerformCameraShake(Spawn,52429,15948)
	local ingrid = GetSpawn(Spawn,270007)
	MoveToLocation(ingrid, -2.48, -1.78, -9.14, 4, "ingridmove3")
	--MoveToLocation(ingrid, -2.07, 1.21, -14.71, 4, "ingridmove3")
end
function ingridmove3(NPC)
	--PerformCameraShake(Spawn,52429,15948)
	local ingrid = GetSpawn(Spawn,270007)
	MoveToLocation(ingrid, 1.01, 1.19, -12.25, 4)
end
btw , i can seem to get it to work if i just have varlos move in my test, is there some way to trigger a spawn to active something in there script

Jabantiz
Lead Developer
Posts: 2912
Joined: Wed Jul 25, 2007 2:52 pm
Location: California

Re: NPC Movement

Post by Jabantiz » Thu Nov 02, 2017 5:16 pm

I just checked the code and the callback will be looked up in the spawn that is moving so the callback does need to be in Ingrid's script as she is the one that is moving. It will only have a single parameter though and there is no way around that.

So to get the player you will have to use SetTempVariable() to store the player pointer on Ingrid and GetTempVariable() to retrieve it in Ingrid's spawn script.

So In Varlos's script you would want something like this

Code: Select all

	local ingrid = GetSpawn(Spawn,270007)
	SetTempVariable(ingrid, "PlayerPointer", Spawn)
	MoveToLocation(ingrid, -2.48, -1.78, -9.14, 4, "ingridmove2")
And in Ingrid's script you would want this

Code: Select all

function ingridmove2(NPC)
	local varlos = GetSpawn(NPC,270008)
	Say(NPC,"Hellllllp")
	Say(varlos, "This is me talking again")
	
	local player = GetTempVariable(NPC, "PlayerPointer")
	if player ~= nil then
		PerformCameraShake(player,52429,15948)
	end

	MoveToLocation(NPC, -2.48, -1.78, -9.14, 4, "ingridmove3")
end

User avatar
Ememjr
Team Member
Posts: 975
Joined: Wed Mar 15, 2017 9:41 am
EQ2Emu Server: Perseverance

Re: NPC Movement

Post by Ememjr » Thu Nov 02, 2017 7:17 pm

dang, its still not getting to ingridmove2, any idea where i could trace it through the debug

Jabantiz
Lead Developer
Posts: 2912
Joined: Wed Jul 25, 2007 2:52 pm
Location: California

Re: NPC Movement

Post by Jabantiz » Thu Nov 02, 2017 8:06 pm

The call backs will be triggered in spawn.cpp, spawn::ProcessMovement()

I will see if I can run a few quick tests to see what is going on.

EDIT: Made a mistake here, ProcessMovement will only trigger for movement loops, for a straight moveto it is triggered from CalculateChange()

Jabantiz
Lead Developer
Posts: 2912
Joined: Wed Jul 25, 2007 2:52 pm
Location: California

Re: NPC Movement

Post by Jabantiz » Thu Nov 02, 2017 9:05 pm

So I did a simple test and it is all working as expected. Just assigned test scripts to two random npc's in thundering steppes.

This is the first script

Code: Select all

function hailed(NPC, Spawn)
	Say(NPC, "Foo")
	local test = GetSpawn(NPC, 2490031)
	if test ~= nil then
		MoveToLocation(test, -428.29, -21.03, -396.54, 2, "TestCallback")
	end
end
And here is the second script

Code: Select all

function TestCallback(NPC)
	Say(NPC, "TEST!!!")
	
	local test = GetSpawn(NPC, 2490236)
	if test ~= nil then
		Say(test, "BAR")
	end
end
And as you can see in the pic all of the Say() got triggered.
scripttest.png
Not sure where it is going wrong on your end, I will go over the scripts you posted again to see if there is any error I missed.
You do not have the required permissions to view the files attached to this post.

User avatar
Ememjr
Team Member
Posts: 975
Joined: Wed Mar 15, 2017 9:41 am
EQ2Emu Server: Perseverance

Re: NPC Movement

Post by Ememjr » Fri Nov 03, 2017 7:15 am

ill will strip dwon my scripts to bare minimum and test tonght,
BTW thanks for all the help

User avatar
Ememjr
Team Member
Posts: 975
Joined: Wed Mar 15, 2017 9:41 am
EQ2Emu Server: Perseverance

Re: NPC Movement

Post by Ememjr » Fri Nov 03, 2017 11:11 am

still no go
here is varlos

Code: Select all

function ingridscript(NPC, Spawn)
	Say(NPC, "Foo")
	local test = GetSpawn(NPC, 270007)
	if test ~= nil then
		MoveToLocation(test, -2.48, -1.78, -9.14, 4, "TestCallback")
	end
end
here is ingrid

Code: Select all

function TestCallback(NPC)
	Say(NPC, "TEST!!!")

	local test = GetSpawn(NPC, 270008)
	if test ~= nil then
		Say(test, "BAR")
	end
end
and still testcallback is not being called

to i need anything else minimum is ingrid script

User avatar
Ememjr
Team Member
Posts: 975
Joined: Wed Mar 15, 2017 9:41 am
EQ2Emu Server: Perseverance

Re: NPC Movement

Post by Ememjr » Fri Nov 03, 2017 11:26 am

i checked my spawn .cpp and it is the same as svn, any other files i should check

Jabantiz
Lead Developer
Posts: 2912
Joined: Wed Jul 25, 2007 2:52 pm
Location: California

Re: NPC Movement

Post by Jabantiz » Fri Nov 03, 2017 3:07 pm

No other files to check, lua will go straight to spawn.cpp and mostly everything is contained in there, only a portion in the zone that calls spawn to get the spawn moving and you said it does move so it is not an issue with that.

For testing try reducing the speed, I wonder if it overshoots the location and isn't within the tolerance to trigger the call back, try changing it from 4 to 2.

User avatar
Ememjr
Team Member
Posts: 975
Joined: Wed Mar 15, 2017 9:41 am
EQ2Emu Server: Perseverance

Re: NPC Movement

Post by Ememjr » Fri Nov 03, 2017 8:04 pm

omg , i cannot believe this,
there was an issue with the spawn entry in the db
i reentered , with the same values and deleted the orginal and it workeded

i only figured it out because i traced it through and in the callspawnscript function there was a null in the spawnscript location

User avatar
Ememjr
Team Member
Posts: 975
Joined: Wed Mar 15, 2017 9:41 am
EQ2Emu Server: Perseverance

Re: NPC Movement

Post by Ememjr » Fri Nov 03, 2017 9:01 pm

ok now its acting wierd although it kinda works here is ingrid scrip now

here is what it appears to do the first move which is actually in varlos script goes o correct position

in ingridmove2, the move to location does happen right then although the callback is made
in ingridmove 3 the movetolocation moves but to the location in ingridmove2 and callback is made to ingrid move4, (and the spawn appears to warp
in ingridmove4 the move location move but to the loacation that was in 3 and stops

it looks like although the first move(in varlos script worked the second one didnt actually move(but the location was correct in spawn details even though spawn was in wrong location

so when i did spawn details /loc showed 1.80, 1.21, -13.71, but the spawn was actually still sitting on -2.07, 1.21, -14.71


Code: Select all

function ingridmove2(NPC)
	Say(NPC, "ingridmove2")

	local test = GetSpawn(NPC, 270008)
	if test ~= nil then
		Say(test, "BAR")
	end

	local player = GetTempVariable(NPC, "PlayerPointer")
	if player ~= nil then
	--	PerformCameraShake(player,52429,15948)
	end
	MoveToLocation(NPC, -2.07, 1.21, -14.71, 3, "ingridmove3")
	



end
function ingridmove3(NPC)

	MoveToLocation(NPC, 1.80, 1.21, -13.71, 3, "ingridmove4")

end

function ingridmove4(NPC)

	MoveToLocation(NPC, 1.80, 1.21, -13.71, 3)

end

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests