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

Global MSG according to the player storage

warriorfrog

Active Member
Joined
Jul 29, 2015
Messages
334
Reaction score
35
Is anybody know how to send a Global MSG according to the player storage?

I've tried this, but not work:
Code:
local txtENG = {
   "ENG 1",
   "ENG 2",
   "ENG 3"
}

local txtPT = {
   "PT 1",
   "PT 2",
   "PT 3"
}

local txtESP = {
   "ESP 1",
   "ESP 2",
   "ESP 3"
}

local idiomstorage = 8971
local i = 0
function onThink(interval, lastExecution)
   local message
   if getPlayerStorageValue(cid, idiomstorage) <= 1 then
       message = txtENG[(i % #txtENG) + 1]
   elseif getPlayerStorageValue(cid, idiomstorage) == 2 then
       message = txtPT[(i % #txtPT) + 1]
   elseif getPlayerStorageValue(cid, idiomstorage) == 3 then
       message = txtESP[(i % #txtESP) + 1]
   end

   for _, pid in ipairs(getPlayersOnline()) do
       doPlayerSendTextMessage(pid, 20, " [MSG]: ".. message ..". ")
       i = i + 1
   end
   return TRUE
end
 
Solution
It won't work because you don't understand what you copy and pasted, a script isn't constructed like you are working with a lego set. There is logic to consider when writing one.

I've looked over your code and commented out what you did wrong, but I did not fix anything in it.
LUA:
local txtENG = {
  "ENG 1",
  "ENG 2",
  "ENG 3"
  }

local txtPT = {
  "PT 1",
  "PT 2",
  "PT 3"
  }

local txtESP = {
  "ESP 1",
  "ESP 2",
  "ESP 3"
  }

local idiomstorage = 8971
local i = 0
function onThink(interval, lastExecution)
  -- message has to be an empty string otherwise u can't attach anything to it
  local message = ''
  --[[
  you can't call getPlayerStorageValue because cid is not defined, it isn't just a word
  its a variable and holds a...
It won't work because you don't understand what you copy and pasted, a script isn't constructed like you are working with a lego set. There is logic to consider when writing one.

I've looked over your code and commented out what you did wrong, but I did not fix anything in it.
LUA:
local txtENG = {
  "ENG 1",
  "ENG 2",
  "ENG 3"
  }

local txtPT = {
  "PT 1",
  "PT 2",
  "PT 3"
  }

local txtESP = {
  "ESP 1",
  "ESP 2",
  "ESP 3"
  }

local idiomstorage = 8971
local i = 0
function onThink(interval, lastExecution)
  -- message has to be an empty string otherwise u can't attach anything to it
  local message = ''
  --[[
  you can't call getPlayerStorageValue because cid is not defined, it isn't just a word
  its a variable and holds a value which is the creature id, a number
  so none of this code will execute, all you will get is errors
  if getPlayerStorageValue(cid, idiomstorage) <= 1 then
  message = txtENG[(i % #txtENG) + 1]
  elseif getPlayerStorageValue(cid, idiomstorage) == 2 then
  message = txtPT[(i % #txtPT) + 1]
  elseif getPlayerStorageValue(cid, idiomstorage) == 3 then
  message = txtESP[(i % #txtESP) + 1]
  end

  these tables and the formula you are creating to index the table are going to throw an error.. because
  you only have 3 indexes per table and you are scaling the value of the expression, you will get an out of bounds
  error
  ]]
  for _, pid in ipairs(getPlayersOnline()) do
  -- here is where you want to check if a player has a storage value
  -- because getPlayersOnline returns a table of players, when
  -- place in an iterator such as a for loop its 1st return value returns the index of the table which is a number value
  -- the second return value is the player id and it too is a number
  -- that is what pid is referencing
  doPlayerSendTextMessage(pid, 20, " [MSG]: ".. message ..". ")
  i = i + 1 -- what is the purpose of i?
  end
  return TRUE
  end

You've been here as long as I have, you should really set some time aside and start reading up on lua, you don't have to master it but you have to get a general understanding of it. It would really benefit you in the long run.
 
Solution
Back
Top