PerformCameraShake

EQ2Emulator Development forum.

Moderator: Team Members

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

PerformCameraShake

Post by Ememjr » Tue Oct 31, 2017 6:19 pm

so there is an PerformCameraShake opcode that wasnt setup in worldstruct, or in code anywhere, and i need it for some zone stuff i am working on,
anyway i test the shake manully with a /test command, and i could barely stay on the boat, so i wanted to add a lua function to use it in this fashin

Code: Select all

        PerformCameraShake(Spawn,52429,15948)
	PerformCameraShake(Spawn,52429,15820)
	PerformCameraShake(Spawn,52429,15820)
the first number should be the player( ofrom what i see its the only way the function in code and get your client) the other 2 numbers are the 2 int16s that the packet requires

i think i am missing something in the server console i see an error lua:51 attempt to call global 'PerformCaneraShake' ( a nil value)

I noticed it does not even make it to the lua code in the luafunctions.cpp when i put a breakpoint on if (!lua_interface)


here is my lua function

Code: Select all

int	EQ2Emu_lua_PerformCameraShake(lua_State* state){
	if (!lua_interface)
		return 0;
	Client* client = 0;
	Spawn* player = lua_interface->GetSpawn(state);
	if (player->GetZone())
		client = player->GetZone()->GetClientBySpawn(player);

	if (!client){
		lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
		return 0;
	}
	int16 value1 = lua_interface->GetInt16Value(state,1);
	int16 value2 = lua_interface->GetInt16Value(state,2);
	PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
	if (packet){
		packet->setDataByName("unknown1", value1);
		packet->setDataByName("unknown2", value2);
		client->QueuePacket(packet->serialize());
		safe_delete(packet);
	}
}

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

Re: PerformCameraShake

Post by Jabantiz » Tue Oct 31, 2017 6:31 pm

Did you register it? All functions need to be registered in luainterface.cpp in the function void LuaInterface::RegisterFunctions(lua_State* state)

Also there is an error when you grab value1 and value2, lua starts its index at 1, not 0 like c++, so this line

Code: Select all

Spawn* player = lua_interface->GetSpawn(state);
Defaults by pulling at index 1 so value1 should pull from index 2 and value2 should pull from index 3

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

Re: PerformCameraShake

Post by Ememjr » Tue Oct 31, 2017 6:34 pm

i just found that i didnt register it, , aw my mistake forgot to change it after i figured out that i needed to get the spawn, i originally was just going to pass the 2 values

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

Re: PerformCameraShake

Post by Ememjr » Wed Nov 01, 2017 7:05 am

so this function i created seems to work, but a question on lua fnctions in general
some of the lua functions use myfunctionname(NPC,Spawn,value,value)
some use (NPC, value,value)
and finally some use just (values)
i think i read about some being hardcoded, so should i put PerformCameraShake(NPC,Spawn,52429,15948) vs PerformCameraShake(Spawn,52429,15948)

also when setting a timer i when the timer expires and the pcs2 callback should go to function pcs2 correct, but i get an error saying the player cannot be found

i will find and post the exact location of the error(cannot seem to find it right now

Code: Select all

AddTimer(NPC,5000,"pcs2")
function pcs2(NPC, Spawn)
    PerformCameraShake(Spawn,52429,15820)
    AddTimer(NPC,5000,"pcs3")
end
function pcs3(NPC, Spawn)
    PerformCameraShake(Spawn,52429,15820)
end
for reference here is the entire script

Code: Select all

--[[
	Script Name	: SpawnScripts/Farseas/captainvarlos.lua
	Script Purpose	: Captain Varlos
	Script Author	: Ememjr
	Script Date		: 2017.10.30
	Script Notes	:
--]]



function targeted(NPC, Spawn)
	local conversation = CreateConversation()

	AddConversationOption(conversation, "Where am I?", "Option1")
	StartConversation(conversation, NPC, Spawn, "Ahoy! 'Tis good to see you awake. Ya seem a little squiffy, least ya' cheated death!","voiceover/english/captain_varlos/boat_06p_tutorial02/varlos_0_001.mp3",1930075150,2666442405)
end

function hailed(NPC, Spawn)
	--FaceTarget(NPC, Spawn)
	--local conversation = CreateConversation()

	--AddConversationOption(conversation, "Glad to be of assistance.  What can I do?", "Option3")
	--StartConversation(conversation, NPC, Spawn, "No, no! You've done plenty for me already ... But, lately my back has been hurting me terribly. Gracious! I'm complaining again! I hate to impose ... but you can do one more thing for me.")
end

function Option1(NPC, Spawn)
	FaceTarget(NPC, Spawn)
	local conversation = CreateConversation()
	AddConversationOption(conversation, "Who are you?", "Option2")
	StartConversation(conversation, NPC, Spawn, "Me apologies.","voiceover/english/captain_varlos/boat_06p_tutorial02/varlos_0_002.mp3",2054400186,1976167819)
end

function Option2(NPC, Spawn)
	FaceTarget(NPC, Spawn)
	local conversation = CreateConversation()
	AddConversationOption(conversation, "How did I get here?", "Option3")
	StartConversation(conversation, NPC, Spawn, "I am Captain Draik Varlos, and this 'ere fine ship is the Far Journey.","voiceover/english/captain_varlos/boat_06p_tutorial02/varlos_0_003.mp3",2565389482,560555759)
end

function Option3(NPC, Spawn)
	FaceTarget(NPC, Spawn)
	local conversation = CreateConversation()
	AddConversationOption(conversation, "Vaguely. Where are we headed?", "Option4")
	StartConversation(conversation, NPC, Spawn, "Me hearties pulled ya' from the sea, you an those other bilge rats. Do ya' remember?","voiceover/english/captain_varlos/boat_06p_tutorial02/varlos_0_004.mp3",29296168,2709023783)
end

function Option4(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)
	AddTimer(NPC,5000,"pcs2")
	MoveToLocation(270027, 1.7, 1.18, -11.51,1)


	--PlayFlavor(NPC,"voiceover/english/captain_varlos/boat_06p_tutorial02_fvo_006.mp3","Ingrid! Quit gawking at the shorty and fix that yard-arm!","",2753489262,3183736171,Spawn)
	--PlayFlavor(NPC,"voiceover/english/captain_varlos/boat_06p_tutorial02_fvo_007.mp3","Don't want the ship to come apart in these high winds, do ya'?!","",517097409,4194681002,Spawn)



	--local conversation = CreateConversation()
	--AddConversationOption(conversation, "See you soon.","Offerquest")
	--StartConversation(conversation, NPC, Spawn, "We are heading to the Island of Refuge.")
end
function pcs2(NPC, Spawn)
--PerformCameraShake(Spawn,52429,15820)
--AddTimer(NPC,5000,"pcs3")
end

function pcs3(NPC, Spawn)
PerformCameraShake(Spawn,52429,15820)

end

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

Re: PerformCameraShake

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

Yes with the callback set to "pcs2" it will call the lua function "function pcs2()". By default that call back function will only have 1 parameter and that is the spawn the timer was added to, in this case you use AddTimer(NPC, 5000, "pcs2") so that NPC pointer will be the only parameter the callback function receives, however you give the callback two parameters (second will always be null in this case) and you use the second for the camera shake so that is where the error is coming from.

Now you can fix this by just adding in the optional parameters for AddTimer() which will force a second spawn pointer to the callback function. First you need to add an int for how many times to run this timer then a spawn to pass to the callback so it should look like this

Code: Select all

AddTimer(NPC, 5000, "pcs2", 1, Spawn)
And the call back should now work as you expected it to.

AddTimer() - For reference

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests