-
Notifications
You must be signed in to change notification settings - Fork 0
/
(sr)Give inventory - simple.lsl
170 lines (143 loc) · 5.03 KB
/
(sr)Give inventory - simple.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
// this script is designed to give content of box _except_ itself. It can be used as is, or modified.
integer g_bGiveOnRez = TRUE; // automatically give inventory if object is rezzed in world
integer g_bGiveOnAttach = TRUE; // automatically give inventory if object is attached
integer g_bDetachAfterUse = TRUE; // automatically detach
integer g_bCleanLandAfterUse = TRUE; // automatically destroy package if rezzed on land !!WARNING!! no copy package will be lost!
// but setting it to true helps to keep sandboxes clean, as newbies people don't know what to do
// clearly yet
// *** FEEL FREE TO EDIT THOSE ***
string g_sDefaultFolder = ""; // if default folder is empty, GenerateFolderName() is used
string g_sUnpackString = "Unpack";
//%n %o %f with user name, object's name and folder's name respectively
string g_sHello = "Good day, %n. This is automated package containing goods you purchased. To use them properly you should unpack them. We gladly help you with that, using this script.";
string g_sNotify = "This package would create a folder %f in your inventory and put its content there. Please, stand by...";
string g_sRemove = "Package is automatically removed.";
// name replacers (%n %o %f) do not work here. Done to avoid postponed detach event.
string g_sByeString = "Thank you for using our services, we hope you will enjoy your purchase.";
// hover text color
vector g_vColor = <0.0, 1.0, 1.0>;
key g_kUser;
string strReplace(string str, string search, string replace)
{
return llDumpList2String(llParseStringKeepNulls((str = "") + str,
[search], []), replace);
}
// generate folder name here
// uses package's object name if default is empty string
string GenerateFolderName()
{
if(g_sDefaultFolder == "")
return llGetObjectName();
else
{
return g_sDefaultFolder;
}
}
// parses string, replacing %n %o %f with user name, object's name and folder's name respectively
string parseString(string s)
{
string res;
res = strReplace(s, "%o", llGetObjectName());
res = strReplace(res, "%n", llKey2Name(llGetOwner()) );
res = strReplace(res, "%f", GenerateFolderName());
return res;
}
Notify(string msg)
{
string s = msg;
llInstantMessage(g_kUser, msg);
llSetText(msg, g_vColor, 1.0);
}
list ReadInvenotory()
{
list inventory;
integer count = llGetInventoryNumber(INVENTORY_ALL);
integer i;
string s;
string scriptName = llGetScriptName();
for(i = 0; i < count; i++)
{
s =llGetInventoryName(INVENTORY_ALL,i);
if ( s != scriptName)
{
llSetText(g_sNotify + "\nProcessing... " +(string)(i*100.0/count) + "%",
g_vColor, 1.0);
// add to to-be-give
inventory = s + inventory; // best LSL-Mono way
//inventory = (inventory=[]) + inventory + s; // best LSL way
}
}
return inventory;
}
ProcessInventory(string folder)
{
Notify(g_sNotify);
// read inventory
list ToBeGiven = ReadInvenotory();
// do stuff with this list if you need to
// give items listed
folder = GenerateFolderName();
llGiveInventoryList(g_kUser, folder, ToBeGiven);
}
GiveInventory()
{
ProcessInventory(g_sDefaultFolder);
if(llGetAttached() != 0)
{
if(g_bDetachAfterUse)
{
Notify(g_sRemove);
llSleep(2.0);
llDetachFromAvatar(); // detachm perm granted to attached objects
}
}
else
if(g_bCleanLandAfterUse)
{
Notify(g_sRemove + "\n" + g_sByeString);
llSleep(2.0);
llDie();
}
}
default
{
state_entry()
{
}
attach(key id)
{
if(id != NULL_KEY) //was attached
{
llRequestPermissions(id, PERMISSION_ATTACH );
g_kUser = id; // after marketplace sometimes object doesn't have proper owner and prev.owner\creator properties
// until object gets rezzed inworld by new owner (results of testing anno fall 2011).
// sometimes it's old owner.
if(g_bGiveOnAttach) GiveInventory();
}
else if (llGetAttached() == 0)
{
// there is false idea that id can be null only if object detached
// In fact, disabling scripts during script being active, or lag
// during detachment may cause it happen on attach.
llInstantMessage(g_kUser,g_sByeString);
}
}
on_rez(integer param)
{
g_kUser = llGetOwner();
llSetTouchText(g_sUnpackString);
Notify(g_sHello);
if(g_bGiveOnRez && (llGetAttached() == 0))
{
GiveInventory();
}
}
touch_start(integer total_number)
{
if(llDetectedKey(0))
{
g_kUser = llGetOwner();
GiveInventory();
}
}
}