Page 1 of 1

We need a tutorial on how to set up and NPC for scripts

Posted: Sun Sep 27, 2009 5:37 pm
by Astal
Ive been searching around and nothing says how to tie a script to a certain NPC, ive been trying to get an NPC to talk when I hail it forever now. If anyone could help me out id appreciate it.

Re: We need a tutorial on how to set up and NPC for scripts

Posted: Sun Sep 27, 2009 5:56 pm
by Scatman
Go to your spawn_scripts table. If you want a certain spawn to have a spawn script, enter a new row and fill in their spawn id into the spawn_id column. Next, enter in the location of your lua scripted you created into the lua_script column (C:\eq2emu\SpawnScripts\blahblah). Here's an example spawn script. I wasn't sure exactly what you needed help with since you didn't explain what your problem was in depth:

Code: Select all

function spawn(NPC)
	SetPlayerProximityFunction(NPC, 20, "InRange", "LeavingRange")
end

function InRange(NPC, Spawn)
	Say(NPC, "Hey, you've come within 20 meters of me!", Spawn)
end

function LeavingRange(NPC, Spawn)
	Say(NPC, "You're now outside my 20 meter radius of checking for spawns.", Spawn)
end

function respawn(NPC)
	spawn(NPC)
end

function hailed(NPC, Spawn)
	FaceTarget(NPC, Spawn)
	conversation = CreateConversation()
	
	AddConversationOption(conversation, "Just great thanks, and yourself?", "GreatThanks")
	AddConversationOption(conversation, "Grande.")
	StartConversation(conversation, NPC, Spawn, "Hey there " .. GetName(Spawn) .. ", how are ya doin' today?")
end

function hailed_busy(NPC, Spawn)
	Say(NPC, "You've hailed me while I'm busy like fighting.", Spawn)
end

function targeted(NPC, Spawn)
	Say(NPC, "You've targeted me.", Spawn)
end

function attacked(NPC, Spawn)
	Say(NPC, "You've attacked me.", Spawn)
end

function healthchanged(NPC, Spawn)
	Say(NPC, "My health has changed.", Spawn)
end

function aggro(NPC, Spawn)
	Say(NPC, "This is called when you first attack me.", Spawn)
end

function killed(NPC, Spawn)
	Say(NPC, "I've killed you!", Spawn)
end

function death(NPC, Spawn)
	Say(NPC, "You've killed me :(", Spawn)
end

function casted_on(NPC, Spawn, SpellName)
	Say(NPC, "You casted " .. SpellName .. " on me!", Spawn)
end

-----------------------------------------------------------------------------
--			functions to handle the extended conversations from hailed
-----------------------------------------------------------------------------

function GreatThanks(NPC, Spawn)
	FaceTarget(NPC, Spawn)
	conversation = CreateConversation()
	
	AddConversationOption(conversation, "Good to hear..")
	StartConversation(conversation, NPC, Spawn, "Wonderful!")
end

Re: We need a tutorial on how to set up and NPC for scripts

Posted: Sun Sep 27, 2009 6:27 pm
by Astal
thanks scat, thats exactly what i needed

Re: We need a tutorial on how to set up and NPC for scripts

Posted: Sun Sep 27, 2009 7:01 pm
by Astal
Did i Do this right?

F:\Eq 2 Emu\Config Files\SpawnScripts\Greeter.lua is in the lua script box then i have 1 for all the other boxes, because it is the only spawn on my server and its all set to one lol. Im still not getting anything. I have the NPC set up so it can be hailed also.

I guess u gotta restart the server each time you change a script or somthin, its workin now

Re: We need a tutorial on how to set up and NPC for scripts

Posted: Sun Sep 27, 2009 7:14 pm
by bolly
nope you can do a /reload spawnscripts and then follow it by /reload spawns :-)

Re: We need a tutorial on how to set up and NPC for scripts

Posted: Sun Sep 27, 2009 7:20 pm
by Scatman
Just a /reload spawnscripts will work if you are changing content of the script.

Re: We need a tutorial on how to set up and NPC for scripts

Posted: Sun Sep 27, 2009 7:45 pm
by Astal
ok, hey you know how to make item at all? Checked the wiki, but it is severely lacking in info lol.

Re: We need a tutorial on how to set up and NPC for scripts

Posted: Sun Sep 27, 2009 7:51 pm
by bolly
http://www.eq2emulator.net/wiki/index.p ... ns:Content

Put together a little page on the wiki to get new peeps started

Re: We need a tutorial on how to set up and NPC for scripts

Posted: Sun Sep 27, 2009 7:53 pm
by Astal
bolly wrote:http://www.eq2emulator.net/wiki/index.p ... ns:Content

Put together a little page on the wiki to get new peeps started
yeah, i wish i knew more about items id add to the wiki on em. I got a lot of learning to do.

Re: We need a tutorial on how to set up and NPC for scripts

Posted: Sun Sep 27, 2009 8:01 pm
by bolly
Astal wrote:ok, hey you know how to make item at all? Checked the wiki, but it is severely lacking in info lol.
Yeah i had the same problem so I looked at the databases, searched around the forums and then started filling in the wiki to help others, help me!! check out the items table and it's children ie item_appearance and what not. Fill in as appropriate - trial and error then update the wiki

Also worth checking out the source code whenever you get stuck (good ol' grep/findinfiles)

Here's a sample item (backpack):

Code: Select all

insert into items (name, item_type,icon,weight,description,sell_price,lua_script) values ('Basic Backpack','Bag', 10,5,'A 4 slot bag with 5 perc reduction',10,'');
then find the ID for the one you just inserted

Code: Select all

select id,name from items where name like '%Basic Backpack%';
We'll say it was ID 1 for this example

Then insert it's bag details into the item_defails_bag table

Code: Select all

insert into item_details_bag (item_id,num_slots,weight_reduction) values (1,4,5); 
Now reload your items in game /reload items

Search for it with /item

There's lots of other tables for different types of items, look at item_details_weapon etc :-)

Re: We need a tutorial on how to set up and NPC for scripts

Posted: Sun Sep 27, 2009 8:02 pm
by Astal
will do, im gonna load up the release pack along side and check out the items on there and see what I can learn, i will be sure to fill out the wiki when i learn things.

Re: We need a tutorial on how to set up and NPC for scripts

Posted: Sun Sep 27, 2009 8:09 pm
by bolly
awesome, that pack is pretty sweet - check out the spawnscripts and quests folder but note the version i downloaded was a different database schema to the current version on svn

good luck bro!

Re: We need a tutorial on how to set up and NPC for scripts

Posted: Sun Sep 27, 2009 8:20 pm
by Astal
bolly wrote:awesome, that pack is pretty sweet - check out the spawnscripts and quests folder but note the version i downloaded was a different database schema to the current version on svn

good luck bro!
yeah i noticed that too so you cant directly import it, you would have to type it all out manually.

I noticed a guy was working on an item editor, hopefully he will include item icons and possibly a model viewer in it, that would be awesome