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

CreatureScript Error

Zie

New Member
Joined
Jun 7, 2009
Messages
26
Reaction score
0
Hello!

I have an error when I try to use a script.

I run my server off TFS Version 0.2.3 (Mystic Spirit)

The code below is saved as broadcastSingleMonsterKilled.lua in the target location creaturescripts\scripts\

Code:
local config = { 
    broadCast = FALSE, -- Red broadcast = TRUE/FALSE 
    monsterName = "Bug", 
} 
function onKill(cid, target) 
    if isMonster(target) == TRUE and isPlayer(cid) == TRUE then 
        if getCreatureName(target) == string.lower(config.monsterName) then 
            if config.broadCast == TRUE then 
                doBroadcastMessage(getPlayerName(cid).." killed a "..getCreatureName(target)) 
            else 
                doPlayerSendTextMessage(cid, 22, "You killed a "..getCreatureName(target)) 
            end 
        end 
    end 
    return TRUE 
end

I have also added the appropriate text in creaturescripts.xml:

<event type="kill" name="broadcastSingleMonsterKilled" script="broadcastSingleMonsterKilled.lua"/>

I am not positive if I need it in the login.lua, but I have also placed appropriate text in there (or so I believe I did):

registerCreatureEvent(cid, "broadcastSingleMonsterKilled")

The errors I get after I kill a Bug or any other creature are as follows:

[26/06/2009 15:37:03] Lua Script Error: [CreatureScript Interface]
[26/06/2009 15:37:03] data/creaturescripts/scripts/broadcastSingleMonsterKilled.lua:eek:nKill

[26/06/2009 15:37:03] ...turescripts/scripts/broadcastSingleMonsterKilled.lua:6: attempt to call global 'isMonster' (a nil value)
[26/06/2009 15:37:03] stack traceback:
[26/06/2009 15:37:03] ...turescripts/scripts/broadcastSingleMonsterKilled.lua:6: in function <...turescripts/scripts/broadcastSingleMonsterKilled.lua:5>



Also can someone help me to make a script so it will broadcast every monster killed by every player as well? A broadcast such as "PlayerName just killed a MonsterName"

Thanks for any help for getting this to work on my version of TFS
 
Last edited:
Basically it's saying that you're trying to call the function "isMonster", but the function does not exist.

I suggest you remove the "if isMonster(target) == TRUE and isPlayer(cid) == TRUE then" part, it's a tad bit unnecessary considering that you cannot kill anything else than players or monsters.
 
Broadcast whenever someone kills a bug OR Text Message whenever you kill a bug:
Lua:
local config = { 
	broadCast = TRUE, -- Red broadcast = TRUE/FALSE 
	monsterName = "Bug", 
}
function onKill(cid, target) 
	if getCreatureName(target) == string.lower(config.monsterName) then 
		if config.broadCast == TRUE then 
			broadcastMessage(""..getCreatureName(cid).." ["..getPlayerLevel(cid).."] killed a "..getCreatureName(target).."", MESSAGE_STATUS_WARNING) 
		else 
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You killed a "..getCreatureName(target).."") 
		end 
	end 
	return TRUE 
end

Broadcast whenever somebody kills a player/monster:
Lua:
function onKill(cid, target)
	if isPlayer(target) == TRUE then
		broadcastMessage(""..getCreatureName(cid).." ["..getPlayerLevel(cid).."] killed "..getCreatureName(target).." ["..getPlayerLevel(cid).."]", MESSAGE_STATUS_WARNING) 
	else
		broadcastMessage(""..getCreatureName(cid).." ["..getPlayerLevel(cid).."] killed a "..getCreatureName(target).."", MESSAGE_STATUS_WARNING)
	end
	return TRUE 
end
 
Last edited:
Broadcast whenever someone kills a bug OR Text Message whenever you kill a bug:
Lua:
local config = { 
	broadCast = TRUE, -- Red broadcast = TRUE/FALSE 
	monsterName = "Bug", 
}
function onKill(cid, target) 
	if getCreatureName(target) == string.lower(config.monsterName) then 
		if config.broadCast == TRUE then 
			broadcastMessage(""..getCreatureName(cid).." ["..getPlayerLevel(cid).."] killed a "..getCreatureName(target).."", MESSAGE_STATUS_WARNING) 
		else 
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You killed a "..getCreatureName(target).."") 
		end 
	end 
	return TRUE 
end

Broadcast whenever somebody kills a player/monster:
Lua:
function onKill(cid, target)
	if isPlayer(target) == TRUE then
		broadcastMessage(""..getCreatureName(cid).." ["..getPlayerLevel(cid).."] killed "..getCreatureName(target).." ["..getPlayerLevel(cid).."]", MESSAGE_STATUS_WARNING) 
	else
		broadcastMessage(""..getCreatureName(cid).." ["..getPlayerLevel(cid).."] killed a "..getCreatureName(target).."", MESSAGE_STATUS_WARNING)
	end
	return TRUE 
end


Thanks a bunchies. The second code works but the first does not :( I only really need second, thanks! I also wish to find / request a script on when you die by a monster that it will broadcast. I took your code and tried to edit it...but nothing happens at all

Code:
function onDeath(cid, target)
        if isPlayer(target) == TRUE then
                broadcastMessage(""..getCreatureName(target).." killed "..getCreatureName(target).." ["..getPlayerLevel(cid).."]", MESSAGE_STATUS_WARNING) 
        end
        return TRUE 
end

Thanks in advance to whoever can help me! I'm newb :(
 
Last edited:
Back
Top