I am in need for a script which gives the player a certain amount of exp when entering a specific tile on the map.
seems more like a request.
But since you posted it on support with no code i'm going to guide you.
In data folder there is folder called:
movements
open it. and you see
.xml file in it.
Open movements.xml
In here you will have to register your script.
now
open your map.
DoubleClick on the
tile you wanted to add this onStep feature.
Write a number you haven't used before in
Unique ID field.
remember this
Unique ID
Now
go back to the
movements.xml file we opened before.
Look for event what is similar to this:
event="onStepIn"
It may differ in every TFS version.
Copy paste the the
entire line and find a section in it what says:
itemid=
"number"
Change the variableName
itemid to
uniqueid
change the
"number" to
Unique Id you used for
tile (the unique ID I told you to remember)
It should look like this now:
uniqueid=
"Unique Id"
Now
find section on the same line what says:
script=
"some kind of string.lua"
remember the
"some kind of string.lua" name.
change the string to:
"ExplorationTile.lua".
this is going to be you file path. this means: in Script folder there is .lua file called ExplorationTile.
And that is what we are going to do next.
Close the
movements.xml file
(save ofc)
Now on the same folder where you opened
movements.xml file
navigate to
folder: Scripts
Now
remind yourself what was the
string name before.
If it had symbol
"/" in it, then it means the file you are looking for is inside
folder.
Find the path to the original file.
When you find it
Copy the file (don't open it).
Now
go back to the
folder: script (data/movements/scripts) and
Paste the file there.
rename the file name to
ExplorationTile (it should keep the .lua extension)
Open the file now.
Find the line what has similar start like this:
function onStepIn(paramaters)
Copy the line.
Select All.
Delete all the selected and
Paste the copied line.
You should now only have only 1 line in the code.
Lets start constructing script now:
(I use TFS 1.0, so code might start looking different, but you will get basic idea)
The first
parameter should be something like (
cid,
player,
creature)
(It holds is creature id)
You need to use
storage value to hold some
player specific number value.
Now leave this file be
(don't close) and
open the
SourceCode folder (this is not in data folder) (if you don't have it, open one in online documentation) [doublecheck the TFS version you are using and the sourcecode TFS you just opened]
Anyway
find a file called
luascript.cpp open it with notepad++ (or on online just click it)
push down CTRL+F and
search for keyword
storagevalue.
(one word)
in TFS 1.0 you find these lines.
Look for something similar
Code:
registerMethod("Player", "getStorageValue", LuaScriptInterface::luaPlayerGetStorageValue);
registerMethod("Player", "setStorageValue", LuaScriptInterface::luaPlayerSetStorageValue);
These are going to be your functions what you need.
now
open up your script again.
on the 2nd line write:
Code:
local player = Player(FIRST PARAMETER)
what does it do is: it will take the creature id and tries to get
player metaTable out of it.
on the 3rd line write:
Code:
if player:getStorageValue(number value) < 0 then
if you have something different instead of "getStorageValue" in the registerMethod you saw in source, use that instead of my example.
Anyway, what does it do is: It asks what number does
player MetaTable
storage(key for the value) hold. As for
number value use anything you haven't used on server before.
number between 1000-3million i think.
All the storageValues have default number -1.
on the 4th line write:
Code:
player:setStorageValue(number value, 1)
use the same
storagevalue number you used before. it will change the value inside the storage to 1. Now It can't be less than 0.
(hence the above if statement will be executed once)(unless you change with some other script)
Storagevalues are saved to database. So they will stay the same even after you close your server or player logs out.
once again if in the registermethod you have something different than "setStorageValue" use the one you have instead.
the number "1", behind the value you chose, means what is going to be the new number value instead of the default "-1".
Now we want to add that 1 time experience.
go back to
luascript.cpp file
press CTRL+F and
find for keyword
addexp
I found these in TFS 1.0
Code:
registerMethod("Player", "getExperience", LuaScriptInterface::luaPlayerGetExperience);
registerMethod("Player", "addExperience", LuaScriptInterface::luaPlayerAddExperience);
registerMethod("Player","removeExperience",LuaScriptInterface::luaPlayerRemoveExperience);
Once again if you use different
TFS they might be different.
What we need is
addExperience.
(might be called a little different for you, but should be something like add-...)
on the 5th line write:
Code:
player:addExperience(number amount of experience you want to add)
once again, if your registerMethod doesn't have
addExperience, use whatever add you have there.
on the 6th line write:
this will close the
if statement
on the 7th line write:
this will close the
function
Now save the file > Save the map >reload server. Try it out.
Post any errors you get here.
And we will help you.
After you get this working.
If you want I give you next guide
how to make this script even better.
And maybe you will let us know what TFS you are using.