-
Notifications
You must be signed in to change notification settings - Fork 4
Create project
Learn how to get started writing alt:V resources in Golang.
To develop resources using Golang, make sure to check out the following requirements and recommended tools.
You need to have to following tools installed on your machine:
- Go >= 1.21.0
- mingw-w64 (for Windows users)
- GCC >= 9.3.0 (for Linux or macOS users)
After installing Go, create a new empty folder and run go mod init to initialize a new project.
In this example we will call our project gofreeroom:
# Linux / macOS / Powershell (Windows)
mkdir gofreeroom
cd gofreeroom
go mod init gofreeroomTo get the latest version of the go api run
go get -u github.com/timo972/altv-go@latestWe are going to write a simple resource that spawns a player on connect.
Create a file called main.go and paste the following content into it.
package main
import (
"github.com/timo972/altv-go/altlog"
"github.com/timo972/altv-go/entity"
"github.com/timo972/altv-go/event"
)
func init() {
event.On.PlayerConnect(onPlayerConnect)
event.On.Start(onStart)
event.On.Stop(onStop)
}
func main() {}
func onPlayerConnect(p entity.Player) {
p.Spawn(0, 0, 76, 0)
}
func onStart() {
altlog.Println("Hello from ~lb~go")
}
func onStop() {
altlog.Println("bye")
}Building the resource is as easy as building a regular golang application. Simply define an output lib name and set buildmode to c-shared.
# Linux / macOS
go build -o gofreeroom.so -buildmode=c-shared
# Windows
go build -o gofreeroom.dll -buildmode=c-sharedThe first build will likely run a little slower because the go compiler has to link to a c lib. All following builds will be at usual go speed.
Congratulations ๐! The gofreeroom.so (on linux) or gofreeroom.dll (on windows) library can now be run by the alt:V server.
Learn how to properly configure an alt:V resource to run the shared library
You encountered a problem ๐ฅ? Check out the Troubleshooting Guide!
If you can't find a solution there file a new issue in this repository or contact me on Discord.