• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Action on item throw?

Forum General

1st Donator Division
Joined
May 6, 2010
Messages
200
Reaction score
1
Location
Toronto, Canada
Is it possible to do an actions script that does X when the item is tossed to the ground?

For example, if I were to toss [item 8840] 5 squares from me, it would start a script or something.

What I really want it to do;
You throw [item 8840] anywhere and it ticks 3 seconds, then blows up, creating a 3x3 explosion and damages everyone in that radius.
It's basically like a grenade.

Also, when you're in PZ, it doesn't tick or blow up when you throw it, to prevent PZ abuse.
 
Yeah, I got your updated script, but there's just 1 problem.

After I changed the area to AREA_CIRCLE2X2, it still does only 1 square explosion.

Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_EXPLOSIONHIT)
function onGetFormulaValues(cid, level, maglevel)
	return -50, -75
end
setCombatCallback(combat, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")
setCombatArea(combat, createCombatArea(AREA_CIRCLE2X2))

local function blowUp(pos, guid)
	pos.stackpos = 1
	while getThingfromPos(pos).uid > 0 do
		local v = getThingfromPos(pos)
		if v.actionid == guid + 100 then
			local p = getPlayerByGUID(guid)
			if p then
				local op = getThingPos(p)
				if op.z ~= pos.z then
					doTeleportThing(p, pos)
				end
				doCombat(p, combat, positionToVariant(pos))
				doTeleportThing(p, op)
			else
				doSendMagicEffect(pos, CONST_ME_POFF)
			end
			doRemoveItem(v.uid)
			pos.stackpos = pos.stackpos - 1
			local k = getThingfromPos(pos)
			if k.itemid == 8046 then
				doRemoveItem(k.uid)
			else
				pos.stackpos = pos.stackpos + 1
				doRemoveItem(getThingfromPos(pos).uid)
			end
			break
		end
		pos.stackpos = pos.stackpos + 1
	end
end

function onAddItem(moveItem, tileItem, position, cid)
	if isPlayer(cid) and not getTileInfo(getThingPos(cid)).protection and not getTileInfo(position).protection and getTileItemByType(position, ITEM_TYPE_TELEPORT).uid < 1 then
		doCreateItem(8046, 1, position)
		doItemSetAttribute(moveItem.uid, "aid", getPlayerGUID(cid) + 100)
		addEvent(blowUp, 3000, position, getPlayerGUID(cid))
		doSendAnimatedText(position, 3, TEXTCOLOR_WHITE)
		addEvent(doSendAnimatedText, 1000, position, 2, TEXTCOLOR_WHITE)
		addEvent(doSendAnimatedText, 2000, position, 1, TEXTCOLOR_WHITE)
	end
end
 
you need to add in data/spells/lib/spells.lua the square at your taste.

example:

Code:
--Circles
AREA_CIRCLE2X2 = {
	{0, 1, 1, 1, 0},
	{1, 1, 1, 1, 1},
	{1, 1, 3, 1, 1},
	{1, 1, 1, 1, 1},
	{0, 1, 1, 1, 0}
}

:p
 
you need to add in data/spells/lib/spells.lua the square at your taste.

example:

Code:
--Circles
AREA_CIRCLE2X2 = {
	{0, 1, 1, 1, 0},
	{1, 1, 1, 1, 1},
	{1, 1, 3, 1, 1},
	{1, 1, 1, 1, 1},
	{0, 1, 1, 1, 0}
}

:p

It is there;

Code:
--Waves
AREA_WAVE4 = {
	{1, 1, 1, 1, 1},
	{0, 1, 1, 1, 0},
	{0, 1, 1, 1, 0},
	{0, 0, 3, 0, 0}
}

AREA_SQUAREWAVE5 = {
	{1, 1, 1},
	{1, 1, 1},
	{1, 1, 1},
	{0, 1, 0},
	{0, 3, 0}
}

AREA_WAVE5 = {
	{0, 1, 1, 1, 0},
	{1, 1, 1, 1, 1},
	{0, 1, 1, 1, 0},
	{0, 0, 1, 0, 0},
	{0, 0, 3, 0, 0}
}

--Diagonal waves
AREADIAGONAL_WAVE4 = {
	{0, 0, 0, 0, 1, 0},
	{0, 0, 0, 1, 1, 0},
	{0, 0, 1, 1, 1, 0},
	{0, 1, 1, 1, 1, 0},
	{1, 1, 1, 1, 1, 0},
	{0, 0, 0, 0, 0, 3}
}

AREADIAGONAL_SQUAREWAVE5 = {
	{1, 1, 1, 0, 0},
	{1, 1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1, 1, 1},
	{1, 3, 1},
	{1, 1, 1}
}

-- Walls
AREA_WALLFIELD = {
	{1, 1, 3, 1, 1}
}

AREADIAGONAL_WALLFIELD = {
	{0, 0, 0, 0, 1},
	{0, 0, 0, 1, 1},
	{0, 1, 3, 1, 0},
	{1, 1, 0, 0, 0},
	{1, 0, 0, 0, 0},
}
 
Ah ;/ You have to put it inside the script (before everything) because tables from spells.lua are only available in spell scripts.
 
I've got a script for a grenade sorta thing actually. you click use on it, toss it somewhere, has a timer, and while it's like that, it's not moveable. I could give it to ya if you want... It does 3x3 I think. Don't think it's perfect cause it doesn't do damage as far as I know, though I tested it on a creature, not on a player.
 
Yeah, it works now, but there's a little unimportant buggo; when you throw this bomb in the water, it disappears the bomb, but the countdown continues and the glitter stays above the water forever.

If you can't fix that, it's no big deal, does no harm to my server.
 
I've got a script for a grenade sorta thing actually. you click use on it, toss it somewhere, has a timer, and while it's like that, it's not moveable. I could give it to ya if you want... It does 3x3 I think. Don't think it's perfect cause it doesn't do damage as far as I know, though I tested it on a creature, not on a player.

Yeah, it works now, but there's a little unimportant buggo; when you throw this bomb in the water, it disappears the bomb, but the countdown continues and the glitter stays above the water forever.

If you can't fix that, it's no big deal, does no harm to my server.

Ehh, not sure if it'd work. It was made for 8.0 and I think the latest versions are missing some of the functions. Nevermind ;D
 
Ah ;/ You have to put it inside the script (before everything) because tables from spells.lua are only available in spell scripts.
stop fail ;
Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_EXPLOSIONHIT)
[B][COLOR="Magneta"]local t = assert(loadfile("data/spells/lib/spells.lua"))
t()[/COLOR][/B]
function onGetFormulaValues(cid, level, maglevel)
	return -50, -75
