Page 1 of 2

TUTORIAL - Creating your first server + savePos script

Posted: October 16th, 2018, 4:42 pm
by Karm
Hi!
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:
Image

Here, click in Downloads:
Image

And we select the last version of the server. In this case, Beta 1.0 - Patch 5.
Image

After download it, we create a folder for store the server. I create the folder C:/IV-MP Server
Image

Unzip the content of the server at folder.
Image

For run the server, we execute IVMP Lua.exe
Image

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.
Image

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")
And in main.lua (at server main folder), we will add the line. All script we want to use must be loaded here:

Code: Select all

loadScript("savePos")
Image

OK, let's try the script! Run your server (close first if it was open) and connect with your client.
Image

When you be in, press T for write at chat and type /savepos:
Image

If all was fine, we will read the position info:
Image

And we will have the info at positions.txt:
Image

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!!

Re: TUTORIAL - Creating your first server + savePos script

Posted: October 25th, 2018, 10:18 pm
by SamyrCastello
i cant enter in my server Connection Attempt Failed

Re: TUTORIAL - Creating your first server + savePos script

Posted: October 27th, 2018, 6:50 am
by Karm
Hi SamyrCastello,
can you post a image capture of the error?

Re: TUTORIAL - Creating your first server + savePos script

Posted: October 27th, 2018, 5:12 pm
by SamyrCastello
Server in Masterlist Image

Re: TUTORIAL - Creating your first server + savePos script

Posted: October 27th, 2018, 5:18 pm
by SamyrCastello
see i cant connect on my server

Image

Re: TUTORIAL - Creating your first server + savePos script

Posted: October 28th, 2018, 7:50 pm
by WuskieFTW
It's impossible to connect to a local host using IP, click on "Direct" instead and select your IPV4.

Re: TUTORIAL - Creating your first server + savePos script

Posted: October 29th, 2018, 8:50 am
by SamyrCastello
problem solved I changed the port in config.cfg and the router now i can connect thanks for the attention and help :D

Re: TUTORIAL - Creating your first server + savePos script

Posted: March 25th, 2019, 10:56 am
by cortes
I did everything but gave this error please help me to create my dedicated server Utilis: script loaded: rcon
Utilis: script loaded: playerSpawn
Utilis: script loaded: carSpawning
Utilis: script loaded: weapons
...wnloads\Beta-1.0 Patch 9\/filterscripts/scriptLoader.lua:5: module 'filterscripts/savePos' not found:
no field package.preload['filterscripts/savePos']
no file 'C:\Users\corte\Downloads\Beta-1.0 Patch 9\lua\filterscripts/savePos.lua'
no file 'C:\Users\corte\Downloads\Beta-1.0 Patch 9\lua\filterscripts/savePos\init.lua'
no file 'C:\Users\corte\Downloads\Beta-1.0 Patch 9\filterscripts/savePos.lua'
no file 'C:\Users\corte\Downloads\Beta-1.0 Patch 9\filterscripts/savePos\init.lua'
no file 'C:\Users\corte\Downloads\Beta-1.0 Patch 9\..\share\lua\5.3\filterscripts/savePos.lua'
no file 'C:\Users\corte\Downloads\Beta-1.0 Patch 9\..\share\lua\5.3\filterscripts/savePos\init.lua'
no file '.\filterscripts/savePos.lua'
no file '.\filterscripts/savePos\init.lua'
no file 'C:\Users\corte\Downloads\Beta-1.0 Patch 9\filterscripts/savePos.dll'
no file 'C:\Users\corte\Downloads\Beta-1.0 Patch 9\..\lib\lua\5.3\filterscripts/savePos.dll'
no file 'C:\Users\corte\Downloads\Beta-1.0 Patch 9\loadall.dll'
no file '.\filterscripts/savePos.dll'
Player niko(1) credentials arrived

Re: TUTORIAL - Creating your first server + savePos script

Posted: November 20th, 2020, 2:13 pm
by ÉrrePê
Hello,

I'm trying to create a server and I'm having some troubles.

If someone can give me a hand, it would be really awesome!

Thank you !!

Re: TUTORIAL - Creating your first server + savePos script

Posted: December 6th, 2020, 3:22 pm
by Vittorio
ÉrrePê wrote: November 20th, 2020, 2:13 pm Hello,

I'm trying to create a server and I'm having some troubles.

If someone can give me a hand, it would be really awesome!

Thank you !!
Certainly. If you could join our Discord server to get faster, more effective help, I am gladly awaiting you there: https://discord.gg/wsqf9wH