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

TalkAction set player name in-game

Snafu01

New Member
Joined
Oct 14, 2013
Messages
12
Reaction score
1
You can set players name in game.

Put these functions in your 50-function

Code:
function setPlayerName(cid, name)
   local query = "INSERT INTO `players` SET `name` = "..name.." WHERE `name` = "..cid
   return db.executeQuery(query)
end

function getOfflinePlayerName(cid)
local query = "SELECT `name` FROM `players` WHERE `name` = "..cid
return db.getResult(query)
end

and in talkactions
Code:
function onSay(cid, words, param, channel)
   if (param == '') then
     doPlayerSendCancel(cid, "Command requires param")
   return true
   end
   t = string.explode(param, ",")
   t[1] = setname
   local player = getPlayerByNameWildcard(param)
   local db_player = getOfflinePlayerName(player)

   if isPlayer(player) then
     doRemoveCreature(player, 1)
     setPlayerName(db_player, setname)
     doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_GREEN, "You have set the players name.")
   else
     doPlayerSendCancel(cid, "This player is not online.")
   return false
   end
return true
end
 
Last edited:
db.executeQuery("INSERT INTO `players` SET `name` = "..name.." WHERE `name` = "..cid)
return query

local query = "SELECT `name` FROM `players` WHERE `name` = "..cid

this will not work o_O
 
You can set access in talkaction so you can remove that check, you also register the words so you don't need that check either.
Then you split the string in order to do nothing with it? Why would you set t[1] to setname (nil value).
I do not think returning db.execute(query) help you, you might want to use db.getResult.
setname is still nil when calling setPlayerName so you are concatenating a nil value which won't work, also you can't check if name = cid, that will never give you a player.
Use constants for doPlayerSendTextMessage (instead of 22)
setOfflinePlayerStorage is not defined.

Should this really a release, if so I question why don't you test it lol.
Otherwise if you need help with scripts this is the wrong board, support is what you are looking for.
 
Fixed some minor bugs.... Also param = player you want to change names t[1] = name you want to change it. If you want to be an idiot go to native boards... I did this at like 3am get off my back. ty for showing mistakes but you dont need to be retarded about it.
 
I just show everything that is wrong. There were / are so many issue that nobody knows whether you meant to post in support board or not.
Not giving any information doesn't really help.

If you don't make good scripts at 3am that is understandable, but why do you have to "release" them if one can't even execute them without being floaded by errors?

For anybody searching a working script:
Code:
local config = {
    newNameLength = {4, 20}
}

function setPlayerName(cid, currentName, newName)
  if not isPlayer(cid) then return false end
  doRemoveCreature(cid)
  db.executeQuery(string.format('UPDATE `players` SET `name` = %s WHERE name = %s;', db.escapeString(newName), db.escapeString(currentName)))
  return true
end

function onSay(cid, words, param, channel)
  if (param == '') then
    doPlayerSendCancel(cid, 'Command requires param')
    return true
  end

  local t = param:explode(',')
  if not t[2] then
    doPlayerSendCancel(cid, string.format('Use: %s <playername>, <newname>', words))
    return true
  end
  local player = getPlayerByNameWildcard(t[1])
  if not isPlayer(player) then
    doPlayerSendCancel(cid, string.format('The player with name "%s" could not be found.', t[1]))
    return true
  end
  local length = #t[2]
  if math.min(math.max(length, config.newNameLength[1]), config.newNameLength[2]) ~= length then
    doPlayerSendCancel(cid, string.format('New name has to be between %i and %i characters long.', config.newNameLength[1], config.newNameLength[2]))
    return true
  end
  local name = getPlayerName(player)
  doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_GREEN, string.format('"%s" has been renamed to "%s".', name, t[2]))
  setPlayerName(player, name, t[2])
  return true
end
 
Last edited:
I just show everything that is wrong. There were / are so many issue that nobody knows whether you meant to post in support board or not.
Not giving any information doesn't really help.

If you don't make good scripts at 3am that is understandable, but why do you have to "release" them if one can't even execute them without being floaded by errors?

For anybody searching a working script:
Code:
local config = {
    newNameLength = {4, 20}
}

function setPlayerName(cid, currentName, newName)
  if not isPlayer(cid) then return false end
  doRemoveCreature(cid)
  db.executeQuery(string.format('UPDATE `players` SET `name` = %s WHERE name = %s;', db.escapeString(newName), db.escapeString(currentName)))
  return true
end

function onSay(cid, words, param, channel)
  if (param == '') then
    doPlayerSendCancel(cid, 'Command requires param')
    return true
  end

  local t = param:explode(',')
  if not t[2] then
    doPlayerSendCancel(cid, string.format('Use: %s <playername>, <newname>', words))
    return true
  end
  local player = getPlayerByNameWildcard(t[1])
  if not isPlayer(player) then
    doPlayerSendCancel(cid, string.format('The player with name "%s" could not be found.', t[1]))
    return true
  end
  local length = #t[2]
  if math.min(math.max(length, config.newNameLength[1]), config.newNameLength[2]) ~= length then
    doPlayerSendCancel(cid, string.format('New name has to be between %i and %i characters long.', config.newNameLength[1], config.newNameLength[2]))
    return true
  end
  local name = getPlayerName(player)
  doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_GREEN, string.format('"%s" has been renamed to "%s".', name, t[2]))
  setPlayerName(player, name, t[2])
  return true
end
Where do I add this for it to work?
 
Back
Top