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

TFS 1.X+ Npc who talks only to man or woman

Jvkisuckbr

New Member
Joined
May 11, 2019
Messages
8
Reaction score
3
Location
Brazil
I have custom sprites in my server, and i need a npc who talks only to man or woman. help plz.

I use this script:
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end

local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
local config = {
  itemNeeded = 33525,
  count = 5,
  addonName = "sparrow",
  outfitId = 1145,
  giveAddons = 2,
  storage = 3848,
}
            if (msgcontains(msg, config.addonName)) then
            if getPlayerStorageValue(cid,3848) < 1 then else return selfSay('Sorry, you this have a addon of '..config.addonName..' Outfit.', cid) end   
                    selfSay("To achieve the "..config.addonName..", the more you need to give me certain items do you accept this trade? ", cid)
                      talkState[talkUser] = 1
            elseif(msgcontains(msg, "yes")) and talkState[talkUser] == 1 then
            if doPlayerRemoveItem(cid, 33525, 5) then
            doPlayerAddOutfit(cid,config.outfitId, config.giveAddons)
                       setPlayerStorageValue(cid, 3848, 1)
                       selfSay("Thank you, you can look at your inventory of outfits.",cid)
            else selfSay('Sorry, you need a '..config.count..' of '..getItemName(config.itemNeeded)..' for complet a my trade.', cid) end           
                       talkState[talkUser] = 0
                      
            end


return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Solution
If your intention is to make specific NPC that talks with males and handle the male outfits, it may be easier to make one NPC that gives you a certain outfit based on your sex.
Also, a small tip, if you add a female outfit to a male character, he won't be able to wear it until he chances sex.

But here is what you asked for, also, I cleared the code for you, your indentation was a huge mess.

Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg)...
Just add the male check where you want it to talk to only male and female check where you want it to talk to female, If it didn't work change PLAYERSEX_MALE to 1 and change PLAYERSEX_FEMALE to 0
Lua:
if player:getSex() == PLAYERSEX_MALE then
if player:getSex() == PLAYERSEX_FEMALE then
 
Last edited:
Just add the male check where you want it to talk to only male and female check where you want it to talk to female, If it didn't work change PLAYERSEX_MALE to 1 and change PLAYERSEX_FEMALE to 2
Lua:
if player:getSex() == PLAYERSEX_MALE then
if player:getSex() == PLAYERSEX_FEMALE then
female is 0 😅
 
Just add the male check where you want it to talk to only male and female check where you want it to talk to female, If it didn't work change PLAYERSEX_MALE to 1 and change PLAYERSEX_FEMALE to 0
Lua:
if player:getSex() == PLAYERSEX_MALE then
if player:getSex() == PLAYERSEX_FEMALE then

where do i add this?
 
Lua:
if player:getSex() == 1 then -- PLAYERSEX_MALE
if player:getSex() == 0 then -- PLAYERSEX_FEMALE

Put in the start of part where you want to just talk with a specific sex.

Example: (for male)

Lua:
if player:getSex() == 1 then
    [YOUR SCRIPT HERE]
end
 
If your intention is to make specific NPC that talks with males and handle the male outfits, it may be easier to make one NPC that gives you a certain outfit based on your sex.
Also, a small tip, if you add a female outfit to a male character, he won't be able to wear it until he chances sex.

But here is what you asked for, also, I cleared the code for you, your indentation was a huge mess.

Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end

