scaryface87 Posted June 22, 2014 Share Posted June 22, 2014 (edited) bad argument #1 for 'ipairs' (table expected, got nill) function classchat(player, command, ...) local message = table.concat(arg, " ") local classmembers = getElementData(player,"class") for i,v in ipairs(classmembers) do outputChatBox("*CLASS*" .. getPlayerName(player) .. ": " .. message ,255, 100, 0, true) end end addCommandHandler("class", classchat) Edited June 22, 2014 by Guest Link to comment
scaryface87 Posted June 22, 2014 Author Share Posted June 22, 2014 bad argument #1 for 'ipairs' (table expected, got nill) function classchat(player, command, ...) local message = table.concat(arg, " ") local classmembers = getElementData(player,"class") for i,v in ipairs(classmembers) do outputChatBox("*CLASS*" .. getPlayerName(player) .. ": " .. message ,255, 100, 0, true) end end addCommandHandler("class", classchat) Link to comment
AboShanab Posted June 22, 2014 Share Posted June 22, 2014 function classchat(player, command, ...) local message = table.concat({...}, " ") for i,v in ipairs(getElementsByType("player")) do if ( getElementData ( v, "class" ) ) then outputChatBox("*CLASS*" .. getPlayerName(player) .. ": " .. message , v, 255, 100, 0, true) end end end addCommandHandler("class", classchat) Try This ^ Link to comment
scaryface87 Posted June 22, 2014 Author Share Posted June 22, 2014 its sending the message to everyone not to 1 class wich u are in Link to comment
Moderators Citizen Posted June 23, 2014 Moderators Share Posted June 23, 2014 # hmmm, what you need ? It's obvius ... A teacher has stutends and he want to only talk to them. @scaryface87: you used this instruction to get the class: local classmembers = getElementData(player,"class") but how do you set it ? Can you show us how you create the table and how do you set it as an element data ? Thanks Link to comment
scaryface87 Posted June 23, 2014 Author Share Posted June 23, 2014 # hmmm, what you need ? It's obvius ... A teacher has stutends and he want to only talk to them. @scaryface87: you used this instruction to get the class: local classmembers = getElementData(player,"class") but how do you set it ? Can you show us how you create the table and how do you set it as an element data ? Thanks Im a little bit confused? It sets the element data on playerspawn (i already used getElementData for other things so dont rlly htink its a problem there) h"how you create the table" what u meaN? Link to comment
Moderators Citizen Posted June 24, 2014 Moderators Share Posted June 24, 2014 I meant: "Can you show the code where you are setting this "class" element data ?" Because this data should be a table, and I want to see how did you make this table (how did you fill it). Link to comment
scaryface87 Posted June 24, 2014 Author Share Posted June 24, 2014 im just using setElementData(player, "class", className) Link to comment
Moderators Citizen Posted June 24, 2014 Moderators Share Posted June 24, 2014 And what is className ? Come on, give us the code we need, not 1 line after the other. Your code was expecting a table and not a class name as a string. The error says it got nil instead of a table. So it means the value of className here setElementData(player, "class", className) is nil. So give us the code above that line ! + If you want to use a classe name instead of a table of class members, then use this code (based on iAbo's code): function classchat(player, command, ...) local message = table.concat({...}, " ") for i,v in ipairs(getElementsByType("player")) do if getElementData( player, "class" ) == getElementData( v, "class" ) then outputChatBox("*CLASS*" .. getPlayerName(player) .. ": " .. message , v, 255, 100, 0, true) end end end addCommandHandler("class", classchat) Note (and I repeat) the code will still not work untill you fix the className value for the setElementData Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now