• 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 GetPlayerSex(cid) problem.

Sklm01

New Member
Joined
Dec 12, 2011
Messages
11
Reaction score
0
Hi guys, well this is my problem:

I'm trying to do something really simple:

If a girl says "hi" to an NPC it will respond "Hi Lady"

however if it's a boy the NPC will say "Hi Lord" but it isn't working for girls (says "Hi Lord" every time) :s someone know why?

and if someone could tell me how to print (GetPlayerSex (cid)) somewhere, so I would know what this variable contains.

im using TFS 0.2.12 (Mystic Spirit)

Thanks and sorry for the bad English.


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

npcHandler:addModule(FocusModule:new())

	if (getPlayerSex(cid) == 0) then           -- tryed (0,1,-1) and still dosn't work
		npcHandler:setMessage(MESSAGE_GREET, "Greetings! |PLAYERNAME|, What can i do for you, my Lady?") --if a girl player greets
	else
		npcHandler:setMessage(MESSAGE_GREET, "Greetings! |PLAYERNAME|, What can i do for you, my Lord?  ") --if a boy player greets
	end

local shopModule = ShopModule:new()
npcHandler:addModule(shopModule)

shopModule:addBuyableItem({'brown backpack'}, 10519, 500, 'brown backpack')
shopModule:addBuyableItem({'brown bag'}, 10520, 100, 'brown bag')

npcHandler:addModule(FocusModule:new())
 
Last edited:
Haven't tested:
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

local PlayerSex = getPlayerSex(cid)
 
npcHandler:addModule(FocusModule:new())
 
	if PlayerSex == 1 then
		npcHandler:setMessage(MESSAGE_GREET, "Greetings! |PLAYERNAME|, What can i do for you, my Lord?") --if a boy player greets
	else
		npcHandler:setMessage(MESSAGE_GREET, "Greetings! |PLAYERNAME|, What can i do for you, my Lady?  ") --if a girl player greets
	end
 
local shopModule = ShopModule:new()
npcHandler:addModule(shopModule)
 
shopModule:addBuyableItem({'brown backpack'}, 10519, 500, 'brown backpack')
shopModule:addBuyableItem({'brown bag'}, 10520, 100, 'brown bag')
 
npcHandler:addModule(FocusModule:new())
 
are you noob?
he made a local function...
LUA:
 local playersex = getPlayerSex(cid)
no difference then what you said.

i meant...

LUA:
...

local PlayerSex = getPlayerSex(cid)



	if  getPlayerSex == 1 then 

		npcHandler:setMessage(MESSAGE_GREET, "Greetings! |PLAYERNAME|, What can i do for you, my Lady?") --if player greets
	else
		npcHandler:setMessage(MESSAGE_GREET, "Greetings! |PLAYERNAME|, What can i do for you, my Lord?  ") --if player greets
	end

and still dosn't work.
 
Just tested this and works for me.

LUA:
local Playersex = getPlayerSex(cid)

if Playersex = 0 then

Edit: nvm I tested with xml, will test with lua.
 
Last edited:
Haven't test as I said, but when it works like Limos said, then:
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
 
local PlayerSex = getPlayerSex(cid)
 
npcHandler:addModule(FocusModule:new())
 
	if PlayerSex = 1 then
		npcHandler:setMessage(MESSAGE_GREET, "Greetings! |PLAYERNAME|, What can i do for you, my Lord?") --if a boy player greets
	else
		npcHandler:setMessage(MESSAGE_GREET, "Greetings! |PLAYERNAME|, What can i do for you, my Lady?  ") --if a girl player greets
	end
 
local shopModule = ShopModule:new()
npcHandler:addModule(shopModule)
 
shopModule:addBuyableItem({'brown backpack'}, 10519, 500, 'brown backpack')
shopModule:addBuyableItem({'brown bag'}, 10520, 100, 'brown bag')
 
npcHandler:addModule(FocusModule:new())

Ofc rep him too!
 
Just tested this and works for me.

LUA:
local Playersex = getPlayerSex(cid)

If Playersex = 0 then

Edit: nvm I tested with xml, will test with lua.

:( i really don't get it ... look:

1) if ->
LUA:
 local Playersex = getPlayerSex(cid)


	if Playersex = 0 then

i get this warning: [20/04/2012 15:20:32] [Warning - NpcScript::NpcScript] Can not load script: data/npc/scripts/tools.lua
[20/04/2012 15:20:32] data/npc/scripts/tools.lua:14: 'then' expected near '='

