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

Solved Problem with checking if player exists

Anti

Member
Joined
Aug 12, 2010
Messages
49
Reaction score
8
Hello!
I have a script going which should check if a player exists. The player should not have to be online.

The script looks something like this:
Code:
if Player(name) then
    return true
else
    return false
end

This works as long as the player requested is online. As soon as the player logs off, the script will fail to create the Player and it will return false.
Is there a simple way to solve this or do I have to make e.g. a custom DB query to check for players?

Edit: I'm using TFS 1.1.

Thanks!
 

Code:
function onSay(cid, words, param, channel)
   if(param == '') then
     doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command param required.")
     return true
   end
 
   local pid = getPlayerByNameWildcard(param)
   if(pid) then
     doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Player " .. param .. " is online.")
   else
     doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Player " .. param .. " is offline or do not exist.")
   end
 
   return true
end
 
Code:
function onSay(cid, words, param, channel)
   if(param == '') then
     doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command param required.")
     return true
   end

   local pid = getPlayerByNameWildcard(param)
   if(pid) then
     doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Player " .. param .. " is online.")
   else
     doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Player " .. param .. " is offline or do not exist.")
   end

   return true
end
Thank you for the reply, but this wont solve the problem. I need to check if the player exist in the database. If the player X exists, but is not online I want to return true. I cannot find a functions which does this in the TFS 1.1 package, so I think I will have to make a separate query that checks for players in the database.
 
Thank you for the reply, but this wont solve the problem. I need to check if the player exist in the database. If the player X exists, but is not online I want to return true. I cannot find a functions which does this in the TFS 1.1 package, so I think I will have to make a separate query that checks for players in the database.

First post was really hard to understand.
There is a function for that.(If its right this time)

update:
050-function.lua
Code:
function playerExists(name)
   return (getPlayerGUIDByName(name) ~= 0)
end

in talkaction
Code:
function onSay(cid, words, param, channel)
   if(param == '') then
     doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command param required.")
     return true
   end
   if(playerExists(param)) then
     doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Player exist.")
   else
     doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Player does not exist.")
   end
   return true
end
 
Last edited:
Back
Top