local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
local config = {
    itemNeeded = 33525,
    count = 5,
    addonName = "sparrow",
    outfitId = 1145,
    giveAddons = 2,
    storage = 3848,
}

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    if (msgcontains(msg, config.addonName)) then
        if getPlayerStorageValue(cid,3848) > 1 then
            return selfSay('Sorry, you this have a addon of '..config.addonName..' Outfit.', cid)
        end
        selfSay("To achieve the "..config.addonName..", the more you need to give me certain items do you accept this trade? ", cid)
        talkState[talkUser] = 1
    elseif(msgcontains(msg, "yes")) and talkState[talkUser] == 1 then
        if doPlayerRemoveItem(cid, 33525, 5) then
            doPlayerAddOutfit(cid,config.outfitId, config.giveAddons)
            setPlayerStorageValue(cid, 3848, 1)
            selfSay("Thank you, you can look at your inventory of outfits.",cid)
        else
            selfSay('Sorry, you need a '..config.count..' of '..getItemName(config.itemNeeded)..' for complet a my trade.', cid) end      
            talkState[talkUser] = 0                
        end
        return true
    end
end

local function greetCallback(cid)
    local player = Player(cid)
    if player:getSex() == 1 then
        selfSay("Welcome, my male friend.",cid)
        return true
    else
        selfSay("Im not talking to females.",cid)
        return false
    end
end

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())


The part responsible for rejecting females is
Lua:
local function greetCallback(cid)
    local player = Player(cid)
    if player:getSex() == 1 then
        selfSay("Welcome, my male friend.",cid)
        return true
    else
        selfSay("Im not talking to females.",cid)
        return false
    end
end

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
 
Last edited:
Solution
If your intention is to make specific NPC that talks with males and handle the male outfits, it may be easier to make one NPC that gives you a certain outfit based on your sex.
Also, a small tip, if you add a female outfit to a male character, he won't be able to wear it until he chances sex.

But here is what you asked for, also, I cleared the code for you, your indentation was a huge mess.

Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end

local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
local config = {
    itemNeeded = 33525,
    count = 5,
    addonName = "sparrow",
    outfitId = 1145,
    giveAddons = 2,
    storage = 3848,
}

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    if (msgcontains(msg, config.addonName)) then
        if getPlayerStorageValue(cid,3848) > 1 then
            return selfSay('Sorry, you this have a addon of '..config.addonName..' Outfit.', cid)
        end
        selfSay("To achieve the "..config.addonName..", the more you need to give me certain items do you accept this trade? ", cid)
        talkState[talkUser] = 1
    elseif(msgcontains(msg, "yes")) and talkState[talkUser] == 1 then
        if doPlayerRemoveItem(cid, 33525, 5) then
            doPlayerAddOutfit(cid,config.outfitId, config.giveAddons)
            setPlayerStorageValue(cid, 3848, 1)
            selfSay("Thank you, you can look at your inventory of outfits.",cid)
        else
            selfSay('Sorry, you need a '..config.count..' of '..getItemName(config.itemNeeded)..' for complet a my trade.', cid) end      
            talkState[talkUser] = 0                
        end
        return true
    end
end

local function greetCallback(cid)
    local player = Player(cid)
    if player:getSex == 1 then
        selfSay("Welcome, my male friend.",cid)
        return true
    else
        selfSay("Im not talking to females.",cid)
        return false
    end
end

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())


The part responsible for rejecting females is
Lua:
local function greetCallback(cid)
    local player = Player(cid)
    if player:getSex == 1 then
        selfSay("Welcome, my male friend.",cid)
        return true
    else
        selfSay("Im not talking to females.",cid)
        return false
    end
end

npcHandler:setCallback(CALLBACK_GREET, greetCallback)


Thank you very much, it worked, but I needed to correct some details in your code:
Lua:
if getPlayerStorageValue(cid,3848) > 1 then               for              if getPlayerStorageValue(cid,3848) < 1 then else

Lua:
else
            selfSay('Sorry, you need a '..config.count..' of '..getItemName(config.itemNeeded)..' for complet a my trade.', cid) end       
            talkState[talkUser] = 0                 
        end
        return true
    end
end

for

else
            selfSay('Sorry, you need a '..config.count..' of '..getItemName(config.itemNeeded)..' for complet a my trade.', cid) end       
            talkState[talkUser] = 0                 
        end
        return true
    end

Lua:
if player:getSex == 1 then            for    if player:getSex() == 1 then
 
Back
Top