
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
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
Code: Select all
apple_altar.surface:addItem(spawn("apple").item)
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,
},
}
}
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)
end
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
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