Sign in to follow this  
Frugle

Need help with this small script (major noob here)

Recommended Posts

function ClientChat(text)
 
if ( text == "pos" ) then
outputConsole ( "SUCCESS" )
outputChatBox ( "SUCCESS", getRootElement(), 255, 255, 255, true )
else 
outputConsole ( "FAILURE" )
outputChatBox ( "FAILURE", getRootElement(), 255, 255, 255, true )
end
end
 
addEventHandler ("OnClientChatMessage", getRootElement(), ClientChat)

I am trying to output SUCCESS to chatbox and console if player types pos, but nothing happens :( Not even FAILURE output.

Need help!

Share this post


Link to post

You're not major noob... It happens if you're still an unexperienced scripter. Don't worry experience comes with time ;)

function ClientChat(text)
 
if ( text == "pos" ) then
outputConsole ( "SUCCESS" )
outputChatBox ( "SUCCESS", getRootElement(), 255, 255, 255, true )
else
outputConsole ( "FAILURE" )
outputChatBox ( "FAILURE", getRootElement(), 255, 255, 255, true )
end
end
 
addEventHandler ("onClientChatMessage", getRootElement(), ClientChat)

There that'll work.

You wrote "OnClientChatMessage" instead of "onClientChatMessage".

Cheers ;)

Nidza

Share this post


Link to post

You're not major noob... It happens if you're still an unexperienced scripter. Don't worry experience comes with time, CodeMaster :P

For client-side outputChatBox, 2nd arguments is not visibleTo.. it's the red colour.

Frugle, use /debugscript 3, command to open a "debug window" where you'll see all the errors/warnings when executing your scripts but before you type that command in you have to login as an admin.

Share this post


Link to post
I've tried everything but I can't get it to work.

Show us your current code and tell us what you do to test the script.

Share this post


Link to post
function joinHandler()
local x = 244.0065612793
local y = 2507.7377929688
local z = 16.496959686279
spawnPlayer(source, x, y, z)
fadeCamera(source, true)
setCameraTarget(source, source)
outputChatBox("Welcome to My Server", source)
end
addEventHandler("onPlayerJoin", getRootElement(), joinHandler)
 
 
function ClientChat(text)
if ( text == "pos" ) then
outputConsole( "SUCCESS" )
outputChatBox( "SUCCESS" )
else 
outputConsole( "FAILURE" )
outputChatBox( "FAILURE" )
end
end
 
addEventHandler ("onClientChatMessage", getRootElement(), ClientChat)

I test it by typing pos to ingame chat. Typing something else doesn't output "FAILURE" too.

Share this post


Link to post

onClientChatMessage is triggerend whenever text is shown in the chat box (even with outputChatBox). So when you outputChatBox( "FAILURE" ) you this will trigger the event again and again and again.. It's like infinite loop. Besides the "text" that is shown in the chatbox is not only the text you typed in but also your nickname and colours. Eg.:

"Me: hello"

the "text" argument will be like:

"Me: #COLOURhello"

I'm just wondering why you need to use "pos" only in chatbox. Can't you use addCommandHandler()?

Share this post


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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.