habiba
New Member
ALL CREDITS TO ZERIIKLER
Welcome to the tutorial on Creating Actions.
Well, lets get going..
Every server has many functions to make your server do different things.
These functions include,
All of those do different things, although their names pretty much explain themselves its nice to know how to use them
Here's a list of all the LUA Functions.
(Functions from TheForgottenServer)
Now making a script consists of using these.
Just about, everything can be done in LUA.
There are also, created functions here, that people make for other people to use.
But lets just stick with the ones posted above.
To create a script(depending on what your making, "talkaction", "action", "movement" etc.) you can start with these.
For Action Scripts
For Movement Scripts
For Talk Action Scripts
Or Creature Scripts.
But heres how Creature Scripts vary.
There can be a couple, depending on which distro you're using.
Etc..
Now lets get started with making a nice basic script.
Part One: Actions
Actions are very common. They are used for a lot of different things.
Example: Eating Food, Doors, Shovels, Quests.. Etc.
So lets start our script off with this.
Okay so we want our script to do something right?
So lets say we want someone to use a scroll, and maybe gain exp, or say something.
Or gain exp, and say something at the same time
So lets look at our functions.
We have..
And
But what item are we going to use to give exp and make us say something?
Lets use
Poem Scroll ^_^
ID: 6119
So now we know the functions and item we want to use, so lets make the script!
Now let me explain..
So now first, in this script, we're telling the server if the item's ID = 6119(poem scroll) then its going to add 300 exp, and the player will say "YAY! EXP!.
Now return 1 means, that its going to return no errors, like if that wasn't there, you would receive a cancel message in-game saying You cannot use this object.
But, the script will still work.
You can ether have return TRUE, which is the same as return 1.
return 0 means false. so return FALSE would be the same as return 0.
There are ways to make the script easier to config like this.
Which might be easier to do with new LUA learners so you can easily configure your script better
Now we have also in the script "doCreatureSay(cid, words, 3)"
"3" means, the way the player will say YAY! EXP!.
Here's the different ways you can say it.
This can be found in your Global.LUA
Now maybe you want the item to remove after you use it :huh:
Well you can add the function, doRemoveItem.
Let me show you how it would work.
Okie, so now we have "doRemoveItem(cid, item.uid, 1)" in there. That will indeed remove the item after you use it. If you want to know, what the "1" means, well it means how many is it going to remove. In our case we put 1. If you put two and the player had two scrolls, it wouldn't remove two. Only one. This works for other items, that stack.
So lets get into the script a little more.
Maybe you want only a specific vocation using this scroll, or only players above or below a level. Lets add that
Okej, So lets look though our functions.
Ahhh yes, "getPlayerVocation"
So lets put that in the script xD
So now we are telling the server if the item's ID is = to 6119, AND the players vocation is (1 or 5)
Sorcerer & Master Sorcerer
Ok so maybe we want the script to say something if your not a Sorcerer or a Master Sorcerer. So we add another function.
"doPlayerSendCancel"
Here's what it shall look like.
Now i added
else means if the player doesn't have the script requirements then its going to do something else. Like send them a cancel saying their not of vocation. If you didnt have something "else" then it just wouldn't do anything.
Ok so now we added the getPlayerVocation. Lets add a level requirement..
Again, looking though functions, and yes!
"getPlayerLevel"
So lets add it xD
Okie, so we added,
and also
Now, Let me explain this.
We are now telling the server to get the players level.
and ">=" means greater or equal to
Just like math right?
Yup
Heres how they go with explaining,
">" Means just greater than
"<" Means just less than
"==" Means equal to
">=" Means greater than or equal to
"<=" Means less than or equal to
"~=" Means not equal to
Ok, so now lets talk about how you end your scripts.
Every script will be ended with "end"
There might be more than two ends, depending on how your script is.
an easy way to see when your script ends is by using NotePad++
You can download it from this link.
>>DOWNLOAD<<
On the left side of it, you'll see where your script starts and where it should end.
I STRONGLY Recommend using this program when you script.
I Hope you understood everything i explained.
I will write Part 2: Movements
When i have more time.
Hope you guys liked.
Comments? :huh:
Welcome to the tutorial on Creating Actions.
Well, lets get going..
Every server has many functions to make your server do different things.
These functions include,
Code:
doTeleportThing(cid, newpos, <optional> pushmove)
doCreatureSay(cid, text, type)
doPlayerFeed(cid, food)
doPlayerAddMana(cid, mana)
All of those do different things, although their names pretty much explain themselves its nice to know how to use them
Here's a list of all the LUA Functions.
(Functions from TheForgottenServer)
Code:
setPlayerGroupId(cid, newGroupId)
playerLearnInstantSpell(cid, name)
canPlayerLearnInstantSpell(cid, name)
getPlayerLearnedInstantSpell(cid, name)
getPlayerInstantSpellCount(cid)
getPlayerInstantSpellInfo(cid, index)
getInstantSpellInfoByName(cid, name)
getInstantSpellWords(name)
setPlayerStorageValue(uid, valueid, newvalue)
getGlobalStorageValue(valueid)
setGlobalStorageValue(valueid, newvalue)
getTilePzInfo(pos)
getTileHouseInfo(pos)
getItemRWInfo(uid)
getThingfromPos(pos)
getThing(uid)
queryTileAddThing(uid, pos, <optional> flags)
getThingPos(uid)
doRemoveItem(uid, <optional> n)
doPlayerFeed(cid, food)
doPlayerSendDefaultCancel(cid, ReturnValue)
doTeleportThing(cid, newpos, <optional> pushmove)
doTransformItem(uid, toitemid, <optional> count/subtype)
doCreatureSay(cid, text, type)
doSendMagicEffect(pos, type)
doSendDistanceShoot(frompos, topos, type)
doChangeTypeItem(uid, newtype)
doSetItemActionId(uid, actionid)
doSetItemText(uid, text)
doSetItemSpecialDescription(uid, desc)
doSendAnimatedText(pos, text, color)
doPlayerAddSkillTry(cid, skillid, n)
doCreatureAddHealth(cid, health)
doPlayerAddMana(cid, mana)
doPlayerAddManaSpent(cid, mana)
doPlayerAddSoul(cid, soul)
doPlayerAddItem(uid, itemid, <optional> count/subtype)
doPlayerAddItemEx(cid, uid, <optional: default: 0> useCidPosOnFail)
doPlayerSendTextMessage(cid, MessageClasses, message)
doPlayerRemoveMoney(cid, money)
doShowTextDialog(cid, itemid, text)
doDecayItem(uid)
doCreateItem(itemid, type/count, pos)
doCreateItemEx(itemid, <optional> count/subtype)
doTileAddItemEx(pos, uid)
doCreateTeleport(itemid, topos, createpos)
doSummonCreature(name, pos)
doConvinceCreature(cid, target)
doRemoveCreature(cid)
doMoveCreature(cid, direction)
doPlayerSetTown(cid, townid)
doPlayerSetVocation(cid,voc)
doPlayerRemoveItem(cid,itemid,count)
doPlayerAddExp(cid,exp)
doPlayerSetGuildId(cid, id)
doPlayerSetGuildRank(cid, rank)
doPlayerSetGuildNick(cid, nick)
doPlayerAddOutfit(cid,looktype,addons)
doPlayerRemOutfit(cid,looktype,addons)
doSetCreatureLight(cid, lightLevel, lightColor, time)
doSetCreatureDropLoot(cid, doDrop)
getCreatureCondition(cid, condition)
isPlayer(cid)
isCreature(cid)
isContainer(uid)
isMoveable(uid)
getPlayerByName(name)
getPlayerGUIDByName(name)
registerCreatureEvent(uid, eventName)
getContainerSize(uid)
getContainerCap(uid)
getContainerItem(uid, slot)
doAddContainerItem(uid, itemid, <optional> count/subtype)
getHouseOwner(houseid)
getHouseName(houseid)
getHouseEntry(houseid)
getHouseRent(houseid)
getHouseTown(houseid)
getHouseAccessList(houseid, listid)
getHouseByPlayerGUID(playerGUID)
setHouseAccessList(houseid, listid, listtext)
setHouseOwner(houseid, ownerGUID)
getWorldType()
getWorldTime()
getWorldLight()
getWorldCreatures(type)
getWorldUpTime()
broadcastMessage(message, type)
getGuildId(guild_name)
getPlayerSex(cid)
doPlayerSetSex(cid, newSex)
createCombatArea( {area}, <optional> {extArea} )
createConditionObject(type)
setCombatArea(combat, area)
setCombatCondition(combat, condition)
setCombatParam(combat, key, value)
setConditionParam(condition, key, value)
addDamageCondition(condition, rounds, time, value)
addOutfitCondition(condition, lookTypeEx, lookType, lookHead, lookBody, lookLegs, lookFeet)
setCombatCallBack(combat, key, function_name)
setCombatFormula(combat, type, mina, minb, maxa, maxb)
setConditionFormula(combat, mina, minb, maxa, maxb)
doCombat(cid, combat, param)
createCombatObject()
doAreaCombatHealth(cid, type, pos, area, min, max, effect)
doTargetCombatHealth(cid, target, type, min, max, effect)
doAreaCombatMana(cid, pos, area, min, max, effect)
doTargetCombatMana(cid, target, min, max, effect)
doAreaCombatCondition(cid, pos, area, condition, effect)
doTargetCombatCondition(cid, target, condition, effect)
doAreaCombatDispel(cid, pos, area, type, effect)
doTargetCombatDispel(cid, target, type, effect)
doChallengeCreature(cid, target)
numberToVariant(number)
stringToVariant(string)
positionToVariant(pos)
targetPositionToVariant(pos)
variantToNumber(var)
variantToString(var)
variantToPosition(var)
doChangeSpeed(cid, delta)
doSetMonsterOutfit(cid, name, time)
doSetItemOutfit(cid, item, time)
doSetCreatureOutfit(cid, outfit, time)
getCreatureOutfit(cid)
getCreaturePosition(cid)
getCreatureName(cid)
getCreatureSpeed(cid)
getCreatureBaseSpeed(cid)
getCreatureTarget(cid)
isItemStackable(itemid)
isItemRune(itemid)
isItemDoor(itemid)
isItemContainer(itemid)
isItemFluidContainer(itemid)
getItemName(itemid)
getItemWeight(itemid, count)
debugPrint(text)
isInArray(array, value)
addEvent(callback, delay, parameter)
stopEvent(eventid)
doPlayerPopupFYI(cid, message)
mayNotLogout(cid, value)
mayNotMove(cid, value)
doPlayerAddPremiumDays(cid, days)
doPlayerRemovePremiumDays(cid, days)
getPlayerPremiumDays(cid)
getPlayerSkullType(cid)
getPromotedVocation(vocation)
getPlayerBlessing(cid, blessing)
doPlayerAddBlessing(cid, blessing)
saveData()
escapeString(str)
Now making a script consists of using these.
Just about, everything can be done in LUA.
There are also, created functions here, that people make for other people to use.
But lets just stick with the ones posted above.
To create a script(depending on what your making, "talkaction", "action", "movement" etc.) you can start with these.
For Action Scripts
Code:
function onUse(cid, item, frompos, item2, topos)
Code:
function onStepIn(cid, item, position, fromPosition)
Code:
function onSay(cid, words, param)
But heres how Creature Scripts vary.
There can be a couple, depending on which distro you're using.
Code:
function onLogin(cid)
function onKill(cid)
function onDeath(cid)
function onLogout(cid)
Now lets get started with making a nice basic script.
Part One: Actions
Actions are very common. They are used for a lot of different things.
Example: Eating Food, Doors, Shovels, Quests.. Etc.
So lets start our script off with this.
Code:
function onUse(cid, item, frompos, item2, topos)
Okay so we want our script to do something right?
So lets say we want someone to use a scroll, and maybe gain exp, or say something.
Or gain exp, and say something at the same time
So lets look at our functions.
We have..
Code:
doPlayerAddExp(cid,exp)
Code:
doCreatureSay(cid, text, type)
But what item are we going to use to give exp and make us say something?
Lets use
Poem Scroll ^_^
ID: 6119
So now we know the functions and item we want to use, so lets make the script!
Code:
function onUse(cid, item, frompos, item2, topos)
if item.itemid == 6119 then
doPlayerAddExp(cid, 300)
doCreatureSay(cid, "YAY! EXP!", 3)
end
return 1
end
Now let me explain..
So now first, in this script, we're telling the server if the item's ID = 6119(poem scroll) then its going to add 300 exp, and the player will say "YAY! EXP!.
Now return 1 means, that its going to return no errors, like if that wasn't there, you would receive a cancel message in-game saying You cannot use this object.
But, the script will still work.
You can ether have return TRUE, which is the same as return 1.
return 0 means false. so return FALSE would be the same as return 0.
There are ways to make the script easier to config like this.
Code:
local itemID = 6119 -- The ID of the item that will give you EXP
local xp = 300 --How much EXP will be givin when item is used
local words = "YAY! EXP!" --What the player will say when item is used
function onUse(cid, item, frompos, item2, topos)
if item.itemid == itemID then
doPlayerAddExp(cid, xp)
doCreatureSay(cid, words, 3)
end
return 1
end
Which might be easier to do with new LUA learners so you can easily configure your script better
Now we have also in the script "doCreatureSay(cid, words, 3)"
"3" means, the way the player will say YAY! EXP!.
Here's the different ways you can say it.
Code:
TALKTYPE_SAY = 1
TALKTYPE_WHISPER = 2
TALKTYPE_YELL = 3
TALKTYPE_PRIVATE_PN = 4
TALKTYPE_PRIVATE_NP = 5
TALKTYPE_PRIVATE = 6
TALKTYPE_CHANNEL_Y = 7
TALKTYPE_BROADCAST = 11
TALKTYPE_CHANNEL_R1 = 12
TALKTYPE_PRIVATE_RED = 13
TALKTYPE_CHANNEL_O = 14
TALKTYPE_CHANNEL_R2 = 16
TALKTYPE_ORANGE_1 = 18
TALKTYPE_ORANGE_2 = 19
This can be found in your Global.LUA
Now maybe you want the item to remove after you use it :huh:
Well you can add the function, doRemoveItem.
Let me show you how it would work.
Code:
local itemID = 6119 -- The ID of the item that will give you EXP
local xp = 300 --How much EXP will be givin when item is used
local words = "YAY! EXP!" --What the player will say when item is used
function onUse(cid, item, frompos, item2, topos)
if item.itemid == itemID then
doPlayerAddExp(cid, xp)
doCreatureSay(cid, words, 3)
doRemoveItem(cid, item.uid, 1)
end
return 1
end
Okie, so now we have "doRemoveItem(cid, item.uid, 1)" in there. That will indeed remove the item after you use it. If you want to know, what the "1" means, well it means how many is it going to remove. In our case we put 1. If you put two and the player had two scrolls, it wouldn't remove two. Only one. This works for other items, that stack.
So lets get into the script a little more.
Maybe you want only a specific vocation using this scroll, or only players above or below a level. Lets add that
Okej, So lets look though our functions.
Ahhh yes, "getPlayerVocation"
So lets put that in the script xD
Code:
local itemID = 6119 -- The ID of the item that will give you EXP
local xp = 300 --How much EXP will be givin when item is used
local words = "YAY! EXP!" --What the player will say when item is used
local vocs = 1, 5
function onUse(cid, item, frompos, item2, topos)
if item.itemid == itemID and getPlayerVocation(cid) == vocs then
doPlayerAddExp(cid, xp)
doCreatureSay(cid, words, 3)
doRemoveItem(cid, item.uid, 1)
end
return 1
end
So now we are telling the server if the item's ID is = to 6119, AND the players vocation is (1 or 5)
Sorcerer & Master Sorcerer
Ok so maybe we want the script to say something if your not a Sorcerer or a Master Sorcerer. So we add another function.
"doPlayerSendCancel"
Here's what it shall look like.
Code:
local itemID = 6119 -- The ID of the item that will give you EXP
local xp = 300 --How much EXP will be givin when item is used
local words = "YAY! EXP!" --What the player will say when item is used
local vocs = 1, 5
function onUse(cid, item, frompos, item2, topos)
if item.itemid == itemID and getPlayerVocation(cid) == vocs then
doPlayerAddExp(cid, xp)
doCreatureSay(cid, words, 3)
doRemoveItem(cid, item.uid, 1)
else
doPlayerSendCancel(cid, "Sorry, your not a Sorcerer or Master Sorcerer")
end
return 1
end
Now i added
Code:
else
doPlayerSendCancel(cid, "Sorry, your not a Sorcerer or Master Sorcerer")
else means if the player doesn't have the script requirements then its going to do something else. Like send them a cancel saying their not of vocation. If you didnt have something "else" then it just wouldn't do anything.
Ok so now we added the getPlayerVocation. Lets add a level requirement..
Again, looking though functions, and yes!
"getPlayerLevel"
So lets add it xD
Code:
local itemID = 6119 -- The ID of the item that will give you EXP
local xp = 300 --How much EXP will be givin when item is used
local words = "YAY! EXP!" --What the player will say when item is used
local vocs = 1, 5
local level = 20
function onUse(cid, item, frompos, item2, topos)
if item.itemid == itemID and getPlayerVocation(cid) == vocs and getPlayerLevel(cid) >= level then
doPlayerAddExp(cid, xp)
doCreatureSay(cid, words, 3)
doRemoveItem(cid, item.uid, 1)
else
doPlayerSendCancel(cid, "Sorry, your not a Sorcerer or Master Sorcerer And not level 20+")
end
return 1
end
Okie, so we added,
Code:
getPlayerLevel(cid) >= level
Code:
local level = 20
Now, Let me explain this.
We are now telling the server to get the players level.
and ">=" means greater or equal to
Just like math right?
Yup
Heres how they go with explaining,
Code:
>
<
==
>=
<=
~=
">" Means just greater than
"<" Means just less than
"==" Means equal to
">=" Means greater than or equal to
"<=" Means less than or equal to
"~=" Means not equal to
Ok, so now lets talk about how you end your scripts.
Every script will be ended with "end"
There might be more than two ends, depending on how your script is.
an easy way to see when your script ends is by using NotePad++
You can download it from this link.
>>DOWNLOAD<<
On the left side of it, you'll see where your script starts and where it should end.
I STRONGLY Recommend using this program when you script.
I Hope you understood everything i explained.
I will write Part 2: Movements
When i have more time.
Hope you guys liked.
Comments? :huh: