Reklama
Pokazuje wyniki od 1 do 3 z 3

Temat: [8.4+][Actions] Health Wand

  1. #1

    Data rejestracji
    2006
    Posty
    27
    Siła reputacji
    0

    Domyślny [8.4+][Actions] Health Wand

    Jest to różdżka lecząca, w pełni uzależniona od level'a gracza oraz jego magic level'a.
    Kod:
    local config = 
    {
    level = 8, -- player level required for use wand
    exhaustion = 1 * 1000, --exhaustion in milisecunds
    }
    local exhaust = createConditionObject(CONDITION_EXHAUST)
    setConditionParam(exhaust, CONDITION_PARAM_TICKS, config.exhaustion)
    
    function onUse(cid, item, fromPosition, itemEx, toPosition)
    if (not isPlayer(itemEx.uid)) then
    	return true
    end
    if(isKnight(cid) == TRUE or isPaladin(cid)) then
    	doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, 'You must be druid or sercerer to use this item.')
    	return true
    end
    if(hasCondition(cid, CONDITION_EXHAUST_HEAL)) then
    	doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, 'You are exhausted.')
    	return true
    end
    local playerLevel = getPlayerLevel(cid)
    if (playerLevel < config.level) then
    	doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, 'Your level is too low.')
    	return true
    end
    local playerMana = getPlayerMana(cid)
    if (playerMana < manaForLevel(cid)) then
    	doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, 'You don\'t have enough mana.')
    	return true
    end
    local playerMagic = getPlayerMagLevel(cid)
    local healthTemplate = ((playerLevel * 0.2) * (playerMagic * 0.5))
    local maxHealth = getCreatureMaxHealth(cid)
    local actuallHealth = getCreatureHealth(cid)
    local healthMargin = maxHealth - actuallHealth
    if(healthMargin == 0) then
    	doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, 'You have max health points.')
    	return true
    end
    if (healthTemplate < 10) then
    	healthTemplate = 10
    end
    if (healthTemplate > healthMargin) then
    	healthTemplate = healthMargin
    end
    doSendMagicEffect(toPosition, CONST_ME_MAGIC_BLUE)
    doCreatureAddHealth(cid, healthTemplate)
    doCreatureAddMana(cid, -manaForLevel(cid))
    doCreatureSay(itemEx.uid, "[Health:"..healthTemplate.."][Mana:"..-manaForLevel(cid).."].", TALKTYPE_ORANGE_1)
    doAddCondition(cid, exhaust)
    return true
    end
    
    
    function manaForLevel(cid)
    local level = getPlayerLevel(cid)
    local magLevel = getPlayerMagLevel(cid)
    if (level < 100) then
    	return level * 2 / 4
    else
    	return level * 25 / magLevel
    end
    end
    Kod:
    	<action itemid="7424" event="script" value="healthWand.lua"/>
    Skrypt jest oczywiście mojego autorstwa.
    Ostatnio zmieniony przez Tairens : 24-09-2009, 16:37

  2. #2
    Avatar Voler
    Data rejestracji
    2007
    Wiek
    33
    Posty
    205
    Siła reputacji
    17

    Domyślny

    Może wytłumacz bardziej o co tu biega, co do skryptu to nie widze błędów więc raczej działa.

  3. Reklama
  4. #3
    Avatar Killavus
    Data rejestracji
    2005
    Położenie
    Wrocław
    Wiek
    32
    Posty
    915
    Siła reputacji
    19

    Domyślny

    Człowieku, naucz się robić wcięcia!

    Raz, że bez wcięć wygląda to paskudnie, to jeszcze nic nie widać w takim kodzie. A chyba powinien być w miarę przejrzysty, prawda? No i dobrym zwyczajem byłoby wrzucenie lokalnych zmiennych na górę skryptu - to nie jest ogromny błąd i NIE trzeba tego robić, ale często zwiększa czytelność kodu. O ile w małych skryptach jest to mało ważne, to w większych kodach pisanych strukturalnie to spore ułatwienie - nie muszę szukać po całym kodzie 'a co to do cholery jest healthMargin?!'. ;)

    Tak powinno to poprawnie wyglądać:
    Kod:
    local config = 
    {
      level = 8, -- player level required for use wand
      exhaustion = 1 * 1000, --exhaustion in milisecunds
    }
    local exhaust = createConditionObject(CONDITION_EXHAUST)
    setConditionParam(exhaust, CONDITION_PARAM_TICKS, config.exhaustion)
    
    function onUse(cid, item, fromPosition, itemEx, toPosition)
      local playerMana = getPlayerMana(cid)
      local playerLevel = getPlayerLevel(cid)
      local playerMagic = getPlayerMagLevel(cid)
      local healthTemplate = ((playerLevel * 0.2) * (playerMagic * 0.5))
      local maxHealth = getCreatureMaxHealth(cid)
      local actuallHealth = getCreatureHealth(cid)
      local healthMargin = maxHealth - actuallHealth
      
      if (not isPlayer(itemEx.uid)) then
        return true
      end
      
      if(isKnight(cid) == TRUE or isPaladin(cid)) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, 'You must be druid or sercerer to use this item.')
        return true
      end
      
      if(hasCondition(cid, CONDITION_EXHAUST_HEAL)) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, 'You are exhausted.')
        return true
      end
      
      if (playerLevel < config.level) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, 'Your level is too low.')
        return true
      end
    
      if (playerMana < manaForLevel(cid)) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, 'You don\'t have enough mana.')
        return true
      end
    
      if(healthMargin == 0) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, 'You have max health points.')
        return true
      end
      
      if (healthTemplate < 10) then
        healthTemplate = 10
      end
      if (healthTemplate > healthMargin) then
        healthTemplate = healthMargin
      end
      
      doSendMagicEffect(toPosition, CONST_ME_MAGIC_BLUE)
      doCreatureAddHealth(cid, healthTemplate)
      doCreatureAddMana(cid, -manaForLevel(cid))
      doCreatureSay(itemEx.uid, "[Health:"..healthTemplate.."][Mana:"..-manaForLevel(cid).."].", TALKTYPE_ORANGE_1)
      doAddCondition(cid, exhaust)
      return true
    end
    
    
    function manaForLevel(cid)
      local level = getPlayerLevel(cid)
      local magLevel = getPlayerMagLevel(cid)
      if (level < 100) then
        return level * 2 / 4
      else
        return level * 25 / magLevel
      end
    end
    Pozdrawiam
    Killavus

Reklama

Informacje o temacie

Użytkownicy przeglądający temat

Aktualnie 1 użytkowników przegląda ten temat. (0 użytkowników i 1 gości)

Podobne tematy

  1. dysk laptop log health hd tune
    Przez Old-Era w dziale Sprzęt i oprogramowanie
    Odpowiedzi: 2
    Ostatni post: 20-04-2016, 17:47
  2. Odpowiedzi: 4
    Ostatni post: 13-03-2013, 15:41
  3. Mana potion vs health potion
    Przez gompek w dziale Tibia
    Odpowiedzi: 10
    Ostatni post: 02-09-2010, 20:48
  4. Nowy Wand!!!!!
    Przez Thaw w dziale Tibia
    Odpowiedzi: 13
    Ostatni post: 13-12-2006, 22:20
  5. Red spell wand
    Przez konto usunięte w dziale Tibia
    Odpowiedzi: 8
    Ostatni post: 03-12-2006, 16:43

Zakładki

Zakładki

Zasady postowania

  • Nie możesz pisać nowych tematów
  • Nie możesz pisać postów
  • Nie możesz używać załączników
  • Nie możesz edytować swoich postów
  •