-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGridHaul Vehicle API.lsl
184 lines (182 loc) · 6.06 KB
/
GridHaul Vehicle API.lsl
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*
** DISCLIAMER **
** VENKELLIE WILL NOT HELP IF THE BASE CODE OF THIS SCRIPT HAS BEEN MODIFIED **
*/
/*
vt = vehicle type = suggested grid grams
------------------------------
ap = Airplane = 20
hp = Helipad = 5
rd = Road = 4
ft = Foot = 2
rr = RailRoad = 12
bo = Boat = 15
sa = Space = 40
am = Amphibian = 39 (road + boat + airplane)
replace the two letters below from the list above.
ie. replace rd with ap for a airplane
string vt = "ap";
*/
string vt = "rd";
/*
max grid grams your vehicle can haul
or set to 0 (zero) if you want the server to set the size
or -1 to use the cubic meter calculation that is in the state_entry event
list box = llGetBoundingBox(llGetKey());
vector vsize = llList2Vector(box, 1) - llList2Vector(box, 0);
maxgg = (llRound(vsize.x) + llRound(vsize.y) + llRound(vsize.z));
maxgg += llGetNumberOfPrims();
*/
integer maxgg = -1;
/* channel number for link_message */
integer lmchan = 30;
// OPEN API channel developers can send data to this script
// also listen on this channel for json data from the HUD
integer OPENAPI = 47434285;
// We should not assume that every possible vehicle has a valid llAcvatarOnSitTarget() (CarlaWetter)
integer target;
integer FindSitTarget() {
// function to scan for the first valid sit target in the vehicle linkset
integer prims = llGetObjectPrimCount(llGetKey()); // number of prims, no seated avis
if (prims > 1) {
integer i = 1;
while ((target == 0)&&(i <= prims)) {
i++;
if (llList2Integer(llGetLinkPrimitiveParams(i, [PRIM_SIT_TARGET]),0) == 1) {
target = i;
}
}
}else if (prims == 1) {
target = 0;
}
return target;
}
// Back to our regular schedule
// this sends a link message to any script in the linkset listening for integer of lmchan
sendlink(list jl) {
string json = llList2Json(JSON_OBJECT,jl);
llMessageLinked(LINK_SET,lmchan,json,NULL_KEY);
}
unloading(string cargo) {
// do your unloading code here
list jl = ["status","unloading"];
jl += ["cargo", cargo];
sendlink(jl);
}
loading(string cargo) {
// do your loading code here
list jl = ["status","loading"];
jl += ["cargo", cargo];
sendlink(jl);
}
/* dont worry about everything below */
integer ghchan = -47434285; // GRIDHAUL on any phone keypad, this chats with the HUD
key owner; // owner of the vehicle
key hudkey = NULL_KEY; // hud's prim UUID key
// this sends to the HUD
apisay(string uri, list other) {
other += ["uri",uri];
string js = llList2Json(JSON_OBJECT,other);
string bs = llStringToBase64(js);
if (hudkey == NULL_KEY) {
hudkey = owner;
}
llRegionSayTo(hudkey,ghchan,bs);
}
// converts 1000 to 1,000
string NumberFormat(integer number) {
string output;
integer x = 0;
string numberString = (string)number;
integer numberStringLength = llStringLength(numberString);
integer z = (numberStringLength + 2) % 3;
for(;x < numberStringLength; ++x) {
output += llGetSubString(numberString, x, x);
if ((x % 3) == z && x != (numberStringLength - 1)) {
output += ",";
}
}
return output;
}
default {
state_entry() {
target = FindSitTarget(); // scan for first valid sit target in linkest on init
if (maxgg == -1) {
list box = llGetBoundingBox(llGetKey());
vector vsize = llList2Vector(box, 1) - llList2Vector(box, 0);
maxgg = (llRound(vsize.x) + llRound(vsize.y) + llRound(vsize.z));
maxgg += llGetNumberOfPrims();
}
llOwnerSay("Maximum cargo capacity: "+NumberFormat(maxgg)+" GridGrams");
owner = llGetOwner();
llListen(ghchan,"","","");
llListen(OPENAPI,"","","");
}
listen(integer chan, string name, key id, string msg) {
if (chan == OPENAPI && llGetOwnerKey(id) != owner) {
string parcel_uuid = llJsonGetValue(msg,["parcel_uuid"]);
string vuri = llJsonGetValue(msg,["uri"]);
string cargo = llJsonGetValue(msg,["cargo"]);
if (vuri == "loading") {
loading(cargo);
}
if (vuri == "unloading") {
unloading(cargo);
}
}
if (chan == ghchan && llGetOwnerKey(id) == owner) {
string bs = llBase64ToString(msg);
string json = llUnescapeURL(bs);
string parcel_uuid = llJsonGetValue(json,["parcel_uuid"]);
if (llJsonValueType(json,["uri"]) != JSON_INVALID) {
string vuri = llJsonGetValue(json,["uri"]);
string cargo = llJsonGetValue(json,["cargo"]);
if (vuri == "loading") {
loading(cargo);
}
if (vuri == "unloading") {
unloading(cargo);
}
}
}
}
link_message(integer sn, integer num, string str, key id) {
if (num == 0) {
if (str == "driver_getin") {
apisay("sit",["vt",vt,"maxgg",maxgg]);
}
if (str == "SPT_SEATED, DRIVER" && id == owner) {
apisay("sit",["vt",vt,"maxgg",maxgg]);
}
if (str == "starter_abandon") {
apisay("stand",["vt","ft"]);
}
if (str == "SPT_SEATED, DRIVER" && id == NULL_KEY) {
apisay("stand",["vt","ft"]);
}
}
}
changed(integer c) {
if (c & CHANGED_LINK) {
key sa = llAvatarOnLinkSitTarget(target);
// obviously we can not use llAvatarOnSitTarget() any more
if (sa) {
apisay("sit",["vt",vt,"maxgg",maxgg]);
}else{
key sabu = llAvatarOnSitTarget();
// Should still check for it just incase
if (sabu) {
apisay("sit",["vt",vt,"maxgg",maxgg]);
}else{
apisay("stand",["vt","ft"]);
}
}
}
if (c & CHANGED_INVENTORY || c & CHANGED_OWNER) {
llResetScript();
}
}
on_rez(integer sp) {
llResetScript();
}
}