• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Enter tile (x,y,z) to get experience

Damon

Check my status to contact me :)
Joined
Mar 26, 2011
Messages
6,219
Solutions
1
Reaction score
2,038
Location
Germany
Hello,
I am in need for a script which gives the player a certain amount of exp when entering a specific tile on the map. I plan to use this in order to feature exploring. Needlessly to say this exp gain should only work once per character so he cant walk back and forth on it continusly to farm exp.
In the end it should work like this. Player steps on tile at (x,y,z) and a message appears saying "You have recived 500 experience points for discovering Dargolof Hills" and gives the player 500 exp. Hope someone can help me out :)

Kind regards,
Damon
 
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:
Code:
end
this will close the if statement

on the 7th line write:
Code:
end
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.
 
Last edited:
Server version?
TFS 0.4 for client 8.70 :) Sorry I forgot about this^^
bIPmw96.jpg


As I am no good at scripting, yes, this is a request @whitevo ^^
However I will check on what you were writing :)
 
First you start with the function you need, like whitevo kind of already explained.
Code:
function onStepIn(cid, item, position, fromPosition)
     -- what the script should do
     return true
end
You need to check in the script if something is the right tile. You can check the position, but more easy is just to add an uniqueid and check for that, since with a position you have to check for 3 things (x, y, z).
So you add uniqueids to the tiles, for example 8001, 8002, 8003. Add the same actionid to the tiles and add the script with that actionid in movements.xml so you only have to add 1 id incase you have alot of tiles, else you can just add them with the uniqueid.

Then you can create a table for the tiles based on uniqueid.
Code:
local positions = {
     [8001] = {exp = 10000, text = "Welcome to x town."},
     [8002] = {exp = 20000, text = "Welcome to y City."},
     [8003] = {exp = 23000, text = "Welcome to the blabla Village."}
}

function onStepIn(cid, item, position, fromPosition)
     local x = positions[item.uid]
     if x and getCreatureStorage(cid, item.uid) == -1 then
         doPlayerAddExperience(cid, x.exp)
         doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, x.text)
         doCreatureSetStorage(cid, item.uid, 1)
     end
     return true
end
Atm x stands for a certain table in the local positions table.
So if the uniqueid of the tile is 8001, then x will be positions[8001] which is this table: {exp = 10000, text = "Welcome to x town."}.
To get values from the table, all you have to do is add .name, so as you can see, x.exp and x.text. If you want to add more things you can do it the same way.
I used the uniqueid as storage here, if you want a different storage number you can just add for example storage = 8754 in the table and then use x.storage.
 
Awesome! Thank you both for helping me out there! I am short on time due to exams so i wont be testing it right away but i will maybe write the script tonight and check on it^^ Will also post it here when im done^^
 
Back
Top