Scripting Development

EQ2Emulator Development forum.

Moderator: Team Members

LethalEncounter
Team: Zombie
Posts: 2717
Joined: Wed Jul 25, 2007 10:10 pm

Scripting Development

Post by LethalEncounter » Mon Mar 24, 2008 12:22 pm

When I get back from my vacation (probably next week) I will start working on the LUA/C++ interface. I also plan on converting the spell system to use lua scripts instead of the database as using scripts will be much easier to use and modify. Each spell will consist of a different lua script file which is executed when the spell is triggered. Combat, spells, and scripting will be completed before 0.6 is released. Once that is done people will be able to play the game with at least some functionality. This will be followed closely with loot, merchants, groups, banks and lastly tradeskills.

User avatar
alfa
Team Member
Posts: 550
Joined: Fri Jul 27, 2007 6:24 pm
Location: France
Contact:

Post by alfa » Mon Mar 24, 2008 3:07 pm

Great news :)
Fight with me... Or die, like the rest.
J.A. say: "I think Xinux tried to tell me this, but I ignore most things he suggests."

User avatar
Arremis
Retired
Posts: 388
Joined: Sun Sep 02, 2007 10:11 am
Location: Memphis, TN

Post by Arremis » Tue Mar 25, 2008 3:15 am

WOOT :D

User avatar
ZexisStryfe
Posts: 1026
Joined: Thu Jul 26, 2007 6:39 am
EQ2Emu Server: Sytherian Legends
Location: Connecticut
Contact:

Post by ZexisStryfe » Tue Mar 25, 2008 5:57 am

LE, you are my hero :sniff sniff:
Just a side note, where do AAs fit in on that schedule?
~ EQ2 Emulator Project Manager

Image
Image
Image
"Zexis, from this day forth, you shall be known as... '3 of 6'" - John Adams

LethalEncounter
Team: Zombie
Posts: 2717
Joined: Wed Jul 25, 2007 10:10 pm

Post by LethalEncounter » Tue Mar 25, 2008 2:35 pm

dunno above AAs, I might implement them in between along with something else.

LethalEncounter
Team: Zombie
Posts: 2717
Joined: Wed Jul 25, 2007 10:10 pm

Post by LethalEncounter » Sun Mar 30, 2008 3:56 pm

OK, I have gotten Sprint to work correctly in LUA using an interface I wrote. I'm not really happy with the design at this point mainly from an inheritance standpoint. My code automatically looks in the Spells directory for any *.lua scripts and loads them. Here is the Sprint script:

Code: Select all

--Defines
spell_tier = 1
min_num_calls = 20
max_num_calls = 20
call_frequency = 3000
interruptable = false
speed_value = 40
power_req = .10
--main process function
function process1(Caster, Target)
	power_left = GetPower(Caster)
	total_power = GetMaxPower(Caster)
	if (total_power * power_req) < power_left then
		speed = GetSpeed(Caster)
		if speed < speed_value then
			SetSpeed(Caster, speed_value)
		end
		new_power =  GetPower(Caster) - (total_power * power_req)
		if new_power > 0 and HasMoved(Caster) == true then
			SetPower(Caster, new_power)
		elseif new_power <= 0 then
			SetSpeed(Caster, 0)
		end
	else
		SetSpeed(Caster, 0)
	end
	return
end
function remove1(Caster, Target)
	SetSpeed(Caster, 0)
end
This works well. The problem comes into play when I want to have one spell inherit from another. This would be really useful so that we can just change a few values instead of copying all the code for spell upgrades. Like if there was an upgrade to Sprint, if it was properly setup I could just change the speed_value/power_req variables and call the same function for the new spell. I could change the global values to accomplish this, but I would rather have a better solution that that. Anyone have a clue how to do this in LUA? I just started playing with it yesterday so I am definitely not good at it :P

User avatar
alfa
Team Member
Posts: 550
Joined: Fri Jul 27, 2007 6:24 pm
Location: France
Contact:

Post by alfa » Sun Mar 30, 2008 5:42 pm

First good work for your script engine.
And can you just store some spell value in DB ?
I mean keep spell struct with LUA and increment some value like "speed_value" (for example) with a table in DB.
Fight with me... Or die, like the rest.
J.A. say: "I think Xinux tried to tell me this, but I ignore most things he suggests."

LethalEncounter
Team: Zombie
Posts: 2717
Joined: Wed Jul 25, 2007 10:10 pm

Post by LethalEncounter » Mon Mar 31, 2008 3:00 pm

Yah, the spells are definitely going to be a combination of DB work and LUA scripts. Andrew came up with an idea last night that I will be implementing tonight. Basically he suggested that we put the script name in the spells table along with any parameters for that script so that instead of 500-600 spells (most with tiers of 1-9) we can greatly reduce the number of LUA scripts needed. Most spells are pretty common in their effects. I am going to go through the spell tables and clean them up tonight as well.

LethalEncounter
Team: Zombie
Posts: 2717
Joined: Wed Jul 25, 2007 10:10 pm

Post by LethalEncounter » Mon Mar 31, 2008 7:19 pm

OK, I finished creating the system that Andrew thought about. I got rid of 3 spell tables in the process and it is far more flexible than it used to be! I created a new command called /reloadspells that will reload them so that you can update spells and use them immediately in game. Having the spell variables in the DB makes it easy to modify your spells, just update your db, reload your spells and it is done. The new Sprint.lua script:

