417 lines
15 KiB
Plaintext
417 lines
15 KiB
Plaintext
// 4CGS - Objekt Inventory [v0.07.02]
|
|
|
|
integer m_slots = 2;
|
|
integer m_inventarSlots = 2;
|
|
|
|
list m_current = [];
|
|
list m_last_touch = [];
|
|
integer m_channel_public = -58347;
|
|
integer m_channel_public_socket = 0;
|
|
integer m_channel_private = -58347;
|
|
integer m_channel_private_socket = 0;
|
|
integer m_locked = FALSE;
|
|
vector m_homePosition = <0, 0, 0>;
|
|
key m_storage_id = NULL_KEY;
|
|
string m_name = "";
|
|
|
|
string m_lang_mitnehmen = "Mitnehmen";
|
|
string m_lang_lagern = "Einlagern";
|
|
string m_lang_freierSlot = "Du hast keinen freien Inventar Slot mehr frei!";
|
|
string m_lang_slotLeer = "Dieses Fach ist bereits leer.";
|
|
string m_lang_gleicheItems = "Du kannst nur gleiche Gegenstände zusammen legen!";
|
|
string m_lang_fullSlotDesc = "Was möchtest du mit {0} machen?";
|
|
string m_lang_emptrySlotDesc = "Dieser Slot ist leer. Was möchtest du machen?";
|
|
|
|
integer checkIfPlayerHaveItemInInventar(list _dataStorage, string itemName)
|
|
{
|
|
integer _freeSlot = 0;
|
|
integer _currentSlot;
|
|
for(_currentSlot = 1; _currentSlot <= m_inventarSlots; ++_currentSlot)
|
|
{
|
|
if(getDataEntryFromDataList(_dataStorage, "inventar.slot." + _currentSlot) == itemName)
|
|
return TRUE;
|
|
}
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
integer getNextFreeInventorySlot(list _dataStorage, string _itemName)
|
|
{
|
|
integer _freeSlot = 0;
|
|
integer _currentSlot;
|
|
for(_currentSlot = 1; _currentSlot <= m_inventarSlots; ++_currentSlot)
|
|
{
|
|
if(getDataEntryFromDataList(_dataStorage, "inventar.slot." + _currentSlot) == _itemName)
|
|
return _currentSlot;
|
|
|
|
if(getDataEntryFromDataList(_dataStorage, "inventar.slot." + _currentSlot) == "")
|
|
if(_freeSlot == 0)
|
|
_freeSlot = _currentSlot;
|
|
}
|
|
|
|
return _freeSlot;
|
|
}
|
|
|
|
integer getItemCountFromPlayer(list _dataStorage, integer slot)
|
|
{
|
|
return (integer)getDataEntryFromDataList(_dataStorage, "inventar.slot." + slot + ".count");
|
|
}
|
|
|
|
cleanGameState()
|
|
{
|
|
list _dataStorage = getDataListFromDataStorage("game.inventar.objekt." + m_storage_id + ".inventar");
|
|
|
|
integer _currentSlot;
|
|
for(_currentSlot = 1; _currentSlot <= m_slots; _currentSlot++)
|
|
{
|
|
setInventarSlotImage(_currentSlot, TEXTURE_BLANK, 0);
|
|
setInventarSlotCountNumber(_currentSlot, 0);
|
|
|
|
if(checkDataEntryInDataList(_dataStorage, "inventar.slot." + _currentSlot) == FALSE)
|
|
{
|
|
_dataStorage = setDataEntryInDataList(_dataStorage, "inventar.slot." + _currentSlot, "");
|
|
_dataStorage = setDataEntryInDataList(_dataStorage, "inventar.slot." + _currentSlot + ".count", "0");
|
|
}
|
|
}
|
|
|
|
saveDataListToDataStorage(_dataStorage, "game.inventar.objekt." + m_storage_id + ".inventar");
|
|
}
|
|
|
|
refreshData()
|
|
{
|
|
list _dataStorage = getDataListFromDataStorage("game.inventar.objekt." + m_storage_id + ".inventar");
|
|
|
|
integer _currentSlot;
|
|
|
|
for(_currentSlot = 1; _currentSlot <= m_slots; _currentSlot++)
|
|
{
|
|
if(checkDataEntryInDataList(_dataStorage, "inventar.slot." + _currentSlot) == TRUE)
|
|
{
|
|
string _invObjekt = getDataEntryFromDataList(_dataStorage, "inventar.slot." + _currentSlot);
|
|
integer _count = (integer)getDataEntryFromDataList(_dataStorage, "inventar.slot." + _currentSlot + ".count");
|
|
|
|
if(_count != 0)
|
|
{
|
|
setInventarSlotImage(_currentSlot, getInventarObjectImageKey(_invObjekt), 255);
|
|
setInventarSlotCountNumber(_currentSlot, _count);
|
|
}else{
|
|
setInventarSlotImage(_currentSlot, TEXTURE_BLANK, 0);
|
|
setInventarSlotCountNumber(_currentSlot, 0);
|
|
}
|
|
}
|
|
}
|
|
|
|
saveDataListToDataStorage(_dataStorage, "game.inventar.objekt." + m_storage_id + ".inventar");
|
|
}
|
|
|
|
default
|
|
{
|
|
state_entry()
|
|
{
|
|
llSetLinkPrimitiveParamsFast(LINK_SET, [PRIM_TEXT, "", <0, 0, 0>, 0.0]);
|
|
if(m_channel_public_socket != 0)
|
|
llListenRemove(m_channel_public_socket);
|
|
|
|
m_channel_public_socket = llListen(m_channel_public, "", "", "");
|
|
|
|
if(m_channel_private_socket != 0)
|
|
llListenRemove(m_channel_private_socket);
|
|
|
|
m_channel_private_socket = llListen(Key2AppChan(llGetOwner(), 48376), "", "", "");
|
|
|
|
m_homePosition = llGetPos();
|
|
cleanGameState();
|
|
refreshData();
|
|
llSetTimerEvent(2);
|
|
}
|
|
|
|
on_rez(integer start_para)
|
|
{
|
|
m_homePosition = llGetPos();
|
|
cleanGameState();
|
|
}
|
|
|
|
timer()
|
|
{
|
|
if(llVecDist(llGetPos(), m_homePosition) >= 10)
|
|
{
|
|
m_storage_id = NULL_KEY;
|
|
osForceDetachFromAvatar();
|
|
}
|
|
}
|
|
|
|
listen(integer channel, string name, key id, string message )
|
|
{
|
|
if(m_locked == FALSE)
|
|
{
|
|
if(left(message, ";") == "setstorageid")
|
|
m_storage_id = (key)right(message, ";");
|
|
|
|
if(left(message, ";") == "setname")
|
|
m_name = (key)right(message, ";");
|
|
|
|
if(left(message, ";") == "attachto")
|
|
{
|
|
llRequestPermissions((key)right(message, ";"), PERMISSION_ATTACH );
|
|
|
|
if(m_channel_private_socket != 0)
|
|
llListenRemove(m_channel_private_socket);
|
|
|
|
m_channel_private = Key2AppChan((key)right(message, ";"), 48376);
|
|
m_channel_private_socket = llListen(m_channel_private, "", "", "");
|
|
|
|
llMessageLinked(LINK_SET, 0, m_name, "showname");
|
|
|
|
m_locked = TRUE;
|
|
}
|
|
}
|
|
|
|
if(left(message, ";") == "gamecommand")
|
|
{
|
|
if(right(message, ";") == "reload")
|
|
refreshData();
|
|
}
|
|
|
|
if(channel != m_channel_private)
|
|
return;
|
|
|
|
list _dataStorage = getDataListFromDataStorage("game.inventar.objekt." + m_storage_id + ".inventar");
|
|
list _dataUserStorage = getDataListFromDataStorage("game.hud.player." + id);
|
|
|
|
string _itemName = getDataEntryFromDataList(_dataStorage, "inventar.slot." + llList2String(m_last_touch, 2));
|
|
|
|
string _playerSlot = getDataEntryFromDataList(_dataUserStorage, "selected");
|
|
|
|
if(message == m_lang_mitnehmen)
|
|
{
|
|
integer _nextFreePlayerInventarSlot = (integer)getNextFreeInventorySlot(_dataUserStorage, _itemName);
|
|
|
|
if(_nextFreePlayerInventarSlot == 0)
|
|
{
|
|
llOwnerSay(m_lang_freierSlot);
|
|
return;
|
|
}
|
|
|
|
if(_itemName == "")
|
|
{
|
|
llOwnerSay(m_lang_slotLeer);
|
|
return;
|
|
}
|
|
|
|
_dataUserStorage = setDataEntryInDataList(_dataUserStorage, "inventar.slot." + _nextFreePlayerInventarSlot, _itemName);
|
|
_dataUserStorage = setDataEntryInDataList(_dataUserStorage, "inventar.slot." + _nextFreePlayerInventarSlot + ".count", getItemCountFromPlayer(_dataUserStorage, _nextFreePlayerInventarSlot) + 1);
|
|
|
|
integer _itemCount = (integer)getDataEntryFromDataList(_dataStorage, "inventar.slot." + llList2String(m_last_touch, 2) + ".count") - 1;
|
|
_dataStorage = setDataEntryInDataList(_dataStorage, "inventar.slot." + llList2String(m_last_touch, 2) + ".count", (string)_itemCount);
|
|
|
|
if(_itemCount == 0)
|
|
_dataStorage = setDataEntryInDataList(_dataStorage, "inventar.slot." + llList2String(m_last_touch, 2), "");
|
|
|
|
saveDataListToDataStorage(_dataStorage, "game.inventar.objekt." + m_storage_id + ".inventar");
|
|
saveDataListToDataStorage(_dataUserStorage, "game.hud.player." + id);
|
|
|
|
llSay((integer)getDataEntryFromDataList(_dataUserStorage, "channel"), "gamecommand;reload");
|
|
llSay(m_channel_public, "gamecommand;reload");
|
|
refreshData();
|
|
return;
|
|
}
|
|
|
|
if(message == m_lang_lagern)
|
|
{
|
|
|
|
string _selectedItem = getDataEntryFromDataList(_dataUserStorage, "inventar.slot." + _playerSlot);
|
|
integer _itemCount = (integer)getDataEntryFromDataList(_dataStorage, "inventar.slot." + llList2String(m_last_touch, 2) + ".count") + 1;
|
|
|
|
if(_selectedItem != _itemName && _itemName != "")
|
|
{
|
|
llOwnerSay(m_lang_gleicheItems);
|
|
return;
|
|
}
|
|
|
|
if(_selectedItem == "")
|
|
{
|
|
llOwnerSay("Du hast kein Item ausgewählt.");
|
|
return;
|
|
}
|
|
|
|
_dataStorage = setDataEntryInDataList(_dataStorage, "inventar.slot." + llList2String(m_last_touch, 2), _selectedItem);
|
|
_dataStorage = setDataEntryInDataList(_dataStorage, "inventar.slot." + llList2String(m_last_touch, 2) + ".count", _itemCount);
|
|
|
|
_dataUserStorage = setDataEntryInDataList(_dataUserStorage, "inventar.slot." + _playerSlot, _selectedItem);
|
|
_dataUserStorage = setDataEntryInDataList(_dataUserStorage, "inventar.slot." + _playerSlot + ".count", getItemCountFromPlayer(_dataUserStorage, _playerSlot) - 1);
|
|
|
|
if(getItemCountFromPlayer(_dataUserStorage, _playerSlot) <= 0)
|
|
{
|
|
_dataUserStorage = setDataEntryInDataList(_dataUserStorage, "inventar.slot." + _playerSlot, "");
|
|
_dataUserStorage = setDataEntryInDataList(_dataUserStorage, "inventar.slot." + _playerSlot + ".count", "0");
|
|
}
|
|
|
|
saveDataListToDataStorage(_dataStorage, "game.inventar.objekt." + m_storage_id + ".inventar");
|
|
saveDataListToDataStorage(_dataUserStorage, "game.hud.player." + id);
|
|
|
|
llSay((integer)getDataEntryFromDataList(_dataUserStorage, "channel"), "gamecommand;reload");
|
|
llSay(m_channel_public, "gamecommand;reload");
|
|
refreshData();
|
|
return;
|
|
}
|
|
}
|
|
|
|
run_time_permissions( integer vBitPermissions )
|
|
{
|
|
if( vBitPermissions & PERMISSION_ATTACH )
|
|
llAttachToAvatarTemp( ATTACH_HUD_TOP_CENTER );
|
|
}
|
|
|
|
attach(key id)
|
|
{
|
|
if(id != NULL_KEY)
|
|
llSetPos(<0, 0, -0.2>);
|
|
}
|
|
|
|
touch_start(integer i)
|
|
{
|
|
m_last_touch = llParseString2List(llGetLinkName(llDetectedLinkNumber(0)), ["-"], []);
|
|
|
|
//Nummer des Inventar Slot
|
|
integer _inventarSlot = (integer)llList2String(m_last_touch, 2);
|
|
|
|
list _dataStorage = getDataListFromDataStorage("game.inventar.objekt." + m_storage_id + ".inventar");
|
|
list _dataUserStorage = getDataListFromDataStorage("game.hud.player." + llDetectedKey(0));
|
|
|
|
string _playerSlot = getDataEntryFromDataList(_dataUserStorage, "selected");
|
|
|
|
string _itemName = getDataEntryFromDataList(_dataStorage, "inventar.slot." + _inventarSlot);
|
|
integer _itemCount = (integer)getDataEntryFromDataList(_dataStorage, "inventar.slot." + _inventarSlot + ".count");
|
|
|
|
list _dataItemStorage = getDataListFromDataStorage("item." + _itemName);
|
|
|
|
string _displayName = getDataEntryFromDataList(_dataItemStorage, "displayname");
|
|
|
|
if(llList2String(m_last_touch, 0) == "button" && llList2String(m_last_touch, 1) == "close")
|
|
osForceDetachFromAvatar();
|
|
|
|
if(llList2String(m_last_touch, 0) == "inv" && llList2String(m_last_touch, 1) == "slot")
|
|
{
|
|
list _buttons = [m_lang_mitnehmen];
|
|
string _beschreibung = osFormatString(m_lang_fullSlotDesc, [_displayName]);
|
|
|
|
if(getDataEntryFromDataList(_dataUserStorage, "inventar.slot." + _playerSlot) == _itemName)
|
|
_buttons += [m_lang_lagern];
|
|
|
|
if(_itemCount == 0)
|
|
{
|
|
_buttons = [m_lang_lagern];
|
|
_beschreibung = m_lang_emptrySlotDesc;
|
|
}
|
|
|
|
llDialog(llDetectedKey(0), _beschreibung, _buttons, m_channel_private);
|
|
}
|
|
}
|
|
}
|
|
|
|
integer Key2AppChan(key ID, integer App)
|
|
{
|
|
return 0x80000000 | ((integer)("0x"+(string)ID) ^ App);
|
|
}
|
|
|
|
string left(string src, string divider)
|
|
{
|
|
integer index = llSubStringIndex( src, divider );
|
|
if(~index)return llDeleteSubString( src, index, -1);
|
|
return src;
|
|
}
|
|
|
|
string right(string src, string divider)
|
|
{
|
|
integer index = llSubStringIndex( src, divider );
|
|
if(~index)return llDeleteSubString( src, 0, index + llStringLength(divider) - 1);
|
|
return src;
|
|
}
|
|
|
|
key getInventarObjectImageKey(string objektName)
|
|
{
|
|
list _dataStorage = getDataListFromDataStorage("item." + objektName);
|
|
|
|
string _image = getDataEntryFromDataList(_dataStorage, "image");
|
|
|
|
if(_image == "")
|
|
return TEXTURE_BLANK;
|
|
|
|
return (key)_image;
|
|
}
|
|
|
|
|
|
setInventarSlotImage(integer slot, key imageID, integer alpha)
|
|
{
|
|
if(getDataEntryFromDataList(m_current, "state.slot."+ slot) != (string)imageID)
|
|
{
|
|
integer _linkCount = osGetLinkNumber("inv-slot-" + slot);
|
|
llSetLinkAlpha(_linkCount, alpha, 4);
|
|
llSetLinkTexture(_linkCount, imageID, 4);
|
|
|
|
m_current = setDataEntryInDataList(m_current, "state.slot."+ slot, (string)imageID);
|
|
}
|
|
}
|
|
|
|
setInventarSlotCountNumber(integer slot, integer count)
|
|
{
|
|
if(getDataEntryFromDataList(m_current, "state.slot."+ slot +".count") != (string)count)
|
|
{
|
|
integer _linkCount = osGetLinkNumber("inv-number-" + slot);
|
|
|
|
if(count != 0)
|
|
llSetLinkPrimitiveParamsFast(_linkCount, [PRIM_TEXT, (string)count, <1, 1, 0.5>, 1.0]);
|
|
|
|
if(count == 0)
|
|
llSetLinkPrimitiveParamsFast(_linkCount, [PRIM_TEXT, "", <0, 0, 0>, 0.0]);
|
|
|
|
m_current = setDataEntryInDataList(m_current, "state.slot."+ slot +".count", (string)count);
|
|
}
|
|
}
|
|
|
|
//DATA STORE LOGIC
|
|
|
|
list getDataListFromDataStorage(string _storage)
|
|
{
|
|
return llCSV2List(osGetDataValue(_storage));
|
|
}
|
|
|
|
saveDataListToDataStorage(list _dataList, string _storage)
|
|
{
|
|
string _csv = llList2CSV(_dataList);
|
|
osSetDataValue(_storage, _csv);
|
|
}
|
|
|
|
integer checkDataEntryInDataList(list _dataList, string _key)
|
|
{
|
|
integer _inListPosition = llListFindList(_dataList, [_key]);
|
|
|
|
if(_inListPosition == -1)
|
|
return FALSE;
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
string getDataEntryFromDataList(list _dataList, string _key)
|
|
{
|
|
integer _inListPosition = llListFindList(_dataList, [_key]);
|
|
|
|
if(_inListPosition == -1)
|
|
return "";
|
|
|
|
return llList2String(_dataList, _inListPosition + 1);
|
|
}
|
|
|
|
list setDataEntryInDataList(list _dataList, string _key, string _value)
|
|
{
|
|
integer _inListPosition = llListFindList(_dataList, [_key]);
|
|
|
|
if(_inListPosition == -1)
|
|
{
|
|
_dataList += [_key, _value];
|
|
return _dataList;
|
|
}
|
|
|
|
return llListReplaceList(_dataList, [_value], _inListPosition + 1, _inListPosition + 1);
|
|
}
|