• 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 1.1: OnStepin function that makes NPC talk

Gaddhuve

Member
Joined
May 6, 2011
Messages
76
Solutions
1
Reaction score
19
So Im not really sure what the best way to do this. Could someone point me in the right direction? This is my attempt:
Code:
local function myFunction(creature, pos)
    local targetNpc = creature('NPC'):getName()
    if targetNpc ~= nil then   
        addEvent(
            function (npcID)
                local npc = Npc(npcID)
                if npc ~= nil then
                    npc:say('Hello', TALKTYPE_SAY)
                end
            end   
        , 3000, targetNpc:getId())       
        end   
    end

function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return false
    end
    if player:getStorageValue(6000) == -1 then   
        addEvent(myFunction, 1000)       
    end
    return true
end

I just dont know how to use creature:getName() and if I should even use it for this. Thanks in advance :)
 
So Im not really sure what the best way to do this. Could someone point me in the right direction? This is my attempt:
Code:
local function myFunction(creature, pos)
    local targetNpc = creature('NPC'):getName()
    if targetNpc ~= nil then  
        addEvent(
            function (npcID)
                local npc = Npc(npcID)
                if npc ~= nil then
                    npc:say('Hello', TALKTYPE_SAY)
                end
            end  
        , 3000, targetNpc:getId())      
        end  
    end

function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return false
    end
    if player:getStorageValue(6000) == -1 then  
        addEvent(myFunction, 1000)      
    end
    return true
end

I just dont know how to use creature:getName() and if I should even use it for this. Thanks in advance :)
does it work at all and just need it to say the player's name? or does it need fixing
 
Forgot to post this:
33d9d84494094bc790ea6bbbdcfb12b4.png
The script loads but gives me this error after 4 seconds when it tries to launch the function.
 
Code:
local function myFunction(cid)
    local targetNpc = Creature('NPC'):getName()
    if targetNpc then  
        addEvent(
            function(npcID, playerName)
                local npc = Npc(npcID)
                if npc then
                    npc:say('Hello '.. playerName, TALKTYPE_SAY)
                end
            end  
        , 3000, targetNpc:getId(), Player(cid):getName())      
        end  
    end

function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return false
    end
    if player:getStorageValue(6000) == -1 then  
        addEvent(myFunction, 1000, creature:getId())
    end
    return true
end
try this
you were trying to make the npc into creature userdata but you used lowercase c instead of capital, i also added the playername to 'Hello'
 
Back
Top