Jump to content

[TFS 1.2] Exercise Weapons


rod_doidim
 Share

Recommended Posts

Olá pessoal, essa é a primeira versão do "Exercise Weapons",

 

Sinta-se livre para sugerir modificações e ajudar a melhorá-lo!
Caso você não tenha as sprites, pode usar outras, como a "Training Dummy" e outros items correspondentes.



[IMG] 


Crie o arquivo exercise_training.lua

local skills = {
	[26397] = {id=SKILL_SWORD,voc=4},
	[26398] = {id=SKILL_AXE,voc=4},
	[26399] = {id=SKILL_CLUB,voc=4},
	[26400] = {id=SKILL_DISTANCE,voc=3,range=CONST_ANI_SIMPLEARROW},
	[26401] = {id=SKILL_MAGLEVEL,voc=2,range=CONST_ANI_ENERGY},
	[26402] = {id=SKILL_MAGLEVEL,voc=1,range=CONST_ANI_FIRE},
}

------- CONFIG -----//
local dummies = {26403,26404}
local skill_gain = 1 -- per hit
local gain_stamina = 60

local function start_train(pid,start_pos,itemid,fpos)
	local player = Player(pid)
	if player ~= nil then
		local pos_n = player:getPosition()

		if start_pos:getDistance(pos_n) == 0 and getTilePzInfo(pos_n) then
			if player:getItemCount(itemid) >= 1 then
				local exercise = player:getItemById(itemid,true)

				if exercise:isItem() then
					if exercise:hasAttribute(ITEM_ATTRIBUTE_CHARGES) then
						local charges_n = exercise:getAttribute(ITEM_ATTRIBUTE_CHARGES)

						if charges_n >= 1 then
							exercise:setAttribute(ITEM_ATTRIBUTE_CHARGES, (charges_n-1))

							local required = 0
							local currently = 0
							local voc = player:getVocation()

							if skills[itemid].id == SKILL_MAGLEVEL then
								required = voc:getRequiredManaSpent(player:getBaseMagicLevel() + 1)/skill_gain
								currently = player:getManaSpent()
								player:addManaSpent(required - currently)
							else
								required = voc:getRequiredSkillTries(skills[itemid].id, player:getSkillLevel(skills[itemid].id)+1)/skill_gain
								currently = player:getSkillTries(skills[itemid].id)

								player:addSkillTries(skills[itemid].id, (required - currently))
							end

							fpos:sendMagicEffect(CONST_ME_HITAREA)
							if skills[itemid].range then
								pos_n:sendDistanceEffect(fpos, skills[itemid].range)
							end
						    player:setStamina(player:getStamina() + 60)

						    if charges_n == 1 then 
								exercise:remove(1)
								return true
						    end
							local training = addEvent(start_train, voc:getAttackSpeed(), pid,start_pos,itemid,fpos)
						else
							exercise:remove(1)
							stopEvent(training)
						end
					end
				end
			end
		else
			stopEvent(training)
		end
	else
		stopEvent(training)
	end
	return true
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
	local start_pos = player:getPosition()

	if target:isItem() then
		if isInArray(dummies,target:getId()) then
			if not skills[item.itemid].range and (start_pos:getDistance(target:getPosition()) > 1) then
				stopEvent(training)
				return false
			end
			if not player:getVocation():getId() == skills[item.itemid].voc or not player:getVocation():getId() == (skills[item.itemid].voc+4) then
				stopEvent(training)
				return false
			end
		    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You started training.")
			start_train(player:getId(),start_pos,item.itemid,target:getPosition())
		end
	end

	return true
end

 

Adicione essa linha em actions.xml

 <!-- Training -->
    <action fromid="26397" toid="26402" script="exercise_training.lua" allowfaruse="1"/>

 

Em events.xml 

- Você vai alterar a parte (enable="0" para "1")

<event class="Player" method="onTradeRequest" enabled="1" />

 

Em /events/scripts/player.lua
Adicione essa linha no início do arquivo

local exercise_ids = {26397,26398,26399,26400,26401,26402}


- Agora vá até a função function Player:eek:MoveItem e adicione abaixo:

   -- Exercise Weapons
    if isInArray(exercise_ids,item.itemid) then
        self:sendCancelMessage('You cannot move this item outside this container.')
        return false
    end


- Na função function Player:eek:OnTradeRequest adicione essa linha abaixo:

 
if isInArray(exercise_ids,item.itemid) then
        return false
    end

 

 

Espero que gostem e seja útil.

Link to comment
Share on other sites

  • 4 months later...
  • 1 month later...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...