I have decided to do this tutorial for newbies and for those who like programming and who want to experiment with this great game. In this tutorial we will do:
- Download the server.
- Write our first script.
- Test it at game.
First of all, you need to download the server going to the Downloads section in this forum http://forum.iv-mp.eu/viewforum.php?f=1 ... 176cfabc62:
Here, click in Downloads:
And we select the last version of the server. In this case, Beta 1.0 - Patch 5.
After download it, we create a folder for store the server. I create the folder C:/IV-MP Server
Unzip the content of the server at folder.
For run the server, we execute IVMP Lua.exe
But first, we are going to create our first script. At filterscripts folder, we create a file called savePos.lua, a script for save our position at the game typing /savepos at chat.
We will write this code at file. This script read the commands and if we type /savepos save the spawn position at positions.txt and shows a message for the player. You have more info at script comments.:
Code: Select all
-- http://lua-users.org/wiki/CommonFunctions
-- remove trailing and leading whitespace from string.
-- http://en.wikipedia.org/wiki/Trim_(programming)
function trim(s)
-- from PiL2 20.4
return (s:gsub("^%s*(.-)%s*$", "%1"))
end
function commandProcessor(playerid, text)
-- Remove whitespaces from input text
local command = trim(text)
if(command == "/savepos") then
-- Gets player position
local x, y, z = getPlayerPos(playerid)
-- https://www.tutorialspoint.com/lua/lua_file_io.htm
-- Opens a file in append mode
file = io.open("positions.txt", "a")
-- sets the default output file as positions.txt
io.output(file)
-- appends the player command info to the last line of the file
io.write("setPlayerPos("..x..", "..y..", "..z..")\n")
-- closes the open file
io.close(file)
sendPlayerMsg(playerid, "Position saved!: x: "..x..", y: "..y..", z: "..z..")", 0xFFFF00FF)
end
end
registerEvent("commandProcessor", "onPlayerCommand")
Code: Select all
loadScript("savePos")
OK, let's try the script! Run your server (close first if it was open) and connect with your client.
When you be in, press T for write at chat and type /savepos:
If all was fine, we will read the position info:
And we will have the info at positions.txt:
You can use this command for store spawn positions.
That's all. Do you need some help at any point?
If you liked the tutorial and you want more tell me at comments.
See you soon!!