• 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!

Script summon monster from item with charges

Jester753

New Member
Joined
Jun 15, 2012
Messages
30
Reaction score
0
This script should summon a demon from a lamp, 3 times then run out of charges but it won't work.

heres my code:

local config=
{
monster="Demon"
i=3
}

function onUse(cid, item, frompos, itemEx, topos)
if config.i >0 then
if item.itemid == 2063 then
doSummonCreature(config.demon, getCreaturePosition(cid))
config.i-1
doPlayerSendTextMessage(cid,21,"It works !")
else
doPlayerSendTextMessage(cid, 21, "It still doesn't work!")
end
else
doPlayerSendTextMessage(cid, 21, "Your item has ran out of charges")
end

return TRUE
end


thanks
 
Sorry no time to test it but i managed to fix the error:

Lua:
local otswe= {
create_monster = "Demon"
}

function onUse(cid, item, frompos, itemEx, topos)
if item.itemid == 2063 then
doSummonCreature(otswe.create_monster, getCreaturePosition(cid))
doPlayerSendTextMessage(cid,21,"You have summoned 1 Demon!")
else
doPlayerSendTextMessage(cid, 21, "It still doesn't work!")
end
return true
end
 
Last edited:
Lua:
local config = {
   monsterName = "Demon",
   charges = 3
}
 
function onUse(cid, item, frompos, itemEx, topos)
   if item.itemid ~= 2063 then
      return false
   end

   if config.charges > 0 then
      config.charges -= 1
      doSummonCreature(config.monsterName, getCreaturePosition(cid))
      doPlayerSendTextMessage(cid, 21, "You rub the lamp. A dark force rises to obey your every command.")
   else
      doPlayerSendTextMessage(cid, 21, "Your item has ran out of charges")
   end
   return true
end

Fixed some obvious mistakes, but this probably still won't work.
 
This may be the one you are looking for.
Lua:
function onUse(cid, item, frompos, item2, topos)
	local charges = 3
	local mob = "Demon"
	local maxSummons = 1
	
	if(getPlayerStorageValue(cid, item.itemid) < charges) then
		if(getTilePzInfo(getCreaturePosition(cid)) == false) then
			if(table.maxn(getCreatureSummons(cid)) < maxSummons) then
				doSummonMonster(cid, mob)
				setPlayerStorageValue(cid, item.itemid, getPlayerStorageValue(cid, item.itemid) + 1)
				doPlayerSendTextMessage(cid, 19, "You successfully summoned a ".. mob .."!")
			else
				doPlayerSendCancel(cid, "You can only summon up to ".. maxSummons .." ".. mob .."s.")
				return false
			end
		else
			doPlayerSendCancel(cid, "You cannot summon in protecting zone.")
			return false
		end
	else
		doPlayerSendCancel(cid, "You have used all charges this lamp contains.")
		return false
	end
	
	return true
end
 
Last edited:
Thanks guys, sorry i just started learning lua scripts. I'm used to C++ so it's a little difficult to switch.

- - - Updated - - -

If i wanted to clear the amount of charges the player has used, lets say if they talked to an npc or something. Would i use this line of code? (using warofthetitans code)

setPlayerStorageValue(cid, item.actionid, getPlayerStorageValue(cid, item.actionid) - 3)
 
Lua:
function onUse(cid, item, frompos, item2, topos)
	local charges = 3
	local mob = "Demon"
	local maxSummons = 1
 
        local str = 111
	if(getPlayerStorageValue(cid, str) < charges) then
		if(getTilePzInfo(getCreaturePosition(cid)) == false) then
			if(table.maxn(getCreatureSummons(cid)) < maxSummons) then
				doSummonMonster(cid, mob)
				setPlayerStorageValue(cid, str, getPlayerStorageValue(cid, str) + 1)
				doPlayerSendTextMessage(cid, 19, "You successfully summoned a ".. mob .."!")
			else
				doPlayerSendCancel(cid, "You can only summon up to ".. maxSummons .." ".. mob .."s.")
				return false
			end
		else
			doPlayerSendCancel(cid, "You cannot summon in protecting zone.")
			return false
		end
	else
		doPlayerSendCancel(cid, "You have used all charges this lamp contains.")
		return false
	end
 
	return true
end
 
Back
Top