end
setCombatCallback(combat, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")
setCombatArea(combat, createCombatArea(AREA_CIRCLE2X2))

local function blowUp(pos, guid)
	pos.stackpos = 1
	while getThingfromPos(pos).uid > 0 do
		local v = getThingfromPos(pos)
		if v.actionid == guid + 100 then
			local p = getPlayerByGUID(guid)
			if p then
				local op = getThingPos(p)
				if op.z ~= pos.z then
					doTeleportThing(p, pos)
				end
				doCombat(p, combat, positionToVariant(pos))
				doTeleportThing(p, op)
			else
				doSendMagicEffect(pos, CONST_ME_POFF)
			end
			doRemoveItem(v.uid)
			pos.stackpos = pos.stackpos - 1
			local k = getThingfromPos(pos)
			if k.itemid == 8046 then
				doRemoveItem(k.uid)
			else
				pos.stackpos = pos.stackpos + 1
				doRemoveItem(getThingfromPos(pos).uid)
			end
			break
		end
		pos.stackpos = pos.stackpos + 1
	end
end

function onAddItem(moveItem, tileItem, position, cid)
	if isPlayer(cid) and not getTileInfo(getThingPos(cid)).protection and not getTileInfo(position).protection and getTileItemByType(position, ITEM_TYPE_TELEPORT).uid < 1 then
		doCreateItem(8046, 1, position)
		doItemSetAttribute(moveItem.uid, "aid", getPlayerGUID(cid) + 100)
		addEvent(blowUp, 3000, position, getPlayerGUID(cid))
		doSendAnimatedText(position, 3, TEXTCOLOR_WHITE)
		addEvent(doSendAnimatedText, 1000, position, 2, TEXTCOLOR_WHITE)
		addEvent(doSendAnimatedText, 2000, position, 1, TEXTCOLOR_WHITE)
	end
end
?
 
Last edited:
Back
Top