-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.go
52 lines (42 loc) · 1.18 KB
/
script.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package ns
import (
"strconv"
ns4 "github.com/noxworld-dev/noxscript/ns/v4"
)
// Source:
// https://github.com/NoxTools/noxscript/blob/master/builtins.h
type Func = any
// RandomFloat generate a random float.
func RandomFloat(min, max float32) float32 {
return ns4.RandomFloat(min, max)
}
// Random generate a random int.
func Random(min, max int) int {
return ns4.Random(min, max)
}
// StopScript exit current script function.
func StopScript(value any) {
ns4.StopScript(value)
}
// IntToString convert an integer to a string.
//
// This will convert an integer to a string, and add the to string the string
// table temporarily.
//
// Deprecated: use strconv.Itoa.
func IntToString(number int) string {
return strconv.Itoa(number)
}
// FloatToString converts a float to a string.
//
// This will convert a float to a string, and add the to string the string
// table temporarily.
//
// Deprecated: use strconv.FormatFloat.
func FloatToString(number float32) string {
return strconv.FormatFloat(float64(number), 'g', -1, 32)
}
// Distance calculate distance between two locations.
func Distance(x1, y1, x2, y2 float32) float32 {
return float32(ns4.Ptf(x1, y1).Sub(ns4.Ptf(x2, y2)).Len())
}