Giter Site home page Giter Site logo

vcmp-lua's Introduction

VCMP Lua Plugin

As the name suggests, this plugin provides a scripting API for VCMP in Lua (yay!). Please check out the WIKI to learn about the structure of the plugin (its quite easy!)

Purpose of this project

The purpose of this project is mainly that I love Lua, and I also love C++, therefore to keep my practice in C++ I decided to work on this plugin with one of my favorite scripting languages (Lua).

The Lua config file

In your server directory you should place a luaconfig.ini file which will allow you to specify some settings the plugin can use. Some of these settings are optional while some (like specifying atleast 1 script file) is compulsory.

The file structure is as of right now very simple:

[config]
# Sets experimental mode ON (1) or OFF (0) | Intended for beta-testing and development only. Do not rely for stability
#experimental=1
# Sets the log level, See the Logger page on Wiki for more information
loglevel=0
# Sets the log file. This log file will be used to create daily logs and it will log everything logged by Logger class, regardless of level
logfile=DailyLogs.logs

[modules]
# This is the modules section, here you can opt in to use external modules that the plugin provides. They can be listed and toggled by setting them to a boolean

#moduleName=[true/false]
lanes=false

[scripts]
# This is the scripts section, here you can specify all your script files that you want to run.

# script=path/to/file.lua
script=lua/script.lua

Building the plugin

Windows

To build on Windows, just download the repository and run the win-build.bat file in the premake folder. You should be getting a Visual Studio 2019 solution file

NOTE: You can only build x64 of Lua plugin on Windows for now. Why? Cuz I'm too lazy to setup my environment to compile mariadb for x32 :D

Linux

To build on Linux:

  • Download/Clone the repository
  • Download premake and build it
  • Inside the repository, call premake: path/to/premake5 gmake
  • Now use make with your desired config: make config=release OR make config=release32

vcmp-lua's People

Contributors

dizzaster avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

matheustkn

vcmp-lua's Issues

player:playSound

Sound plays for all players who are in the same world as the player

player.name does not change the player's name.

Using player.name = "somename" does not change the player's name.

Request new functions:

vehicle:respawn()
vehicle:getDriver()
vehicle:getOccupant(slotID)
vehicle:getTyre(tyre)
Vehicle:setTyre(tyre, state)
vehicle:fix()
vehicle:getPart(partID)
vehicle:setPart(part, state)
vehicle.taxiLight
vehicle.turretRotation
pickup:getModel()

Map.hideObject does not support correct coordinate data

I'm trying to hide the following object

Map.hideObject(474, -393.412, -505.822, 9.92519)

This returns the following error:
[error] Event callback error: stack index 2, expected number, received number: not a numeric type that fits exactly an integer (number maybe has significant decimals) (bad argument into 'void(int, short, short, short)')

The game only hides an object if it uses a decimal value, otherwise the object is not hidden.

Lua machine not exported

Hello, few days ago i noticed this in java plugin and decided to take a look at this plugin too.

In squirrel, stormeus does something like SendPluginCommand(0x7DC..., "");
Also on VcmpPluginInit, you can see somethings are 'exported'- the virtual machine.
Why this is needed is that if someone decided to write a plugin for this lua language, they need access to the lua virtual machine.

Map objects disappearing

Objects created with Object:new disappear from the map after a few minutes.

Script:

initTime = 0
Event.bind("onServerInit", function()
    loadObject(os.time())
	Timer.create(function()
		if Object.count() < 1 then
			Logger.info("No objects found | time: " .. os.time())
			Logger.info("After: " .. os.time() - initTime .. " secs")
		end
	end, 50, -1)
end)

function loadObject(timestamp)
	initTime = timestamp
	Object:new(4499, 1, -305.76, -481.706, 20.7062, 255)
	Logger.info("Object count: " .. Object.count() .. " | time: " .. timestamp)
end

Log:

Server.getSettings() nil value

This function is returning the following error

Event callback error: main.lua:118: attempt to call a nil value (field 'getSettings')

Request Server functions

Squirrel

SetMaxPlayers(int)
SetMaxHeight(int)

Lua Suggestion

Server.maxPlayers = int
Server.maxHeight = int

Didn't find how to solve it

Plugin error >> dlopen() 'plugins/LuaPlugin_x64.so' failed: plugins/LuaPlugin_x64.so: undefined symbol: mysql_use_result
Failed to load plugin: LuaPlugin_x64

OS: Linux debian-m-2vcpu-16gb-fra1-01 5.10.0-11-amd64 #1 SMP Debian 5.10.92-1 (2022-01-18) x86_64 GNU/Linux

failed do initialize embedded Lanes

When starting the plugin with the latest update, this happens
image.png

And also request for new functions too: player:setAlpha(), player.alpha, player.away, vehicle.immunity

Missing functions

Here's the list I've noticed so far

Server.banPlayer(player) / player:ban()
Server.kickPlayer(player) / player:kick()
Server.banIP(ip)
Server.isIPBanned(ip)
Server.unbanIP(ip)
player.away
player:disarm()
player:setAlpha
player.alpha
vehicle.immunity

Edit: Also consider these functions: player:setAlpha/player.alpha, vehicle.immunity

stream:readString() doing incorrect reading of data

When sending strings from the client to the server, fragments of previous reads persist on the server.

Client-side:

// If a string is shorter than the previous one, it will end up getting mixed up with some characters from the previous one.

words <- ["If", "a", "string", "is", "shorter", "than", "the", "previous", "one,", "it", "will", "end", "up", "getting", "mixed", "up", "with", "some", "characters", "from", "the", "previous", "one."] 

foreach(i, w in words) {
	local Data = Stream();
	Data.WriteInt(10)
	Data.WriteString(words[i]);
	Server.SendData(Data);
}

Server-side:

function onClientData(player, stream, size)
  local streamId = stream:readNumber()
  local string = stream:readString()
  if(streamId == 10) then
	Player.msgAll(string)
  end
end

In-game chat display

g

onPlayerDisconnect: Inconsistency between Player 0 and Player 1

When there is more than one player, players 0 and 1 get confused by being indexed in the onPlayerDisconnect event.

If Player 0 leaves the server, it ends up being recognized as ID 1

Console logs:
Players connecting

Player 'Player0' ID 0 connected.
Player 'Player1' ID 1 connected.
Player 'Player2' ID 2 connected.

Player 0 leaving (The console shows that it is player 0 leaving, but the event recognizes it as player 1)

Disconnecting player 'Player0' at ID 0, sent quit packet with reason 1.
Player 'Player0' ID 0 disconnected.
Player1 left with the ID 1

Script in onPlayerDisconnect:

print(player.name .. " left with the ID " .. player.id)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.