• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

NPC Cannot determine playersex?

  • Thread starter Thread starter Icy
  • Start date Start date
I

Icy

Guest
LUA:
local sexMessage = ''
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid)				npcHandler:onCreatureAppear(cid) 			end
function onCreatureDisappear(cid) 			npcHandler:onCreatureDisappear(cid) 			end
function onCreatureSay(cid, type, msg)
	if getPlayerSex(cid) == 0 then
		sexMessage = 'You are a girl'
	else
		sexMessage = 'You are a guy'
	end
	
	npcHandler:onCreatureSay(cid, type, msg)
end
function onThink() 					npcHandler:onThink() 					end

-- Don't forget npcHandler = npcHandler in the parameters. It is required for all StdModule functions!
keywordHandler:addKeyword({'guide'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Try saying {sex}'})
keywordHandler:addKeyword({'sex'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = sexMessage})

npcHandler:addModule(FocusModule:new())


When I say `sex` to him he replies with nothing:

19:52 Icy [5]: sex
19:52 Aidan:
Anyone know what's wrong with this?
 
Last edited by a moderator:
if getPlayerGender(cid) == 0 then

try this one
u.u
Code:
  local sexMessage = ''
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid)                          npcHandler:onCreatureAppear(cid)                        end
function onCreatureDisappear(cid)                       npcHandler:onCreatureDisappear(cid)                     end
function onCreatureSay(cid, type, msg)
        if getPlayerGender(cid) == 0 then
                sexMessage = 'You are a girl'
        else
                sexMessage = 'You are a guy'
        end
       
        npcHandler:onCreatureSay(cid, type, msg)
end
function onThink()                                      npcHandler:onThink()                                    end

-- Don't forget npcHandler = npcHandler in the parameters. It is required for all StdModule functions!
keywordHandler:addKeyword({'guide'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Try saying {sex}'})
keywordHandler:addKeyword({'sex'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = sexMessage})

npcHandler:addModule(FocusModule:new())
 
if getPlayerGender(cid) == 0 then

try this one
u.u
Code:
  local sexMessage = ''
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid)                          npcHandler:onCreatureAppear(cid)                        end
function onCreatureDisappear(cid)                       npcHandler:onCreatureDisappear(cid)                     end
function onCreatureSay(cid, type, msg)
        if getPlayerGender(cid) == 0 then
                sexMessage = 'You are a girl'
        else
                sexMessage = 'You are a guy'
        end
       
        npcHandler:onCreatureSay(cid, type, msg)
end
function onThink()                                      npcHandler:onThink()                                    end

-- Don't forget npcHandler = npcHandler in the parameters. It is required for all StdModule functions!
keywordHandler:addKeyword({'guide'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Try saying {sex}'})
keywordHandler:addKeyword({'sex'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = sexMessage})

npcHandler:addModule(FocusModule:new())

Yeah I kind of figured that's what you meant at first so I tried it but ended up getting this error message in the console:
Code:
[19:54:17.005] [Error - NpcScript Interface]
[19:54:17.005] data/npc/scripts/starter.lua:onCreatureSay
[19:54:17.005] Description:
[19:54:17.005] data/npc/scripts/starter.lua:9: attempt to call global 'getPlayer
Gender' (a nil value)
[19:54:17.005] stack traceback:
[19:54:17.005]  data/npc/scripts/starter.lua:9: in function <data/npc/scripts/st
arter.lua:8>
 
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

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
	elseif msgcontains(msg, 'guide') then
		selfSay('Try saying {sex}', cid)
	elseif msgcontains(msg, 'sex') then
		selfSay('You are a ' .. (getPlayerSex(cid) == 0 and 'girl' or 'guy'), cid)
	end
	return true
end

[B][COLOR="Red"]npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)[/COLOR][/B]
npcHandler:addModule(FocusModule:new())
 
Last edited:
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

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
	elseif msgcontains(msg, 'guide') then
		selfSay('Try saying {sex}', cid)
	elseif msgcontains(msg, 'sex') then
		selfSay('You are a ' .. (getPlayerSex(cid) == 0 and 'girl' or 'guy'), cid)
	end
	return true
end

npcHandler:setCallback(CALLBACK_ONTHINK, thinkCallback)
npcHandler:addModule(FocusModule:new())

He just doesn't say anything after you start talking to him.
 
Works on TFS 0.3.6
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
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
end
function creatureSayCallback(cid, type, msg)
	if not npcHandler:isFocused(cid) then
		return false
	elseif msgcontains(msg, 'guide') then
		selfSay('Try saying {sex}', cid)
	elseif msgcontains(msg, 'sex') then
		selfSay('You are a ' .. (getPlayerSex(cid) == 0 and 'girl' or 'guy'), cid)
	end
	return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Works on TFS 0.3.6
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
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
end
function creatureSayCallback(cid, type, msg)
	if not npcHandler:isFocused(cid) then
		return false
	elseif msgcontains(msg, 'guide') then
		selfSay('Try saying {sex}', cid)
	elseif msgcontains(msg, 'sex') then
		selfSay('You are a ' .. (getPlayerSex(cid) == 0 and 'girl' or 'guy'), cid)
	end
	return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Thanks, worked.
 
Back
Top