2) if ->

LUA:
 local Playersex = getPlayerSex(cid)


	if Playersex == 0 then

i dont get any errors but it dosn't works

and 3) if ->

LUA:
 local Playersex = getPlayerSex(cid)


	if Playersex == false then

		npcHandler:setMessage(MESSAGE_GREET, "Greetings! |PLAYERNAME|, What can i do for you, my Lady?") --if player greets
	else
		npcHandler:setMessage(MESSAGE_GREET, "Greetings! |PLAYERNAME|, What can i do for you, my Lord?  ") --if player greets
	end

it always says "lady"... if i change "false" for "true" it always says "lord"....

it's frustrating :_(

BTW: im using TFS 0.2.12 (Mystic Spirit)
 
It cannot be false/true - that means like he have sex, or don't have, which isn't possible, try mi script, but when it don't work, I don't know... I'll test something now..
 
LUA:
if getPlayerSex(cid) == 1 then
		npcHandler:setMessage(MESSAGE_GREET, "Greetings! |PLAYERNAME|, What can i do for you, my Lord?  ")
        elseif getPlayerSex(cid) == 0 then
		npcHandler:setMessage(MESSAGE_GREET, "Greetings! |PLAYERNAME|, What can i do for you, my Lady?")
end
 
Last edited:
LUA:
if getPlayerSex(cid) == 1 then
		npcHandler:setMessage(MESSAGE_GREET, "Greetings! |PLAYERNAME|, What can i do for you, my Lord?  ")
        elseif getPlayerSex(cid) == 0 then
		npcHandler:setMessage(MESSAGE_GREET, "Greetings! |PLAYERNAME|, What can i do for you, my Lady?")

Was thinking about this, let him test, this should work!
 
LUA:
if getPlayerSex(cid) == 1 then
		npcHandler:setMessage(MESSAGE_GREET, "Greetings! |PLAYERNAME|, What can i do for you, my Lord?  ")
        elseif getPlayerSex(cid) == 0 then
		npcHandler:setMessage(MESSAGE_GREET, "Greetings! |PLAYERNAME|, What can i do for you, my Lady?")

neither :(.. when i try this the NPC dosn't says lord or lady just the default answer "Greeting, |PLAYERNAME|"

i think the main problem is the function itself, i mean i think getPlayerSex(cid) is getting "FALSE" from somewhere every time.... instead of 1 or 0..
 
LUA:
function onCreatureSay(cid, type, msg)
	if((msg == "hi") and not (isFocused(cid))) then
and continue your part with getplayersex




It cannot be false/true - that means like he have sex, or don't have, which isn't possible, try mi script, but when it don't work, I don't know... I'll test something now..
false in lua means 0, and true means 1
 
Last edited:
You do alltogether not seem to realize what's wrong: it's only being ran once in the initialization phase.....

Andu's might work, but it's doubtable.

In npchandler.lua find
function NpcHandler:greet(cid)

Add behind:
local msg = self:getMessage(MESSAGE_GREET)
this snippet
if getPlayerSex(cid) == 1 then
msg = "Greetings! |PLAYERNAME|, What can i do for you, my Lord? "
else
msg = "Greetings! |PLAYERNAME|, What can i do for you, my Lady?"
end
 
You do alltogether not seem to realize what's wrong: it's only being ran once in the initialization phase.....

Andu's might work, but it's doubtable.

In npchandler.lua find
function NpcHandler:greet(cid)

Add behind:
local msg = self:getMessage(MESSAGE_GREET)
this snippet
if getPlayerSex(cid) == 1 then
msg = "Greetings! |PLAYERNAME|, What can i do for you, my Lord? "
else
msg = "Greetings! |PLAYERNAME|, What can i do for you, my Lady?"
end

Yay! it works :p thanks man, but the problem is that if i add the code there, every NPC will say exactly the same, no matter if i "npcHandler:setMessage" to them.
 
Yay! it works :p thanks man, but the problem is that if i add the code there, every NPC will say exactly the same, no matter if i "npcHandler:setMessage" to them.
try replace "self" by "npchandler"

Code:
function NpcHandler:greet(cid)
 if (getPlayerSex(cid) == 0) then
     npcHandler:setMessage(MESSAGE_GREET, 'Welcome on board, Madam |PLAYERNAME|.')
  else
     npcHandler:setMessage(MESSAGE_GREET, 'Welcome on board, Sir |PLAYERNAME|.')
  end
  return 1
end
 
Back
Top