-
Notifications
You must be signed in to change notification settings - Fork 4
/
vehicle.go
79 lines (65 loc) · 1.73 KB
/
vehicle.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package sampgo
import (
"fmt"
"math"
)
const (
SeatDriver = iota
SeatFront
SeatBackLeft
SeatBackRight
)
type Vehicle struct {
ID int
}
type VehicleParams struct {
Engine int
Lights int
Alarm int
Doors int
Bonnet int
Boot int
Objective int
}
func NewVehicle(modelid int, x, y, z, rotation float32, color1, color2 uint8, respawn_delay int, addsiren bool) (Vehicle, error) {
var v Vehicle
if !IsValidVehicleModel(modelid) {
return v, fmt.Errorf("invalid vehicle model")
}
v.ID = CreateVehicle(modelid, x, y, z, rotation, int(color1), int(color2), respawn_delay, addsiren)
if v.ID == InvalidVehicleId {
return v, fmt.Errorf("couldn't create vehicle")
}
return v, nil
}
func (v *Vehicle) Destroy() error {
if !DestroyVehicle(v.ID) {
return fmt.Errorf("vehicle doesn't exist")
}
return nil
}
func (v *Vehicle) GetSpeedFloat64() float64 {
var x, y, z float32
GetVehicleVelocity(v.ID, &x, &y, &z)
return math.Sqrt(float64((x*x)+(y*y)+(z*z))) * 136.666667
}
func (v *Vehicle) GetSpeedFloat32() float32 {
return float32(v.GetSpeedFloat64())
}
func (v *Vehicle) GetSpeedInt() int {
return int(math.Round(v.GetSpeedFloat64()))
}
func (v *Vehicle) PutPlayer(p *Player, seat int) error {
if !PutPlayerInVehicle(p.ID, v.ID, seat) {
return fmt.Errorf("player or vehicle doesn't exist")
}
return nil
}
func (v *Vehicle) GetParams() VehicleParams {
var params VehicleParams
GetVehicleParamsEx(v.ID, ¶ms.Engine, ¶ms.Lights, ¶ms.Alarm, ¶ms.Doors, ¶ms.Bonnet, ¶ms.Boot, ¶ms.Objective)
return params
}
func (v *Vehicle) SetParams(params VehicleParams) {
SetVehicleParamsEx(v.ID, params.Engine, params.Lights, params.Alarm, params.Doors, params.Bonnet, params.Boot, params.Objective)
}