JohnLehn Posted April 21, 2020 Share Posted April 21, 2020 function dchat ( thePlayer, _, ... ) local message = table.concat ( { ... }, " " ) if ( isPlayerOnGroup ( thePlayer ) ) then for _, player in ipairs ( getElementsByType ( "player" ) ) do if ( isPlayerOnGroup ( player ) ) then outputChatBox ( "#0066cc[Unit ".. numbers .."]#0066cc".. getPlayerName ( thePlayer ) ..": #0066cc".. message, player, 255, 255, 255, true ) end end else outputChatBox ( "#838b83Error!", thePlayer, 255, 255, 255, true ) end end addCommandHandler ( "d", dchat ) function randomnum(player) local numbers = tostring(math.random(1,100)) outputChatBox ( " The random number is ".. numbers ..". ", player ) end When you say something on chat /d, i want to appear [Unit (random number)] <playername> : <Text> The error with this code is : Error: Dispatch\Server.Lua:6 attept to concatentate global 'number' (a nil value) Can someone help me ? Please ? Link to comment
Spakye Posted April 21, 2020 Share Posted April 21, 2020 Hello, you are using numbers on line 6 in the outputChatBox but you didnt assign any value to it. you should add this to the dchat function and i guess it should work. local numbers = tostring(math.random(1,100)) 1 Link to comment
JohnLehn Posted April 21, 2020 Author Share Posted April 21, 2020 Thanks ! It worked ! How can i make it to be only one number per user, when i type /d <text> look how it is working: [Unit 46]BigNighT: s [Unit 36]BigNighT: f [Unit 6]BigNighT: s Link to comment
yeahs Posted April 21, 2020 Share Posted April 21, 2020 (edited) You can work with set- and getElementData. Just give your users a ID with setElementData, after he loggedin or connected, and use getElementData to ask for it and use it in your chatbox. You could use something like this: local ID = 0; function givePlayerID(player) ID = ID + 1; setElementData(player,"PlayerID",ID); end addEventHandler("onPlayerJoin",root,function() givePlayerID(source); end) for _,v in pairs(getElementsByType("player"))do givePlayerID(v); end) Now you can use getElementData to get the PlayerID who will be the same until the player disconnect or the script will be restarted. If you want that all players have everytime the same ID you must work with a database or a textfile or something else to save them. Edited April 21, 2020 by xendomrayden 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