diff --git a/Main HUD b/Main HUD new file mode 100644 index 0000000..9bd95cf --- /dev/null +++ b/Main HUD @@ -0,0 +1,873 @@ +// 4Creative Game System - Main HUD v0.7.1 + +// ToDo: +// - Gegestände verarbeiten einbauen (Pfeilspitze + Holz = Pfeil) +// - Max. Traglast einbauen (Jedes Item hat einGewicht in seinem Script) +// - Spielername vom Chatter holen +// - Meter bauen +// - Max. Traglast = Level * 2 Gegenstände (In Items einbauen) +// - Anzahl gesammelter Gegenstände vom Level und Zufall abhängig + +// ► ◄ █ ▄ ■ ▲ ▼ © ▓ ░ ─ ↑ ↓ ▲ ▼ ✔ ✘ • ♫ « » + +integer m_min = FALSE; // HUD minimiert? +integer m_num_slots = 8; // Anzahl Slots, die der Spieler hat. +integer m_max_slots = 8; // Anzahl mx. erreichbare Slots (WICHTIG: AUCH IN JEDEM ITEM SETZEN!) +integer m_refreshtime = 190; // Nach welcher Zeit soll das HUD aktualisiert werden. +integer m_listener_socket = 0; +integer m_listener_channel = 0; +list m_last_touch = []; +string m_listener_state = ""; +string m_last_action = ""; + +string m_lang_groupMessage = "Das Sammelsystem ist hier noch nicht eingerichtet! Bitte benutze das Setup-Tool."; +string m_lang_blueBoxDescText = "Was willst du mit '{0}' machen?\n \n{1}"; +string m_lang_useToOther = "Auf wen möchtest du ' {0}' anwenden?"; +string m_lang_deleteConfirm = "Dies ist ein wichtiges, vielleicht sogar ein einzigartiges Item. Bist du dir wirklich sicher dass du dieses Item nicht mehr brauchst?"; +string m_lang_sendToOther = "An wen möchtest Du '{0}' weitergeben?"; +string m_lang_selectActions = "Was möchtest Du mit '{0}' machen?"; +string m_lang_avatarNotOnRegion = "{0} ist nicht mehr auf der Region."; +string m_lang_noFreeSlot = "{0} hat keinen freien Inventarplatz mehr!"; +string m_lang_getItem = "{0} hat Dir {1} gegeben."; +string m_lang_deleteText = "Du hast {0} weggeworfen."; +string m_lang_toHighWeight = "Dies kann nicht mehr getragen werden."; +string m_lang_ja = "JA"; +string m_lang_nein = "NEIN"; +string m_lang_leveltext = "Level: {0} [XP: {1}]"; +string m_lang_init = "Aktualisierung..."; +string m_lang_maxlevel = "Du hast den höchstmöglichen Level (Level {0}) erreicht."; +string m_lang_maxweight = "Sorry, Du kannst nicht mehr tragen."; + string m_lang_newname = "Gib bitte hier Deinen RP Spielernamen ein:"; +string m_lang_kill = "Wegwerfen"; +string m_lang_use = "Benutzen"; +string m_lang_give = "Weitergeben"; +string m_lang_btn_close = "Schließen "; +string m_lang_btn_sound = "Ton ✔"; +string m_lang_btn_sound_on = "Ton ✔"; +string m_lang_btn_sound_off = "Ton ✘"; +string m_lang_btn_messages = "Meldungen ✔"; +string m_lang_btn_messages_on = "Meldungen ✔"; +string m_lang_btn_messages_off = "Meldungen ✘"; +string m_lang_reset = "Zurücksetzen"; +string line = "────────────────────────────────────────"; +list m_dataStore = []; +list m_dataUserStore = []; +list m_current = []; +integer m_playsound = TRUE; + +change_iconsize(integer prim) +{ + string primname = llGetLinkName(prim); + if(primname == llGetObjectName() || llSubStringIndex(primname, "inv-slot") == 0 || primname == "LOGO" || primname == "preferences") + { + vector size = llList2Vector(llGetLinkPrimitiveParams(prim, [PRIM_SIZE]), 0); + llSetLinkPrimitiveParamsFast(prim, [PRIM_SIZE, size - <0.00, size.y - (size.y * 0.8), size.z - (size.z * 0.8)>]); + if(llSubStringIndex(primname, "inv-slot") == 0) + { + if(m_playsound == TRUE) + osPlaySound(LINK_THIS, "inventar", 1); + } + else + { + if(m_playsound == TRUE) + osPlaySound(LINK_THIS, "click", 1); + } + llSleep(0.20); + llSetLinkPrimitiveParamsFast(prim, [PRIM_SIZE, size]); + } +} + +minmax() +{ + m_min = !m_min; + vector minmax_size = llList2Vector(llGetLinkPrimitiveParams(LINK_THIS, [PRIM_SIZE]), 0); + if(m_min == FALSE) + { + llSetLocalRot(llEuler2Rot(<0, 0, 0> * DEG_TO_RAD)); + llSetTimerEvent(m_refreshtime); + refreshData(); + } + + else + { + llSetLocalRot(llEuler2Rot(<0, 180, 0> * DEG_TO_RAD)); + llSetTimerEvent(0); + osMessageAttachments(llGetOwner(), "HIDE", [ATTACH_HEAD], 0); + } +} + + +updateTime(integer _update) +{ + integer _checkTime = llGetUnixTime() - (integer)getDataEntryFromDataList(m_dataUserStore, "stats.lastCheck"); + + integer _food = (integer)getDataEntryFromDataList(m_dataUserStore, "stats.essen"); + integer _xp = (integer)getDataEntryFromDataList(m_dataUserStore, "stats.xp"); + integer _water = (integer)getDataEntryFromDataList(m_dataUserStore, "stats.wasser"); + + integer _updatedStats = FALSE; + + integer _currentMin = 0; + for(_currentMin = 1; _currentMin <= (_checkTime / 60); ++_currentMin) + { + _food = _food - (integer)getDataEntryFromDataList(m_dataUserStore, "stats.levels.sub_food"); + _water = _water - (integer)getDataEntryFromDataList(m_dataUserStore, "stats.levels.sub_water"); + _updatedStats = TRUE; + } + + if(_updatedStats == TRUE) + { + m_dataUserStore = setDataEntryInDataList(m_dataUserStore, "stats.essen", _food); + m_dataUserStore = setDataEntryInDataList(m_dataUserStore, "stats.wasser", _water); + m_dataUserStore = setDataEntryInDataList(m_dataUserStore, "stats.xp", _xp); + m_dataUserStore = setDataEntryInDataList(m_dataUserStore, "stats.lastCheck", llGetUnixTime()); + } + + if(_update == TRUE) + refreshData(); +} + +default +{ + state_entry() + { + llPreloadSound("click"); + llPreloadSound("inventar"); + m_dataStore = getDataListFromDataStorage("game.hud"); + m_dataUserStore = getDataListFromDataStorage("game.hud.player." + llGetOwner()); + + llSetTimerEvent(m_refreshtime); + startGame(); + } + + timer() + { + m_dataStore = getDataListFromDataStorage("game.hud"); + m_dataUserStore = getDataListFromDataStorage("game.hud.player." + llGetOwner()); + m_dataUserStore = setDataEntryInDataList(m_dataUserStore, "stats.lastCheck", llGetUnixTime()); + updateTime(TRUE); + } + + attach(key id) + { + if(id) + { + m_dataStore = getDataListFromDataStorage("game.hud"); + m_dataUserStore = getDataListFromDataStorage("game.hud.player." + llGetOwner()); + + updateTime(FALSE); + startGame(); + } + } + + touch_start(integer i) + { + change_iconsize(llDetectedLinkNumber(0)); + m_dataStore = getDataListFromDataStorage("game.hud"); + m_dataUserStore = getDataListFromDataStorage("game.hud.player." + llGetOwner()); + + m_last_touch = llParseString2List(llGetLinkName(llDetectedLinkNumber(0)), ["-"], []); + m_listener_state = "main"; + + if(llList2String(m_last_touch, 0) == "inv" && llList2String(m_last_touch, 1) == "slot") + { + integer _inventarSlot = llList2String(m_last_touch, 2); + string _inventarItemName = getDataEntryFromDataList(m_dataUserStore, "inventar.slot." + _inventarSlot); + list _inventarItemDataStorage = getDataListFromDataStorage("item." +_inventarItemName); + string _inventarItemDisplayName = getDataEntryFromDataList(_inventarItemDataStorage, "displayname"); + string _inventarItemBeschreibung = getDataEntryFromDataList(_inventarItemDataStorage, "beschreibung"); + + if(_inventarItemName != "") + { + list _aktionen = [m_lang_kill, m_lang_use, m_lang_give]; + + m_dataUserStore = setDataEntryInDataList(m_dataUserStore, "selected", _inventarSlot); + + saveDataListToDataStorage(m_dataUserStore, "game.hud.player." + llGetOwner()); + llDialog(llDetectedKey(0), line + "\n" + osFormatString(m_lang_blueBoxDescText, [_inventarItemDisplayName, _inventarItemBeschreibung]), _aktionen, m_listener_channel); + return; + } + } + else + { + if(llGetLinkName(llDetectedLinkNumber(0)) == llGetObjectName()) + { + change_iconsize(llGetLinkName(llDetectedLinkNumber(0))); + minmax(); + refreshData(); + } + + if(llGetLinkName(llDetectedLinkNumber(0)) == "preferences") + llResetScript(); + + } + } + + listen(integer channel, string name, key id, string message ) + { + m_dataStore = getDataListFromDataStorage("game.hud"); + m_dataUserStore = getDataListFromDataStorage("game.hud.player." + llGetOwner()); + + if(left(message, ";") == "gamecommand") + { + if(right(message, ";") == "reload") + refreshData(); + } + else + { + integer _inventarSlot = llList2String(m_last_touch, 2); + string _inventarItemName = getDataEntryFromDataList(m_dataUserStore, "inventar.slot." + _inventarSlot); + + if(_inventarItemName != "") + { + list _inventarItemDataStorage = getDataListFromDataStorage("item." +_inventarItemName); + string _inventarItemDisplayName = getDataEntryFromDataList(_inventarItemDataStorage, "displayname"); + string _inventarItemDUnique = getDataEntryFromDataList(_inventarItemDataStorage, "unique"); + + if(m_listener_state == "main") + { + if(message == m_lang_kill) + { + if(_inventarItemDUnique != "TRUE") + { + m_dataUserStore = setDataEntryInDataList(m_dataUserStore, "inventar.slot." + _inventarSlot, ""); + m_dataUserStore = setDataEntryInDataList(m_dataUserStore, "inventar.slot." + _inventarSlot + ".count", "0"); + refreshData(); + saveDataListToDataStorage(m_dataUserStore, "game.hud.player." + llGetOwner()); + } + else + { + m_listener_state = "confirmDelete"; + llDialog(llGetOwner(), m_lang_deleteConfirm, [m_lang_ja, m_lang_nein], m_listener_channel); + } + + return; + } + + if(message == m_lang_give) + { + list _avatars = llGetAgentList(AGENT_LIST_REGION, []); + integer _avatarsCount = llGetListLength(_avatars); + list _player = []; + + while(_avatarsCount--) + if(osCheckDataValue("game.hud.player." + llList2String(_avatars, _avatarsCount))) + if(llList2Key(_avatars, _avatarsCount) != llGetOwner()) + _player += [left(left(llKey2Name(llList2String(_avatars, _avatarsCount)), " "), ".")]; + + m_listener_state = "give"; + llDialog(llGetOwner(), osFormatString(m_lang_sendToOther, [_inventarItemDisplayName]), _player, m_listener_channel); + return; + } + + if(message == m_lang_use) + { + list _actionen = []; + + list _inventarItemInternalActions = llParseString2List(getDataEntryFromDataList(_inventarItemDataStorage, "actions"), [";"], []); + integer _inventarItemInternalActionsCount = llGetListLength(_inventarItemInternalActions); + + while(_inventarItemInternalActionsCount--) + { + string _actionName = llList2String(_inventarItemInternalActions, _inventarItemInternalActionsCount); + + if(_actionName != "") + _actionen += [getDataEntryFromDataList(_inventarItemDataStorage, "actions." + _actionName + ".displayname")]; + } + + m_listener_state = "use"; + llDialog(llGetOwner(), osFormatString(m_lang_selectActions, [_inventarItemDisplayName]), _actionen, m_listener_channel); + return; + } + } + else if(m_listener_state == "give") + { + list _allAvatarsInRegion = llGetAgentList(AGENT_LIST_REGION, []); + integer _allAvatarsInRegionCount = llGetListLength(_allAvatarsInRegion); + key _selectedTargetAvatar = NULL_KEY; + + while(_allAvatarsInRegionCount--) + { + string _avatarID = left(left(llKey2Name(llList2String(_allAvatarsInRegion, _allAvatarsInRegionCount)), " "), "."); + + if(_avatarID == message) + _selectedTargetAvatar = llList2Key(_allAvatarsInRegion, _allAvatarsInRegionCount); + } + + if(_selectedTargetAvatar == NULL_KEY) + { + llOwnerSay(osFormatString(m_lang_avatarNotOnRegion, [llKey2Name(_selectedTargetAvatar)])); + return; + } + + list _selectedTargetAvatarDataStorage = getDataListFromDataStorage("game.hud.player." + _selectedTargetAvatar); + integer _selectedTargetAvatarInventarSlot = getInventarSlot(_selectedTargetAvatarDataStorage, _inventarItemName); + + if(_selectedTargetAvatarInventarSlot == 0) + { + llOwnerSay(osFormatString(m_lang_noFreeSlot, [message])); + return; + } + + if(getMaxPlayerWeight(_selectedTargetAvatarDataStorage) < calcPlayerWeight(_selectedTargetAvatarDataStorage)) + { + llOwnerSay(m_lang_toHighWeight); + return; + } + + _selectedTargetAvatarDataStorage = setDataEntryInDataList(_selectedTargetAvatarDataStorage, "inventar.slot." + _selectedTargetAvatarInventarSlot, _inventarItemName); + _selectedTargetAvatarDataStorage = setDataEntryInDataList(_selectedTargetAvatarDataStorage, "inventar.slot." + _selectedTargetAvatarInventarSlot + ".count", getItemCountFromSlot(_selectedTargetAvatarDataStorage, _selectedTargetAvatarInventarSlot) + 1); + + m_dataUserStore = setDataEntryInDataList(m_dataUserStore, "inventar.slot." + _inventarSlot + ".count", (integer)getItemCountFromSlot(m_dataUserStore, _inventarSlot) - 1); + + if(getItemCountFromSlot(m_dataUserStore, _inventarSlot) <= 0) + { + m_dataUserStore = setDataEntryInDataList(m_dataUserStore, "inventar.slot." + _inventarSlot, ""); + m_dataUserStore = setDataEntryInDataList(m_dataUserStore, "inventar.slot." + _inventarSlot + ".count", "0"); + } + + saveDataListToDataStorage(_selectedTargetAvatarDataStorage, "game.hud.player." + _selectedTargetAvatar); + saveDataListToDataStorage(m_dataUserStore, "game.hud.player." + llGetOwner()); + + refreshData(); + llRegionSay((integer)getDataEntryFromDataList(_selectedTargetAvatarDataStorage, "channel"), "gamecommand;reload"); + llRegionSayTo(_selectedTargetAvatar, 0, osFormatString(m_lang_getItem, [llList2String(llParseString2List(llKey2Name(llGetOwner()), [" "], [""]), 0), _inventarItemDisplayName])); + + return; + } + else if(m_listener_state == "use") + { + useAction(_inventarItemName, message, _inventarSlot, llGetOwner(), FALSE); + } + else if(m_listener_state == "confirmDelete") + { + if(message == m_lang_ja) + { + setDataEntryInDataList(m_dataUserStore, "inventar.slot." + _inventarSlot, ""); + setDataEntryInDataList(m_dataUserStore, "inventar.slot." + _inventarSlot + ".count", "0"); + saveDataListToDataStorage(m_dataUserStore, "game.hud.player." + llGetOwner()); + refreshData(); + } + } + else if(m_listener_state == "getTarget") + { + list _allAvatarsInRegion = llGetAgentList(AGENT_LIST_REGION, []); + integer _allAvatarsInRegionCount = llGetListLength(_allAvatarsInRegion); + key _selectedTargetAvatar = NULL_KEY; + + while(_allAvatarsInRegionCount--) + { + string _avatarID = left(left(llKey2Name(llList2String(_allAvatarsInRegion, _allAvatarsInRegionCount)), " "), "."); + + if(_avatarID == message) + _selectedTargetAvatar = llList2Key(_allAvatarsInRegion, _allAvatarsInRegionCount); + } + + if(_selectedTargetAvatar == NULL_KEY) + { + llOwnerSay(osFormatString(m_lang_avatarNotOnRegion, [""])); + return; + } + + useAction(_inventarItemName, m_last_action, _inventarSlot, _selectedTargetAvatar, TRUE); + if(m_playsound == TRUE) + osPlaySound(LINK_THIS, "inventar", 1); + } + } + } + } + + changed(integer change) + { + if(change & CHANGED_TELEPORT) + { + m_dataStore = getDataListFromDataStorage("game.hud"); + refreshData(); + } + } +} + +//Spielfunktionen + +cleanGameState() +{ + if(m_listener_socket != 0) + llListenRemove(m_listener_socket); + + integer i; + for(i = 1; i < m_num_slots; i++) + { + setInventarSlotImage(i, TEXTURE_BLANK, 0); + setInventarSlotCountNumber(i, 0); + } + + setLevelDisplayNumber(0, 0); + setBalkenValue("wasser", 0); + setBalkenValue("essen", 0); + setBalkenValue("xp", 0); + setBalkenValue("hp", 0); + setBalkenValue("weight", 0); +} + + +startGame() +{ + cleanGameState(); + + if(checkDataEntryInDataList(m_dataStore, "enable") == FALSE || getDataEntryFromDataList(m_dataStore, "enable") == "FALSE") + { + llOwnerSay(m_lang_groupMessage); + return; + } + + m_listener_channel = Key2AppChan(llGetOwner(), 39724); + m_listener_socket = llListen(m_listener_channel, "", "", ""); + + m_dataUserStore = setDataEntryInDataList(m_dataUserStore, "channel", m_listener_channel); + m_dataUserStore = setDataEntryInDataList(m_dataUserStore, "player", "true"); + + if(checkDataEntryInDataList(m_dataUserStore, "stats.essen") == FALSE) + m_dataUserStore = setDataEntryInDataList(m_dataUserStore, "stats.essen", "100"); + + if(checkDataEntryInDataList(m_dataUserStore, "stats.wasser") == FALSE) + m_dataUserStore = setDataEntryInDataList(m_dataUserStore, "stats.wasser", "100"); + + if(checkDataEntryInDataList(m_dataUserStore, "stats.xp") == FALSE) + m_dataUserStore = setDataEntryInDataList(m_dataUserStore, "stats.xp", "0"); + + if(checkDataEntryInDataList(m_dataUserStore, "stats.hp") == FALSE) + m_dataUserStore = setDataEntryInDataList(m_dataUserStore, "stats.hp", "100"); + + if(checkDataEntryInDataList(m_dataUserStore, "stats.weight") == FALSE) + m_dataUserStore = setDataEntryInDataList(m_dataUserStore, "stats.weight", "0"); + + if(checkDataEntryInDataList(m_dataUserStore, "stats.lastCheck") == FALSE) + m_dataUserStore = setDataEntryInDataList(m_dataUserStore, "stats.lastCheck", llGetUnixTime()); + + integer i; + for (i = 1; i <= m_num_slots; i++) + { + if(checkDataEntryInDataList(m_dataUserStore, "inventar.slot." + i) == FALSE) + { + m_dataUserStore = setDataEntryInDataList(m_dataUserStore, "inventar.slot." + i, ""); + m_dataUserStore = setDataEntryInDataList(m_dataUserStore, "inventar.slot." + i + ".count", "0"); + } + } + + saveDataListToDataStorage(m_dataUserStore, "game.hud.player." + llGetOwner()); + refreshData(); +} + +integer getInventarSlot(list _userStorage, string itemName) +{ + integer _currentSlot; + integer _freeSlot = 0; + for(_currentSlot = 1; _currentSlot <= m_num_slots; ++_currentSlot) + { + if(getDataEntryFromDataList(_userStorage, "inventar.slot." + _currentSlot) == itemName) + return _currentSlot; + + if(getDataEntryFromDataList(_userStorage, "inventar.slot." + _currentSlot) == "") + if(_freeSlot == 0) + _freeSlot = _currentSlot; + } + + return _freeSlot; +} + +integer getItemCountFromSlot(list _userStorage, integer _slot) +{ + integer _returnValue = (integer)getDataEntryFromDataList(_userStorage, "inventar.slot." + _slot + ".count"); + return _returnValue; +} + +integer calcPlayerWeight(list _userStorage) +{ + integer _currentSlot; + integer _currentWeight = 0; + for(_currentSlot = 1; _currentSlot <= m_num_slots; ++_currentSlot) + { + if(getDataEntryFromDataList(_userStorage, "inventar.slot." + _currentSlot) != "") + { + string _itemName = getDataEntryFromDataList(_userStorage, "inventar.slot." + _currentSlot); + list _itemData = getDataListFromDataStorage("item." +_itemName); + + integer _itemCount = getItemCountFromSlot(_userStorage, _currentSlot); + integer _itemWeight = (integer)getDataEntryFromDataList(_itemData, "weight"); + + _currentWeight = _currentWeight + (_itemCount * _itemWeight); + } + } + + return _currentWeight; +} + +integer getMaxPlayerWeight(list _userDataStorage) +{ + integer _maxweight = (integer)getDataEntryFromDataList(m_dataStore, "stats.levels.maxweight"); + float _xpMultiplier = (float)getDataEntryFromDataList(m_dataStore, "stats.levels.multiplier"); + + list _levelData = calcLevelData(_userDataStorage); + integer _playerLevel = llList2Integer(_levelData, 0) + 1; + + integer _playerMaxWight = _maxweight * (_playerLevel * _xpMultiplier); + + return _playerMaxWight; +} + +list calcLevelData(list _dataStorage) +{ + integer _xpLevelStep = (integer)getDataEntryFromDataList(m_dataStore, "stats.levels.firstStep"); + integer _maxlevel = (integer)getDataEntryFromDataList(m_dataStore, "stats.levels.maxlevel"); + + float _xpLevelStepMultiplier = (float)getDataEntryFromDataList(m_dataStore, "stats.levels.multiplier"); + integer _currentXP = (integer)getDataEntryFromDataList(_dataStorage, "stats.xp"); + integer _currentLevel = 0; + + integer _xpNeedForNextLevel = _xpLevelStep * _xpLevelStepMultiplier; + + while(_currentXP > _xpNeedForNextLevel) + { + if(_currentLevel <= _maxlevel) + { + _currentLevel = _currentLevel + 1; + _currentXP = _currentXP - _xpNeedForNextLevel; + _xpNeedForNextLevel = (_xpNeedForNextLevel * _xpLevelStepMultiplier); + } + } + + return [_currentLevel, (integer)_currentXP, _xpNeedForNextLevel]; +} + + +refreshData() +{ + integer _currentSlot; + for(_currentSlot = 1; _currentSlot <= m_num_slots; ++_currentSlot) + { + if(getDataEntryFromDataList(m_dataUserStore, "inventar.slot." + _currentSlot) != "") + { + integer _count = getDataEntryFromDataList(m_dataUserStore, "inventar.slot." + _currentSlot + ".count"); + setInventarSlotImage(_currentSlot, getInventarObjectImageKey(getDataEntryFromDataList(m_dataUserStore, "inventar.slot." + _currentSlot)), 255); + setInventarSlotCountNumber(_currentSlot, _count); + } + else + { + setInventarSlotImage(_currentSlot, TEXTURE_BLANK, 0); + setInventarSlotCountNumber(_currentSlot, 0); + } + } + + list _levelData = calcLevelData(m_dataUserStore); + //llOwnerSay("leveldata " + llList2CSV(_levelData)); + + setLevelDisplayNumber(llList2Integer(_levelData, 0), llList2Integer(_levelData, 1)); + + float _xpBalkenValue = (float)((100 / llList2Float(_levelData, 2)) * llList2Float(_levelData, 1)); + float _hpBalkenValue = (float)((llList2Integer(_levelData, 0) * 100) / 100); + integer _food = (integer)getDataEntryFromDataList(m_dataUserStore, "stats.essen"); + integer _water = (integer)getDataEntryFromDataList(m_dataUserStore, "stats.wasser"); + integer _hp = (integer)getDataEntryFromDataList(m_dataUserStore, "stats.hp"); + + if(_food > 100) + m_dataUserStore = setDataEntryInDataList(m_dataUserStore, "stats.essen", "100"); + + if(_food < 0) + m_dataUserStore = setDataEntryInDataList(m_dataUserStore, "stats.essen", "0"); + + if(_water > 100) + m_dataUserStore = setDataEntryInDataList(m_dataUserStore, "stats.wasser", "100"); + + if(_water < 0) + m_dataUserStore = setDataEntryInDataList(m_dataUserStore, "stats.wasser", "0"); + + if(_hp > 100) + m_dataUserStore = setDataEntryInDataList(m_dataUserStore, "stats.hp", "100"); + + if(_hp < 0) + m_dataUserStore = setDataEntryInDataList(m_dataUserStore, "stats.hp", "0"); + + setBalkenValue("wasser", (integer)getDataEntryFromDataList(m_dataUserStore, "stats.wasser")); + setBalkenValue("essen", (integer)getDataEntryFromDataList(m_dataUserStore, "stats.essen")); + setBalkenValue("hp", (integer)getDataEntryFromDataList(m_dataUserStore, "stats.hp")); + setBalkenValue("xp", _xpBalkenValue); + setBalkenValue("weight", (integer)getMaxPlayerWeight(getDataListFromDataStorage("game.hud.player." + llGetOwner()))); + + saveDataListToDataStorage(m_dataUserStore, "game.hud.player." + llGetOwner()); + //osMessageAttachments(llGetOwner(), "SHOW" + NAME, [ATTACH_HEAD], 0); + osMessageAttachments(llGetOwner(), "LEVEL:" + (string)llList2Integer(_levelData, 0), [ATTACH_HEAD], 0); + osMessageAttachments(llGetOwner(), "HP:" + getDataEntryFromDataList(m_dataUserStore, "stats.hp"), [ATTACH_HEAD], 0); +} + +useAction(string _itemName, string _actionName, integer _slot, key _avatar, integer _other) +{ + integer _inventarSlot = llList2String(m_last_touch, 2); + string _inventarItemName = getDataEntryFromDataList(m_dataUserStore, "inventar.slot." + _inventarSlot); + + list _targetUserDataStore = getDataListFromDataStorage("game.hud.player." + _avatar); + list _getItems = []; + + m_last_action = _actionName; + + if(_inventarItemName != "") + { + list _inventarItemDataStorage = getDataListFromDataStorage("item." +_inventarItemName); + string _inventarItemDisplayName = getDataEntryFromDataList(_inventarItemDataStorage, "displayname"); + string _inventarItemDUnique = getDataEntryFromDataList(_inventarItemDataStorage, "unique"); + + list _inventarItemInternalActions = llParseString2List(getDataEntryFromDataList(_inventarItemDataStorage, "actions"), [";"], []); + integer _inventarItemInternalActionsCount = llGetListLength(_inventarItemInternalActions); + + while(_inventarItemInternalActionsCount--) + { + string _inventarItemInternalActionName = llList2String(_inventarItemInternalActions, _inventarItemInternalActionsCount); + string _inventarItemInternalActionDisplayname = getDataEntryFromDataList(_inventarItemDataStorage, "actions." + _inventarItemInternalActionName + ".displayname"); + string _inventarItemInternalActionSetTarget = getDataEntryFromDataList(_inventarItemDataStorage, "actions." + _inventarItemInternalActionName + ".setTarget"); + string _inventarItemInternalActionConsume = getDataEntryFromDataList(_inventarItemDataStorage, "actions." + _inventarItemInternalActionName + ".consume"); + + list _inventarItemInternalActionTasks = llParseString2List(getDataEntryFromDataList(_inventarItemDataStorage, "actions." + _inventarItemInternalActionName + ".tasks"), [";"], []); + integer _inventarItemInternalActionTasksCount = llGetListLength(_inventarItemInternalActionTasks); + + if(_inventarItemInternalActionDisplayname == _actionName) + { + if(_inventarItemInternalActionSetTarget != "TRUE" || _other == TRUE) + { + while(_inventarItemInternalActionTasksCount--) + { + string _actionStringAction = left(llList2String(_inventarItemInternalActionTasks, _inventarItemInternalActionTasksCount), ":"); + string _actionStringArgs = right(llList2String(_inventarItemInternalActionTasks, _inventarItemInternalActionTasksCount), ":"); + + if(_actionStringAction == "say") + llDialog(_avatar, " \n \n" + _actionStringArgs, [], -1); + + if(_actionStringAction == "addFood") + _targetUserDataStore = setDataEntryInDataList(_targetUserDataStore, "stats.essen", (integer)getDataEntryFromDataList(_targetUserDataStore, "stats.essen") + (integer)_actionStringArgs); + + if(_actionStringAction == "addWater") + _targetUserDataStore = setDataEntryInDataList(_targetUserDataStore, "stats.wasser", (integer)getDataEntryFromDataList(_targetUserDataStore, "stats.wasser") + (integer)_actionStringArgs); + + if(_actionStringAction == "addXP") + _targetUserDataStore = setDataEntryInDataList(_targetUserDataStore, "stats.xp", (integer)getDataEntryFromDataList(_targetUserDataStore, "stats.xp") + (integer)_actionStringArgs); + + if(_actionStringAction == "addHP") + _targetUserDataStore = setDataEntryInDataList(_targetUserDataStore, "stats.hp", (integer)getDataEntryFromDataList(_targetUserDataStore, "stats.hp") + (integer)_actionStringArgs); + + if(_actionStringAction == "getItem") + _getItems += [_actionStringArgs]; + + if(_actionStringAction == "contextSwitch") + { + saveDataListToDataStorage(_targetUserDataStore, "game.hud.player." + _avatar); + _targetUserDataStore = getDataListFromDataStorage("game.hud.player." + llGetOwner()); + _avatar = llGetOwner(); + } + + if(_actionStringAction == "attach") + llRegionSay((integer)_actionStringArgs, "attach|" + _avatar); + + if(_actionStringAction == "custom") + { + integer customChannel = (integer)left(_actionStringArgs, ","); + string customText = right(_actionStringArgs, ","); + llRegionSay(customChannel, customText); + } + } + + integer _getItemsListCount = llGetListLength(_getItems); + while(_getItemsListCount--) + { + string _getItemsName = left(llList2String(_getItems, _getItemsListCount), "="); + string _getItemsCount = right(llList2String(_getItems, _getItemsListCount), "="); + + integer _invSlot = getInventarSlot(_targetUserDataStore, _getItemsName); + + if(_invSlot == 0) + { + llRegionSayTo(_avatar, 0, osFormatString(m_lang_noFreeSlot, [_getItemsName])); + return; + } + + _targetUserDataStore = setDataEntryInDataList(_targetUserDataStore, "inventar.slot." + _invSlot, _getItemsName); + _targetUserDataStore = setDataEntryInDataList(_targetUserDataStore, "inventar.slot." + _invSlot + ".count", (integer)getItemCountFromSlot(_targetUserDataStore, _invSlot) + (integer)_getItemsCount); + + } + + saveDataListToDataStorage(_targetUserDataStore, "game.hud.player." + _avatar); + m_dataUserStore = getDataListFromDataStorage("game.hud.player." + llGetOwner()); + + if(_inventarItemInternalActionConsume == "TRUE") + { + m_dataUserStore = setDataEntryInDataList(m_dataUserStore, "inventar.slot." + _inventarSlot + ".count", (integer)getItemCountFromSlot(m_dataUserStore, _inventarSlot) - 1); + + if(getItemCountFromSlot(m_dataUserStore, _inventarSlot) <= 0) + { + m_dataUserStore = setDataEntryInDataList(m_dataUserStore, "inventar.slot." + _inventarSlot, ""); + m_dataUserStore = setDataEntryInDataList(m_dataUserStore, "inventar.slot." + _inventarSlot + ".count", ""); + } + } + + saveDataListToDataStorage(m_dataUserStore, "game.hud.player." + llGetOwner()); + + if(_other == TRUE) + llRegionSay((integer)getDataEntryFromDataList(_targetUserDataStore, "channel"), "gamecommand;reload"); + + refreshData(); + } + else + { + m_listener_state = "getTarget"; + + list _allAvatarsInRegion = llGetAgentList(AGENT_LIST_REGION, []); + integer _allAvatarsInRegionCount = llGetListLength(_allAvatarsInRegion); + list _player = []; + + while(_allAvatarsInRegionCount--) + if(osCheckDataValue("game.hud.player." + llList2String(_allAvatarsInRegion, _allAvatarsInRegionCount))) + _player += [left(left(llKey2Name(llList2String(_allAvatarsInRegion, _allAvatarsInRegionCount)), " "), ".")]; + + llDialog(_avatar, osFormatString(m_lang_useToOther, [_inventarItemInternalActionDisplayname]), _player, m_listener_channel); + } + } + } + } +} + + +key getInventarObjectImageKey(string objektName) +{ + list _inventarItemDataStorage = getDataListFromDataStorage("item." + objektName); + string _inventarItemImage = getDataEntryFromDataList(_inventarItemDataStorage, "image"); + + if(_inventarItemImage != "") + return (key)_inventarItemImage; + + return TEXTURE_BLANK; +} + +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); + } +} + +setBalkenValue(string balken, integer count) // integer max +{ + if(getDataEntryFromDataList(m_dataStore, "stats.enable") != "TRUE") + count = 0; + + if(getDataEntryFromDataList(m_current, "balken."+ balken) != (string)count) + { + integer _linkCount = osGetLinkNumber("display-balken-" + balken); + + if(count != 0) + llSetLinkAlpha(_linkCount, 255, 4); + + if(count == 0) + llSetLinkAlpha(_linkCount, 0, 4); + + float _balkenValue = (1.0 / 100) * count; + llSetLinkPrimitiveParamsFast(_linkCount, [PRIM_SLICE,< 0, _balkenValue, 0>]); + + m_current = setDataEntryInDataList(m_current, "balken."+ balken, (string)count); + } +} + +setInventarSlotCountNumber(integer slot, integer count) +{ + if(m_min == TRUE) + count = 0; + + 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); + } +} + +setLevelDisplayNumber(integer level, integer xp) +{ + if(getDataEntryFromDataList(m_current, "level") != (string)level + (string)xp + (string)m_min) + { + integer _linkCount = osGetLinkNumber("level-anzeige"); + llSetLinkPrimitiveParamsFast(_linkCount, [PRIM_TEXT, osFormatString(m_lang_leveltext, [(string)level, (string)xp]), <0, 1, .2>, !m_min]); + m_current = setDataEntryInDataList(m_current, "level", (string)level + (string)xp) + (string)m_min; + } +} + +//Hilfsfunktionen + +integer Key2AppChan(key ID, integer App) +{ + return 0x80000000 | ((integer)("0x"+(string)ID) ^ App); +} + +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); +} + +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; +} \ No newline at end of file