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

Lua OnKill, add storage problem. [CreatureScript]

Extrodus

|| Blazera.net ||
Joined
Dec 22, 2008
Messages
2,750
Solutions
7
Reaction score
552
Location
Canada
So I found some scripts on the forum that I am converting to TFS 1.2, but after finishing the first one and testing it. I get no errors, and nothing happens on the death of the monster, no text message; no storages set.. nothing.

So here is the creature script:
Code:
<event type="kill" name="Willow_Boss_Storage_Counter" event="script" value="Aragon/dungeons/willow_boss_storage_counter.lua"/>
Code:
<!-- OnLogin.lua Register Event -->
player:registerEvent("Willow_Boss_Storage_Counter")

Script:
Code:
local storage = 45001 -- storageID to use.
local maxPoints = 1 -- maximum amount of saved points a player can have
local givePoints = 1 -- amount of points to give player
local creatureName = '[b] willow' -- creaturename (must be lowercase letters)

function onKill(player, target, damage, flags)

   if player:isPlayer(target) then
        return true
   end

    local name = target:getName():lower()
    if name ~= creatureName then
        return true
    end

    if player:getStorageValue(storage) < 0 then
        player:setStorageValue(storage, 0)
    end

    if player:getStorageValue(storage) < maxPoints then
        player:setStorageValue(storage, player:getStorageValue(storage) + givePoints)
    end

    player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have defeated ' .. name .. '.')

    return true
end


Really don't know why it isn't working, was thinking I may have to use creature functions instead, but not sure. Any help is appreciated!

Note: Here is the movements script for the previous script, I have converted it but havent been able to test it due to the other script not working. If you see any flaws in it, please let me know.

Code:
local storage = 45001 -- storage used in creaturescript
local location = {x = 1000, y = 1000, z = 7} -- place you will teleport
local pointsRequired = 1 -- how many creature points required to teleport

function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
   if player:isPlayer ~= TRUE then
     return false
   end
   if player:getStorageValue(storage) < 0 then
     player:setStorageValue(storage, 0)
   end

   if player:getStorageValue(storage) >= pointsRequired then
     player:setStorageValue(storage, player:getStorageValue(storage) - pointsRequired)
     creature:teleportThing(location)
   else
     player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You require ".. pointsRequired .." points to use this teleport. You currently have ".. player:getStorageValue(storage) .." points.")
   end

   return true
end
 
Last edited:
It's not registered properly in creaturescripts.xml (remove event="script", and replace value with script).
 
What is this? ._."

Code:
function onKill(player, target, damage, flags)

   if player:isPlayer(target) then
        return true
   end

if target:isPlayer() then
return true​
end

Code:
function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
   if player:isPlayer ~= TRUE then
     return false
   end

local player = creature:getPlayer()
if not player then
return false​
end

Red
 
if not creature:isPlayer() then
return false
end

:D

True, but then he'd have to change his entire script to call "creature" instead of "player" -- I'd rather call local player = creature:getPlayer() once and continue to use player; it's more readable and precise for minimal cost.

Red
 
Back
Top