Unknown Soldier
Mapping a map
- Joined
- Oct 30, 2010
- Messages
- 297
- Solutions
- 11
- Reaction score
- 670
Hello,
After few failed trials, I give up. I would want to change the exercise training script so that it would allow players to use the weapons BOTH from their store inbox right away, without a need of moving them into inventory first, and preserve the ability to use them from the backpack in inventory too. I thought that as soon as I would get the item id/count from the store inbox after iterating it, things would go easier afterwards, but they made me stuck.
What I got so far? Lines 47-65 - those are the lines that iterates through the players store inbox.
And problematic to me are the lines 72-79 (and probably later the lines with exercise:remove(1) and/or exercise:setAttribute...).
So if the script finds the certain weapon in store inbox, it should allow to go further into the script, thus allowing the training. Instead of
I've tried things like
or some others... But no success, and the line
is giving me contstant errors. Could anyone take a look at this?
Thanks in advance
After few failed trials, I give up. I would want to change the exercise training script so that it would allow players to use the weapons BOTH from their store inbox right away, without a need of moving them into inventory first, and preserve the ability to use them from the backpack in inventory too. I thought that as soon as I would get the item id/count from the store inbox after iterating it, things would go easier afterwards, but they made me stuck.
What I got so far? Lines 47-65 - those are the lines that iterates through the players store inbox.
And problematic to me are the lines 72-79 (and probably later the lines with exercise:remove(1) and/or exercise:setAttribute...).
So if the script finds the certain weapon in store inbox, it should allow to go further into the script, thus allowing the training. Instead of
local exercise = player:getItemById(itemid,true)
I've tried things like
local exercise = storeInbox:getItemById(itemid,true)
or some others... But no success, and the line
if exercise:isItem() then
is giving me contstant errors. Could anyone take a look at this?
Thanks in advance
Lua:
local skills = {
--shields
[41860] = {id=SKILL_SHIELD,voc=4}, -- KNIGHT
[41861] = {id=SKILL_SHIELD,voc=4}, -- KNIGHT
[41862] = {id=SKILL_SHIELD,voc=4}, -- KNIGHT
[41863] = {id=SKILL_SHIELD,voc=4}, -- KNIGHT
--training weapons
[31196] = {id=SKILL_SWORD,voc=4}, -- KNIGHT
[31197] = {id=SKILL_AXE,voc=4}, -- KNIGHT
[31198] = {id=SKILL_CLUB,voc=4}, -- KNIGHT
[31199] = {id=SKILL_DISTANCE,voc=3,range=CONST_ANI_SIMPLEARROW}, -- PALADIN
[31200] = {id=SKILL_MAGLEVEL,voc=2,range=CONST_ANI_ENERGY}, -- DRUID
[31201] = {id=SKILL_MAGLEVEL,voc=1,range=CONST_ANI_FIRE}, -- SORCERER
--exercise weapons
[31208] = {id=SKILL_SWORD,voc=4}, -- KNIGHT
[31209] = {id=SKILL_AXE,voc=4}, -- KNIGHT
[31210] = {id=SKILL_CLUB,voc=4}, -- KNIGHT
[31211] = {id=SKILL_DISTANCE,voc=3,range=CONST_ANI_SIMPLEARROW}, -- PALADIN
[31212] = {id=SKILL_MAGLEVEL,voc=2,range=CONST_ANI_ENERGY}, -- DRUID
[31213] = {id=SKILL_MAGLEVEL,voc=1,range=CONST_ANI_FIRE}, -- SORCERER
--durable exercise weapons
[41848] = {id=SKILL_SWORD,voc=4}, -- KNIGHT
[41849] = {id=SKILL_AXE,voc=4}, -- KNIGHT
[41850] = {id=SKILL_CLUB,voc=4}, -- KNIGHT
[41851] = {id=SKILL_DISTANCE,voc=3,range=CONST_ANI_SIMPLEARROW}, -- PALADIN
[41852] = {id=SKILL_MAGLEVEL,voc=2,range=CONST_ANI_ENERGY}, -- DRUID
[41853] = {id=SKILL_MAGLEVEL,voc=1,range=CONST_ANI_FIRE}, -- SORCERER
--lasting exercise weapons
[41854] = {id=SKILL_SWORD,voc=4}, -- KNIGHT
[41855] = {id=SKILL_AXE,voc=4}, -- KNIGHT
[41856] = {id=SKILL_CLUB,voc=4}, -- KNIGHT
[41857] = {id=SKILL_DISTANCE,voc=3,range=CONST_ANI_SIMPLEARROW}, -- PALADIN
[41858] = {id=SKILL_MAGLEVEL,voc=2,range=CONST_ANI_ENERGY}, -- DRUID
[41859] = {id=SKILL_MAGLEVEL,voc=1,range=CONST_ANI_FIRE}, -- SORCERER
}
------- CONFIG -----//
local houseDummies = {31215, 31216, 31217, 31218, 31219, 31220}
local freeDummies = {31214, 31221}
local skillRate = 2*configManager.getNumber(configKeys.RATE_SKILL)
local magicRate = 2*configManager.getNumber(configKeys.RATE_MAGIC)
isTrainingStorage = 4000
local function start_train(pid, start_pos, itemid, tilePosition, bonusDummy, dummyId)
local player = Player(pid)
local hasStoreItem = 0
local storeInbox = player:getStoreInbox()
if not storeInbox then
return false
end
for _, item in ipairs(storeInbox:getItems()) do
if item:getId() == itemid then
hasStoreItem = hasStoreItem + 1
print(hasStoreItem)
end
end
if hasStoreItem >= 1 then
print("got the weapon")
print(itemid) --return item ID of used weapon
else
print("no weapon")
end
if player ~= nil then
-- local pos_n = player:getPosition()
if Tile(tilePosition):getItemById(dummyId) then
local pos_n = player:getPosition()
if start_pos:getDistance(pos_n) == 0 then --and getTilePzInfo(pos_n) then
if player:getItemCount(itemid) >= 1 then
local exercise = player:getItemById(itemid,true)
print(exercise)
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 voc = player:getVocation()
if skills[itemid].id == SKILL_MAGLEVEL then
magicTry = voc:getRequiredManaSpent(player:getBaseMagicLevel() + 1)-player:getManaSpent()
if not bonusDummy then
player:addManaSpent(math.ceil(250*magicRate))
player:addSkillTries(SKILL_SHIELD, 1*skillRate)
else
player:addManaSpent(math.ceil(250*magicRate)*1.1) -- 10%
player:addSkillTries(SKILL_SHIELD, (1*skillRate)*1.1) -- 10%
end
else
if not bonusDummy then
player:addSkillTries(skills[itemid].id, 1*skillRate)
player:addSkillTries(SKILL_SHIELD, 1*skillRate)
else
player:addSkillTries(skills[itemid].id, (1*skillRate)*1.1) -- 10%
player:addSkillTries(SKILL_SHIELD, (1*skillRate)*1.1) -- 10%
end
end
tilePosition:sendMagicEffect(CONST_ME_HITAREA)
if skills[itemid].range then
pos_n:sendDistanceEffect(tilePosition, skills[itemid].range)
end
--player:setStamina(player:getStamina() + 60)
if charges_n == 1 then
exercise:remove(1)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your training weapon has ran out of charges.")
player:setStorageValue(isTrainingStorage, 0)
return true
end
local training = addEvent(start_train, voc:getAttackSpeed(), pid,start_pos,itemid,tilePosition,bonusDummy,dummyId)
player:setStorageValue(isTrainingStorage, 1)
else
exercise:remove(1)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your training weapon has vanished.")
stopEvent(training)
player:setStorageValue(isTrainingStorage, 0)
end
end
end
else
-- player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your training weapon has been lost.")
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Move your training weapon outside store inbox first.")
stopEvent(training)
player:setStorageValue(isTrainingStorage, 0)
end
else
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your training has stopped, you moved.")
stopEvent(training)
player:setStorageValue(isTrainingStorage, 0)
end
else
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your training has stopped, dummy was moved.")
stopEvent(training)
player:setStorageValue(isTrainingStorage, 0)
end
else
stopEvent(training)
if player then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your training has stopped.")
player:setStorageValue(isTrainingStorage, 0)
else
return true
end
end
return true
end
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local start_pos = player:getPosition()
local target_pos = target:getPosition()
if target:isItem() then
if player:getStorageValue(isTrainingStorage) == 1 then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You are already training.")
return true
end
if isInArray(houseDummies,target:getId()) then
if not skills[item.itemid].range and (start_pos:getDistance(target:getPosition()) > 1) then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Get closer to the dummy.")
stopEvent(training)
return true
end
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your training has started (with 10% bonus).")
start_train(player:getId(),start_pos,item.itemid,target:getPosition(), true, target:getId())
elseif isInArray(freeDummies,target:getId()) then
if not skills[item.itemid].range and (start_pos:getDistance(target:getPosition()) > 1) then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Get closer to the dummy.")
stopEvent(training)
return true
end
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your training has started.")
start_train(player:getId(),start_pos,item.itemid,target:getPosition(), false, target:getId())
end
end
return true
end