Scripts help pls part 3 - SOLVED
Posted: Mon Jan 26, 2015 11:49 am
Hi folks. Whoever will help with some scripting will be credited and also receive extra reward in my mod 
1. script which will check all champ inventories for items called charm1, charm2, charm3 and charm4. If all are found, then destroy all and do something (hudprint "quest completed") - SOLVED by AdrTru
2. similar script, which will check all inventories for item "rock" (stackable). If found, then do random math 10% - if succeed, remove 1 rock from the stack. If not succeed, or no rock remaining, do nothing. - SOLVED by AdrTru
3. easy script, which will spawn object called "apple" on altar called "apple_altair" - SOLVED by Frenchie
4. It is somehow possible to limit object healing_crystal to be able heal for example only two times (that it will be not charged again) ? - SOLVED by AdrTru
5. script which will move party one square forward - SOLVED by Frenchie
or another solution advised by minmay
6. I have counter which will have different values during game play. What I need is script which will check if champion named "Drakkan" is in the party and then check for value of the counter. If value is for example 1 (and champion is in the party), then hudprint "something first...", if value of counter is 2 then hudpprint "something two" etc... if "drakkan" is not present or counter has some not defined value, do nothing.
so for example trigger will check - if champ drakkan is in party and value counter == 3 then hudprint... else do nothing
SOLVED by Frenchie
thanks for any help
1. script which will check all champ inventories for items called charm1, charm2, charm3 and charm4. If all are found, then destroy all and do something (hudprint "quest completed") - SOLVED by AdrTru
SpoilerShow
Code: Select all
function getPartyItems()
local i,j,a,entity
local tab = {}
for i = 1,4 do
local champion = party.party:getChampion(i)
for j = 1,32 do
local ent = champion:getItem(j)
if ent ~= nil then
ent = ent.go
if tab[ent.name]==nil then tab[ent.name] = {} end
table.insert(tab[ent.name],{ent.id,i,j,nil})
if ent.containeritem ~= nil then
local box = ent.containeritem
for a = 1,box:getCapacity() do
local iitem = box:getItem(a)
if iitem ~= nil then
if tab[iitem.go.name]==nil then tab[iitem.go.name] = {} end
table.insert(tab[iitem.go.name],{iitem.go.id,i,j,a})
end
end
end
end
end
end
return tab
end
function scRocks()
local v,champ,box,ent
local tab = getPartyItems()
if tab.rock == nil then return false end
for _,v in ipairs(tab.rock) do
box = nil
if math.random(100)<101 then
champ = party.party:getChampion(v[2])
ent = champ:getItem(v[3])
if v[4] ~= nil then
box = ent.go.containeritem
ent = box:getItem(v[4])
end
if ent:getStackSize() == 1 then
if v[4] == nil then champ:removeItemFromSlot(v[3]) else box:removeItemFromSlot(v[4]) end
else ent:setStackSize(ent:getStackSize()-1) end
end
end
end
function scCharm()
local charms = {"charm_1","charm_2","charm_3","charm_4"}
local champ,box,ent
local tab = getPartyItems()
local ok = chooseItems(tab,charms,true)
if ok == false then return false end
for _,ch in ipairs(charms) do
print(ch)
for k,v in pairs(tab[ch]) do
champ = party.party:getChampion(v[2])
ent = champ:getItem(v[3])
if v[4] ~= nil then
box = ent.go.containeritem
ent = box:getItem(v[4])
end
if v[4] == nil then champ:removeItemFromSlot(v[3]) else box:removeItemFromSlot(v[4]) end
end
end
hudPrint("quest completed")
end
function chooseItems(tab,items,allOf)
if type(items) == "string" then items = {items} end
local ok = true
local v
for _,v in ipairs(items) do
if tab[v] == nil then ok = false end
end
if (allOf and ok) or (allOf ~= true) then ok = true else ok = false end
return ok
end
3. easy script, which will spawn object called "apple" on altar called "apple_altair" - SOLVED by Frenchie
SpoilerShow
Code: Select all
apple_altar.surface:addItem(spawn("apple").item)SpoilerShow
Code: Select all
defineObject{
name = "healing_crystal_2use",
baseObject = "healing_crystal",
components = {
{
class = "Counter",
name = "counter",
onActivate = function(self)
self.go.clickable:disable()
self.go.crystal:setCooldown(math.huge)
end,
onInit = function(self)
self:setValue(2);
end,
},
{
class = "Clickable",
offset = vec(0, 1.5, 0),
size = vec(1.6, 2, 1.6),
maxDistance = 1,
onClick = function(self)
if self.go.crystal:isEnabled() then self.go.counter:decrement() end
end,
},
}
}SpoilerShow
5) I can directly help you as I already made the script:
Code: Select all
function Move(st)
fa = party.facing
le = party.level
xx = party.x
yy = party.y
zz = party.elevation
dx, dy = getForward(fa)
party:setPosition(xx + dx * st, yy + dy * st, fa, zz, le)
endSpoilerShow
Code: Select all
party.party:knockback(party.facing)so for example trigger will check - if champ drakkan is in party and value counter == 3 then hudprint... else do nothing
SOLVED by Frenchie
SpoilerShow
Code: Select all
message = { "something first", "something two" }
for i = 1,4 do if party.party:getChampion( i ):getName() == "Drakkan" and counter < 3 then hudprint ( message [ counter ] ) end end