Code: Select all

function process(Caster, Target, PowerCost, SpeedValue)
	power_left = GetPower(Caster)
	total_power = GetMaxPower(Caster)
	if (total_power * PowerCost) < power_left then
		speed = GetSpeed(Caster)
		if speed < SpeedValue then
			SetSpeed(Caster, SpeedValue)
		end
		new_power =  GetPower(Caster) - (total_power * PowerCost)
		if new_power > 0 and HasMoved(Caster) == true then
			SetPower(Caster, new_power)
		elseif new_power <= 0 then
			SetSpeed(Caster, 0)
		end
	else
		SetSpeed(Caster, 0)
	end
	return
end
function remove(Caster, Target)
	SetSpeed(Caster, 0)
end
When creating spells, the first two parameters will allows be Caster and Target, the rest are values from your spell_data table. The process function is called when a spell is called (not necessarily when cast, as in this case process is called every 3 seconds as based on the spell requirement) and remove is called when the spell duration is completed or the spell is removed (player clickable removing not working yet). Notice that the global defines are no longer needed since we are passing in the data from the DB at run time.
Any other ideas that people want to suggest in regards to the new scripting engine?

User avatar
alfa
Team Member
Posts: 550
Joined: Fri Jul 27, 2007 6:24 pm
Location: France
Contact:

Post by alfa » Tue Apr 01, 2008 11:40 am

Yes another idea but not related to spell, just for scripting mob AI, have you plain to add a basical functions like check target life, check mob in group life, do an action,...
It would be allow a big part of community to make some AI / Raid / Instance script easly.
Fight with me... Or die, like the rest.
J.A. say: "I think Xinux tried to tell me this, but I ignore most things he suggests."

LethalEncounter
Team: Zombie
Posts: 2717
Joined: Wed Jul 25, 2007 10:10 pm

Post by LethalEncounter » Tue Apr 01, 2008 2:42 pm

You mean like do something similar with mobs by storing a script name in the NPCs table and calling it when they are attacked? If so, that could definitely be doable. Or were you talking about something differently?

User avatar
John Adams
Retired
Posts: 9684
Joined: Thu Jul 26, 2007 6:27 am
EQ2Emu Server: EQ2Emulator Test Center
Characters: John
Location: Arizona
Contact:

Post by John Adams » Tue Apr 01, 2008 4:05 pm

TessEQ2 is hooked to the 9102 update DB, got the table updates, and trying the Sprint button in my book. The client is saying "You cannot do that right now" and no sprinting. I do have the Spells folder under EQ2World.exe folder, with Sprint.lua inside.
I saw 1 LUA spell loaded at server startup as well.
Am I missing anything? Does the book button not work yet? Do I have to /cast or something?

LethalEncounter
Team: Zombie
Posts: 2717
Joined: Wed Jul 25, 2007 10:10 pm

Post by LethalEncounter » Tue Apr 01, 2008 4:06 pm

Drag it to your spell bar and try it there. It should work.

User avatar
John Adams
Retired
Posts: 9684
Joined: Thu Jul 26, 2007 6:27 am
EQ2Emu Server: EQ2Emulator Test Center
Characters: John
Location: Arizona
Contact:

Post by John Adams » Tue Apr 01, 2008 4:07 pm

Damn that was fast, lol... I didn't even get to refresh the screen to see if you were browsing this forum :D
I did that. No love, sorry. That's where I was getting the response in chat.

User avatar
alfa
Team Member
Posts: 550
Joined: Fri Jul 27, 2007 6:24 pm
Location: France
Contact:

Post by alfa » Tue Apr 01, 2008 4:08 pm

Yes, and also script some basic function for help people to make script.
Some example:
GetCurrentPower(Mob) //Get the current power of mob or player
GetCurrentLife(Mob) //Get the current life of mob or player
CastSpell(Spell_ID) //The mob cast the spell
DoEmote(Emote_ID) //The mob do an emote
CheckAgroOfTarget(Player) // Allow server/script engine to get what mob of group is currently target by player
...
I think it would be greate for make some AI script like (still for example) the gnolls group in Antonica, I mean:
In group (of mob) there is a gnoll Shaman, a gnoll Caster, and a gnoll Warrior
----------------
Example of script
Script for Shaman // When the Warrior is under 50% Shaman try to heal him

Code: Select all

If GetCurrentLife(Warrior) < (Total_Life / 2) then
   CastSpell(ID of an healling Spell)
End
Script for Warrior // When the player is targeting the healer the Warrior try to taunt him

Code: Select all

If CheckAgroOfTarget(Player) = "a gnoll Shaman" and GetCurrentLife(Shaman) < (Total_Life / 2) then
   CastSpell(ID of a taunting Spell)
End
Script for Caster // When the Shaman total power is under 50% the Caster try to feed him

Code: Select all

If GetCurrentPower(Shaman) < (Total_Power / 2) then
   CastSpell(ID of an feed mana Spell)
End
For sure the script in example are not working, and is incomplete (no mana check before try to cast a spell,...) but hope this can help you to understand what I mean when I talk about basic function
I think it would be a great thing to have some thing like that because it wouldn't be so hard to script some AI and the combat interaction would be better, for sure.
Fight with me... Or die, like the rest.
J.A. say: "I think Xinux tried to tell me this, but I ignore most things he suggests."

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests