ArcEmu: [lua] Learn Skills On Character Creation (well Explained) - ArcEmu

Jump to content

Toggle shoutbox Lastest Announcements

dfighter  : (07 December 2014 - 12:06 PM) Arcemu is in hibernation mode, please read http://arcemu.org/fo...showtopic=26903
dfighter  : (01 January 2013 - 05:56 PM) Arcemu wishes you all a happy new year!
Hasbro  : (12 September 2012 - 10:01 AM) Please excuse our outage from the web! Our web host had a major malfunction!
dfighter  : (01 September 2012 - 04:05 PM) Since the spam bots just don't want to stop, I've enabled admin verification when registering.
dfighter  : (23 January 2012 - 09:56 PM) Please note that from now on you will need to confirm your email on the wiki in order to edit it!
Hasbro  : (31 December 2011 - 12:50 PM) Happy New Years all!
Navid  : (26 December 2011 - 04:09 AM) Merry Christmas !!!!!! Happy holidays all :)
WAmadeus  : (24 December 2011 - 03:54 PM) Merry Christmas to all!
dfighter  : (24 December 2011 - 11:05 AM) The Arcemu team wishes y'all a Merry Christmukkah!
Hasbro  : (05 October 2011 - 12:53 PM) Looking for web designers for upcoming web related project. If you're interested in designing user interfaces contact me
dfighter  : (02 September 2011 - 03:47 PM) So who here wants vehicles in Arcemu? :P http://arcemu.org/fo...showtopic=25440
Hasbro  : (14 August 2011 - 03:25 PM) Join us on irc, grab an irc client and connect to irc.freenode.net join channel #arcemu /server irc.freenode.net:6667 /join #arcemu
jackpoz  : (03 August 2011 - 05:33 AM) to all Lua Engine (old one) users: please check http://arcemu.org/fo...showtopic=25274
Hasbro  : (20 May 2011 - 05:27 PM) Looking for people experienced with CMake configuration and setup! Contact me asap
Hasbro  : (15 May 2011 - 05:03 PM) ArcEmu is recruiting C++ programmers, contact Hasbro if interested.
paroxysm  : (03 May 2011 - 06:26 PM) Updated luabridge gossip example to describe the whole gossip creation process rather than just how to create menu. Gossip tutorial
paroxysm  : (23 April 2011 - 11:35 AM) Lua writers can refer to the Luabridge Tutorials section in the Wiki to learn how to write gossip code correctly.
Hasbro  : (20 April 2011 - 05:22 PM) Thank you for your continuous contribution of bug reports, we are working on them.
Hasbro  : (17 April 2011 - 03:20 AM) Please consider donating to support our bills. Donations can be sent using PayPal to donations@arcemu.org - Thank you for your support.
paroxysm  : (10 April 2011 - 12:43 AM) Refer to the Luabridge Tutorials section in the Wiki to learn the new syntax of luabridge.
Resize Shouts Area

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

[lua] Learn Skills On Character Creation (well Explained) You don't need fancy NPC's anymore!

#1 User is offline   YuckFou 

  • Member
  • Pip
  • Group: Members
  • Posts: 13
  • Joined: 01-October 12
  • Gender:Male
  • Location:The Netherlands.
  • Server OS:Windows

Posted 02 October 2012 - 02:31 PM

In this tutorial I will be covering a full guide on how to create and implement a script that will automatically learn desired skills on a character creation.
In this tutorial I will assume you already have some experience with LuA. If that is not the case I recommend you start looking into a more basic tutorial for LuA first.
The text editor that I will be using for this tutorial is: Notepad ++

Heads up, all the way! (content)
1. Setting up & preparing
2. The beginning, creating the function
3. Checking for the user's chosen class
4. Advancing all desired skills
5. Server hooking the script
6. Easy test to see if it works

1. Setting up & preparing
Before we actually starting with the script creation we need ourselves ready and set up.
First of all you want to go to your 'ArcEmu' folder, inside there navigate to your 'scripts' folder.

  • If you don't have the folder you can create a new one and name it 'scripts'.

Open up Notepad ++ or any text editor you would like to use.

  • If Notepad ++ is used, navigate to: Language -> L -> Lua

OPTIONAL: Using a short-cut, hit Ctrl + Alt + S (File -> Save as...) and save your file. You may give it any name you want. Be sure that you don't forget the .lua extension !
Now we are done preparing, grab a drink and let's move on!

2. The beginning, creating the function
Before we do anything we have to create a function.
Put this in your code file:
function OnFirstEnterWorld(event, player)
end

As you might already see this function will tell to do something OnFirstEnterWorld (when the character enters the world for the first time).
We close the function using end
Congratulations! You have already completed the most easy part of this tutorial!
Now you may grab a snack and move on! You've earned it!

3. Checking for the user's chosen class
Inside the function we've made we must check what class the user had chosen.
To do this we will use an if statement.
What will this do? In fact, it's rather easy:
IF the user chose a Warrior, do this:
IF the user chose a Paladin, do this:
And so forth.
So how will this if statement actually look like?
Trust me, once you see the code you will be like: "aah, like that .... "
if(player:GetPlayerClass() == "Warrior") then

Looks like something new kicked in!
player:GetPlayerClass()
What does this sort of 'command' do? This command is the 'actual' command checking what class the user chose.
Now not only functions are required to be closed with end:
if statements also have to be close with an end.
So how will this look like at the end?
if(player:GetPlayerClass() == "Warrior") then
-- what to do
end


Now we ofcourse want this to be done for every class. Now trust me on this, you may copy this bunch of text so you don't have to write it:
if(player:GetPlayerClass() == "Warrior") then
-- what to do
elseif(player:GetPlayerClass() == "Paladin") then
-- what to do
elseif(player:GetPlayerClass() == "Hunter") then
-- what to do
elseif(player:GetPlayerClass() == "Rogue") then
--what to do
elseif(player:GetPlayerClass() == "Priest") then
-- what to do
elseif(player:GetPlayerClass() == "Death Knight") then
-- what to do
elseif(player:GetPlayerClass() == "Shaman") then
--what to do
elseif(player:GetPlayerClass() == "Mage") then
-- what to do
elseif(player:GetPlayerClass() == "Warlock") then
-- what to do
elseif(player:GetPlayerClass() == "Druid") then
-- what to do
end

Don't forget to add this after the function we have made before!

Again something new kicked in!
This time we used elseif instead of if.
Why do you ask?
If we would keep using if we would also have to keep closing it with end.
It is not practical.
Also there is a very nice logic behind using elseif, it looks similar to this: (just like before)
IF the user chose a Warrior, do this: ... BUT ....
ELSEIF the user did not chose a Warrior but chose a Paladin, do this:
It's like asking a question:

Quote

"Did you go (representing if) to school today, if not (representing: elseif): why didn't you go to school?"

If you can understand this logic then LuA will be a bunch easier!

Congratulations! You may now grab a drink and a snack! Let's move on!


4. Advancing all desired skills
To be able to advance all the desired skills you want we will have to use a Unit Command for it.
This unit command is in this case:
player:AddSkill(skill-id, min-value, max-value)
Let's throw this out for a bit:
We know ofcourse that player will in this case represent the character. So what does player actually say to the server:
Do something with the player (character).
:AddSkill(skill-id, min-value, max-value) is the actual part where is happens.
What do we do with the player (character)? Add a skill (AddSkill) with the id of ... (skill-id), using a minimum-value of ... (min-value) and using a maximum-value of ... min-value.

What is the skill-id for?
Every skill has it's own unique ID.
For example: 2H-Swords has an skill-id of 55.
Daggers has an skill-id of 173.
So by saying the skill-id the server will know what skill you want to be learned.

The min-value and max-value must be clear.
Every skill can be leveled up to 400.
If you for example wish to learn 200 of the 400 you will use a min-value of 200 and a (max-value) of 400.

Now your question might be: "How will I know all those ID's?"
Very simply, I have sorted them out for this tutorial:
SWORDS 43
AXES 44
BOWS 45
GUNS 46
MACES 54
2H_SWORDS 55
DEFENSE 95
STAVES 136
2H_MACES 160
UNARMED 162
2H_AXES 172
DAGGERS 173
THROWN 176
CROSSBOWS 226
SPEARS 227
WANDS 228
POLEARMS 229
FIST_WEAPONS 473
------------
MAIL 413
SHIELD 433
PLATE 293
LEATHER 414
CLOTH 415
------------
RIDING 762


So you could simply take the id's from my little list!

So how will we be making a functional unit command?
For example:
player:AddSkill(43, 400, 400)
This will learn the character the skill for Swords with the (max) level of 400.

Here is a list of what classes should (be able to) equip: (this list is in-complete)
----------------
WARRIOR:
----------------
Axes
Defense
Maces
Swords
Two-Handed Swords
Unarmed
----------------
PALADIN:
----------------
Defense
Maces
Two-Handed Maces
Unarmed
Polearms
Swords
Two-Handed Swords
----------------
HUNTER:
----------------
Bows
Daggers
Defense
Two-Handed Axes
Unarmed
Fist Weapons
Thrown
----------------
ROGUE:
----------------
Daggers
Defense
Thrown
Unarmed
Swords
----------------
PRIEST:
----------------
Defense
Maces
Staves
Unarmed
Wands
Daggers
----------------
DEATH KNIGHT:
----------------
Axes
Defense
Polearms
Swords
Two-Handed Axes
Two-Handed Swords
Unarmed
----------------
SHAMAN:
----------------
Defense
Maces
Staves
Unarmed
Daggers
Two-Handed Maces
----------------
MAGE:
----------------
Defense
Staves
Unarmed
Wands
Daggers
Swords
----------------
WARLOCK:
----------------
Daggers
Defense
Staves
Unarmed
Wands
Swords
----------------
DRUID:
----------------
Daggers
Defense
Staves
Unarmed
Fist Weapons


