Jump to content

[PROBLEM]Chat Command


JohnLehn

Recommended Posts

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 post

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 by xendomrayden
Link to post

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...