@@ -198,7 +198,7 @@ void LLPanelContents::onClickNewScript(void *userdata)
198
198
{
199
199
const bool children_ok = true ;
200
200
LLViewerObject* object = LLSelectMgr::getInstance ()->getSelection ()->getFirstRootObject (children_ok);
201
- if (object)
201
+ if (object)
202
202
{
203
203
LLPermissions perm;
204
204
perm.init (gAgent .getID (), gAgent .getID (), LLUUID::null, LLUUID::null);
@@ -227,78 +227,94 @@ void LLPanelContents::onClickNewScript(void *userdata)
227
227
// This temporary workaround should be removed after a server-side fix.
228
228
// See https://github.com/secondlife/viewer/issues/3731 for more information.
229
229
//
230
- if (std::string::size_type pos = desc.find (" lsl2" ); pos != std::string::npos)
230
+ LLViewerRegion* region = object->getRegion ();
231
+ if (region && region->simulatorFeaturesReceived ())
231
232
{
232
- desc.replace (pos, 4 , " SLua" );
233
- }
234
-
235
- auto scriptCreationCallback = [object](const LLUUID& inv_item)
233
+ LLSD simulatorFeatures;
234
+ region->getSimulatorFeatures (simulatorFeatures);
235
+ if (simulatorFeatures[" LuaScriptsEnabled" ].asBoolean ())
236
236
{
237
- if (!inv_item. isNull () )
237
+ if (std::string::size_type pos = desc. find ( " lsl2 " ); pos != std::string::npos )
238
238
{
239
- LLViewerInventoryItem* item = gInventory .getItem (inv_item);
240
- if (item)
241
- {
242
- const std::string hello_lua_script =
243
- " function state_entry()\n "
244
- " ll.Say(0, \" Hello, Avatar!\" )\n "
245
- " end\n "
246
- " \n "
247
- " function touch_start(total_number)\n "
248
- " ll.Say(0, \" Touched.\" )\n "
249
- " end\n "
250
- " \n "
251
- " -- Simulate the state_entry event\n "
252
- " state_entry()\n " ;
253
-
254
- auto scriptUploadFinished = [object, item](LLUUID itemId, LLUUID newAssetId, LLUUID newItemId, LLSD response)
255
- {
256
- LLPointer<LLViewerInventoryItem> new_script = new LLViewerInventoryItem (item);
257
- object->saveScript (new_script, true , true );
258
-
259
- // Delete the temporary item from the user's inventory after rezzing it in the object's inventory
260
- gInventory .deleteObject (item->getUUID ());
261
- gInventory .notifyObservers ();
262
- };
239
+ desc.replace (pos, 4 , " SLua" );
240
+ }
263
241
264
- std::string url = gAgent .getRegion ()->getCapability (" UpdateScriptAgent" );
265
- if (!url.empty ())
242
+ auto scriptCreationCallback = [object](const LLUUID& inv_item)
243
+ {
244
+ if (!inv_item.isNull ())
266
245
{
267
- LLResourceUploadInfo::ptr_t uploadInfo (std::make_shared<LLScriptAssetUpload>(
268
- item->getUUID (),
269
- " luau" ,
270
- hello_lua_script,
271
- scriptUploadFinished,
272
- nullptr ));
273
-
274
- LLViewerAssetUpload::EnqueueInventoryUpload (url, uploadInfo);
246
+ LLViewerInventoryItem* item = gInventory .getItem (inv_item);
247
+ if (item)
248
+ {
249
+ const std::string hello_lua_script =
250
+ " function state_entry()\n "
251
+ " ll.Say(0, \" Hello, Avatar!\" )\n "
252
+ " end\n "
253
+ " \n "
254
+ " function touch_start(total_number)\n "
255
+ " ll.Say(0, \" Touched.\" )\n "
256
+ " end\n "
257
+ " \n "
258
+ " -- Simulate the state_entry event\n "
259
+ " state_entry()\n " ;
260
+
261
+ auto scriptUploadFinished = [object, item](LLUUID itemId, LLUUID newAssetId, LLUUID newItemId, LLSD response)
262
+ {
263
+ LLPointer<LLViewerInventoryItem> new_script = new LLViewerInventoryItem (item);
264
+ object->saveScript (new_script, true , true );
265
+
266
+ // Delete the temporary item from the user's inventory after rezzing it in the object's inventory
267
+ ms_sleep (50 );
268
+ LLMessageSystem* msg = gMessageSystem ;
269
+ msg->newMessageFast (_PREHASH_RemoveInventoryItem);
270
+ msg->nextBlockFast (_PREHASH_AgentData);
271
+ msg->addUUIDFast (_PREHASH_AgentID, gAgent .getID ());
272
+ msg->addUUIDFast (_PREHASH_SessionID, gAgent .getSessionID ());
273
+ msg->nextBlockFast (_PREHASH_InventoryData);
274
+ msg->addUUIDFast (_PREHASH_ItemID, item->getUUID ());
275
+ gAgent .sendReliableMessage ();
276
+
277
+ gInventory .deleteObject (item->getUUID ());
278
+ gInventory .notifyObservers ();
279
+ };
280
+
281
+ std::string url = gAgent .getRegion ()->getCapability (" UpdateScriptAgent" );
282
+ if (!url.empty ())
283
+ {
284
+ LLResourceUploadInfo::ptr_t uploadInfo (std::make_shared<LLScriptAssetUpload>(
285
+ item->getUUID (),
286
+ " luau" ,
287
+ hello_lua_script,
288
+ scriptUploadFinished,
289
+ nullptr ));
290
+
291
+ LLViewerAssetUpload::EnqueueInventoryUpload (url, uploadInfo);
292
+ }
293
+ }
275
294
}
276
-
277
- gInventory .updateItem (item);
278
- gInventory .notifyObservers ();
279
- }
280
- }
281
- };
282
- LLPointer<LLBoostFuncInventoryCallback> cb = new LLBoostFuncInventoryCallback (scriptCreationCallback);
283
-
284
- LLMessageSystem* msg = gMessageSystem ;
285
- msg->newMessageFast (_PREHASH_CreateInventoryItem);
286
- msg->nextBlock (_PREHASH_AgentData);
287
- msg->addUUIDFast (_PREHASH_AgentID, gAgent .getID ());
288
- msg->addUUIDFast (_PREHASH_SessionID, gAgent .getSessionID ());
289
- msg->nextBlock (_PREHASH_InventoryBlock);
290
- msg->addU32Fast (_PREHASH_CallbackID, gInventoryCallbacks .registerCB (cb));
291
- msg->addUUIDFast (_PREHASH_FolderID, gInventory .getRootFolderID ());
292
- msg->addUUIDFast (_PREHASH_TransactionID, LLTransactionID::tnull);
293
- msg->addU32Fast (_PREHASH_NextOwnerMask, PERM_MOVE | PERM_TRANSFER);
294
- msg->addS8Fast (_PREHASH_Type, LLAssetType::AT_LSL_TEXT);
295
- msg->addS8Fast (_PREHASH_InvType, LLInventoryType::IT_LSL);
296
- msg->addU8Fast (_PREHASH_WearableType, NO_INV_SUBTYPE);
297
- msg->addStringFast (_PREHASH_Name, " New Script" );
298
- msg->addStringFast (_PREHASH_Description, desc);
299
-
300
- gAgent .sendReliableMessage ();
301
- return ;
295
+ };
296
+ LLPointer<LLBoostFuncInventoryCallback> cb = new LLBoostFuncInventoryCallback (scriptCreationCallback);
297
+
298
+ LLMessageSystem* msg = gMessageSystem ;
299
+ msg->newMessageFast (_PREHASH_CreateInventoryItem);
300
+ msg->nextBlock (_PREHASH_AgentData);
301
+ msg->addUUIDFast (_PREHASH_AgentID, gAgent .getID ());
302
+ msg->addUUIDFast (_PREHASH_SessionID, gAgent .getSessionID ());
303
+ msg->nextBlock (_PREHASH_InventoryBlock);
304
+ msg->addU32Fast (_PREHASH_CallbackID, gInventoryCallbacks .registerCB (cb));
305
+ msg->addUUIDFast (_PREHASH_FolderID, gInventory .getRootFolderID ());
306
+ msg->addUUIDFast (_PREHASH_TransactionID, LLTransactionID::tnull);
307
+ msg->addU32Fast (_PREHASH_NextOwnerMask, PERM_MOVE | PERM_TRANSFER);
308
+ msg->addS8Fast (_PREHASH_Type, LLAssetType::AT_LSL_TEXT);
309
+ msg->addS8Fast (_PREHASH_InvType, LLInventoryType::IT_LSL);
310
+ msg->addU8Fast (_PREHASH_WearableType, NO_INV_SUBTYPE);
311
+ msg->addStringFast (_PREHASH_Name, " New Script" );
312
+ msg->addStringFast (_PREHASH_Description, desc);
313
+
314
+ gAgent .sendReliableMessage ();
315
+ return ;
316
+ }
317
+ }
302
318
//
303
319
// End hack
304
320
// --------------------------------------------------------------------------------------------------
0 commit comments