So we will need to add a :AddSkill(skill-id, min-value, max-value) for each skill on each class.
It will be big, but I have done it myself so you can copy it (it's according to the list)
So this is the code that we will need to add: (you may copy if you're lazy.... or smart ! :D)
if(player:GetPlayerClass() == "Warrior") then
player:AddSkill(44, 400, 400) -- Axes Level 400
player:AddSkill(95, 400, 400) -- Defense Level 400
player:AddSkill(54, 400, 400) -- Maces Level 400
player:AddSkill(43, 400, 400) -- Swords Level 400
player:AddSkill(55, 400, 400) -- 2H Swords Level 400
player:AddSkill(162, 400, 400) -- Unarmed Level 400
elseif(player:GetPlayerClass() == "Paladin") then
player:AddSkill(95, 400, 400) -- Defense Level 400
player:AddSkill(54, 400, 400) -- Maces Level 400
player:AddSkill(160, 400, 400) -- 2H Maces Level 400
player:AddSkill(162, 400, 400) -- Unarmed Level 400
player:AddSkill(229, 400, 400) -- Polearms Level 400
player:AddSkill(43, 400, 400) -- Swords Level 400
player:AddSkill(55, 400, 400) -- 2H Swords Level 400
elseif(player:GetPlayerClass() == "Hunter") then
player:AddSkill(45, 400, 400) -- Bows Level 400
player:AddSkill(95, 400, 400) -- Defense Level 400
player:AddSkill(173, 400, 400) -- Daggers Level 400
player:AddSkill(172, 400, 400) -- 2H Axes Level 400
player:AddSkill(162, 400, 400) -- Unarmed Level 400
player:AddSkill(473, 400, 400) -- Fist Weapons Level 400
player:AddSkill(175, 400, 400) -- Thrown Level 400
elseif(player:GetPlayerClass() == "Rogue") then
player:AddSkill(173, 400, 400) -- Daggers Level 400
player:AddSkill(95, 400, 400) -- Defense Level 400
player:AddSkill(175, 400, 400) -- Thrown Level 400
player:AddSkill(162, 400, 400) -- Unarmed Level 400
player:AddSkill(43, 400, 400) -- Swords Level 400
elseif(player:GetPlayerClass() == "Priest") then
player:AddSkill(95, 400, 400) -- Defense Level 400
player:AddSkill(54, 400, 400) -- Maces Level 400
player:AddSkill(136, 400, 400) -- Staves Level 400
player:AddSkill(162, 400, 400) -- Unarmed Level 400
player:AddSkill(228, 400, 400) -- Wands Level 400
player:AddSkill(173, 400, 400) -- Daggers Level 400
elseif(player:GetPlayerClass() == "Death Knight") then
player:AddSkill(44, 400, 400) -- Axes Level 400
player:AddSkill(95, 400, 400) -- Defense Level 400
player:AddSkill(229, 400, 400) -- Polearms Level 400
player:AddSkill(43, 400, 400) -- Swords Level 400
player:AddSkill(172, 400, 400) -- 2H Axes Level 400
player:AddSkill(55, 400, 400) -- 2H Swords Level 400
player:AddSkill(162, 400, 400) -- Unarmed Level 400
elseif(player:GetPlayerClass() == "Shaman") then
player:AddSkill(95, 400, 400) -- Defense Level 400
player:AddSkill(54, 400, 400) -- Maces Level 400
player:AddSkill(136, 400, 400) -- Staves Level 400
player:AddSkill(162, 400, 400) -- Unarmed Level 400
player:AddSkill(173, 400, 400) -- Daggers Level 400
player:AddSkill(160, 400, 400) -- 2H Maces Level 400
elseif(player:GetPlayerClass() == "Mage") then
player:AddSkill(95, 400, 400) -- Defense Level 400
player:AddSkill(136, 400, 400) -- Staves Level 400
player:AddSkill(162, 400, 400) -- Unarmed Level 400
player:AddSkill(228, 400, 400) -- Wands Level 400
player:AddSkill(173, 400, 400) -- Daggers Level 400
player:AddSkill(43, 400, 400) -- Swords Level 400
elseif(player:GetPlayerClass() == "Warlock") then
player:AddSkill(173, 400, 400) -- Daggers Level 400
player:AddSkill(95, 400, 400) -- Defense Level 400
player:AddSkill(136, 400, 400) -- Staves Level 400
player:AddSkill(162, 400, 400) -- Unarmed Level 400
player:AddSkill(228, 400, 400) -- Wands Level 400
player:AddSkill(43, 400, 400) -- Swords Level 400
elseif(player:GetPlayerClass() == "Druid") then
player:AddSkill(173, 400, 400) -- Daggers Level 400
player:AddSkill(95, 400, 400) -- Defense Level 400
player:AddSkill(136, 400, 400) -- Staves Level 400
player:AddSkill(162, 400, 400) -- Unarmed Level 400
player:AddSkill(473, 400, 400) -- Fist Weapons Level 400
end


Don't forget that level 400 is for a level 80 character!


5. Server hooking the script
I am not going to explain this part in this tutorial.

You will need to hook the script on the server (easaly explained).
How? Simply add this to the very bottom of your code file:
RegisterServerHook(3, "OnFirstEnterWorld")



6. Easy test to see if it works
To see if your code works you could add a print into your file.
To do this add a new line before
RegisterServerHook(3, "OnFirstEnterWorld")
.
Add this to the line before:
print("------------------2#$@#$%@$#@## ----------- CODE WORKS!!! ----------- 2#$@#$%@$#@## ------------------")
Save your file.

Start your 'world.exe'
Once it is finished loading you might have to scroll up a bit.
Look for the line to be printed in the console, if it shown you will be sure the script had loaded successfully!

Spoiler


Quote

Thank you for doing this tutorial.
If you have anything to say just post it down below!

Sincerely,
-YuckFou

0

#2 User is offline   regonaros 

  • Member
  • Pip
  • Group: Members
  • Posts: 24
  • Joined: 13-August 12
  • Gender:Male
  • Server OS:Windows

Posted 13 December 2012 - 02:18 PM

thanks yuckfou, what do I save the file as? and where abouts? in ArcEmu > scripts or ArceEmu > Scripts?
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users