xXMADEXx Posted January 26, 2013 Share Posted January 26, 2013 Hey guys, how can i make this, so that it will not send a message, if there is no text in "ed_msg"? And, how can i make it so that when they send a message, it will outputChatBox("You sent an SMS to "..who, but instead of it showing the player's id, it will show there name? -- GUI local resX,resY = guiGetScreenSize() local width,height = 422,217 local X = (resX/2) - (width/2) local Y = (resY/2) - (height/2) window = guiCreateWindow(X,Y,width,height,"Send A Message",false) guiWindowSetSizable(window,false) guiSetVisible(window,false) playerList = guiCreateGridList(10,25,403,109,false,window) guiGridListSetSelectionMode(playerList,2) column = guiGridListAddColumn(playerList,"Players",0.9) ed_msg = guiCreateEdit(89,138,320,38,"",false,window) btn_send = guiCreateButton(9,180,180,28,"Send!",false,window) btn_close = guiCreateButton(209,180,201,28,"Cancel",false,window) lbl_msg = guiCreateLabel(21,147,62,25,"Message:",false,window) guiSetProperty(btn_send,"HoverTextColour","ffffff000") guiSetProperty(btn_close,"HoverTextColour","fff000000") guiLabelSetColor(lbl_msg,0,255,0) guiSetFont(lbl_msg,"default-bold-small") guiEditSetMaxLength(ed_msg,80) -- Open GUI bindKey("h", "down", function ( ) guiSetVisible(window, not guiGetVisible ( window )) showCursor(guiGetVisible ( window )) if ( guiGetVisible ( window ) ) then guiGridListClear ( playerList ) if ( column ) then for id, player in ipairs ( getElementsByType ( "player" ) ) do local row = guiGridListAddRow ( playerList ) local r, g, b = getPlayerNametagColor ( player ) guiGridListSetItemText ( playerList, row, column, getPlayerName ( player ), false, false ) guiGridListSetItemColor ( playerList, row, column, r, g, b ) end end end end ) -- Close Button addEventHandler("onClientGUIClick",btn_close, function () if (source == btn_close) then guiSetVisible(window, false) showCursor(false,false) end end ) -- Send function send() local who = guiGridListGetSelectedItem(playerList) local msg = tostring(guiGetText(ed_msg)) if (source == btn_send) then outputChatBox("Message sent to "..who,0,255,255) if (msg == "") then ouputChatBox("Error: You need to enter a message.",255,0,0) cancelEvent() end end end addEventHandler("onClientGUIClick",btn_send,send) Link to comment
Castillo Posted January 27, 2013 Share Posted January 27, 2013 -- GUI local resX,resY = guiGetScreenSize() local width,height = 422,217 local X = (resX/2) - (width/2) local Y = (resY/2) - (height/2) window = guiCreateWindow(X,Y,width,height,"Send A Message",false) guiWindowSetSizable(window,false) guiSetVisible(window,false) playerList = guiCreateGridList(10,25,403,109,false,window) guiGridListSetSelectionMode(playerList,2) column = guiGridListAddColumn(playerList,"Players",0.9) ed_msg = guiCreateEdit(89,138,320,38,"",false,window) btn_send = guiCreateButton(9,180,180,28,"Send!",false,window) btn_close = guiCreateButton(209,180,201,28,"Cancel",false,window) lbl_msg = guiCreateLabel(21,147,62,25,"Message:",false,window) guiSetProperty(btn_send,"HoverTextColour","ffffff000") guiSetProperty(btn_close,"HoverTextColour","fff000000") guiLabelSetColor(lbl_msg,0,255,0) guiSetFont(lbl_msg,"default-bold-small") guiEditSetMaxLength(ed_msg,80) -- Open GUI bindKey("h", "down", function ( ) guiSetVisible(window, not guiGetVisible ( window )) showCursor(guiGetVisible ( window )) if ( guiGetVisible ( window ) ) then guiGridListClear ( playerList ) if ( column ) then for id, player in ipairs ( getElementsByType ( "player" ) ) do local row = guiGridListAddRow ( playerList ) local r, g, b = getPlayerNametagColor ( player ) guiGridListSetItemText ( playerList, row, column, getPlayerName ( player ), false, false ) guiGridListSetItemColor ( playerList, row, column, r, g, b ) end end end end ) -- Close Button addEventHandler("onClientGUIClick",btn_close, function () if (source == btn_close) then guiSetVisible(window, false) showCursor(false,false) end end ) -- Send function send() local row, col = guiGridListGetSelectedItem ( playerList ) if ( row and col and row ~= -1 and col ~= -1 ) then local who = guiGridListGetItemText ( playerList, row, 1 ) local msg = tostring(guiGetText(ed_msg)) if ( msg == "" ) then ouputChatBox ( "Error: You need to enter a message.",255,0,0 ) else outputChatBox("Message sent to "..who,0,255,255) end end end addEventHandler("onClientGUIClick",btn_send,send,false) Link to comment
xXMADEXx Posted January 27, 2013 Author Share Posted January 27, 2013 Thank you, and will i have to make a "triggerServerEvent" for the message to send to the player? Link to comment
xXMADEXx Posted January 27, 2013 Author Share Posted January 27, 2013 Yes, that's right. k, can you help me on the server side, i really dont have a clue what to do with it... This is baicly, what i got. -- Client -- GUI local resX,resY = guiGetScreenSize() local width,height = 422,217 local X = (resX/2) - (width/2) local Y = (resY/2) - (height/2) window = guiCreateWindow(X,Y,width,height,"Send A Message",false) guiWindowSetSizable(window,false) guiSetVisible(window,false) playerList = guiCreateGridList(10,25,403,109,false,window) guiGridListSetSelectionMode(playerList,2) column = guiGridListAddColumn(playerList,"Players",0.9) ed_msg = guiCreateEdit(89,138,320,38,"",false,window) btn_send = guiCreateButton(9,180,180,28,"Send!",false,window) btn_close = guiCreateButton(209,180,201,28,"Cancel",false,window) lbl_msg = guiCreateLabel(21,147,62,25,"Message:",false,window) guiSetProperty(btn_send,"HoverTextColour","ffffff000") guiSetProperty(btn_close,"HoverTextColour","fff000000") guiLabelSetColor(lbl_msg,0,255,0) guiSetFont(lbl_msg,"default-bold-small") guiEditSetMaxLength(ed_msg,80) -- Open GUI bindKey("h", "down", function ( ) guiSetVisible(window, not guiGetVisible ( window )) showCursor(guiGetVisible ( window )) if ( guiGetVisible ( window ) ) then guiGridListClear ( playerList ) if ( column ) then for id, player in ipairs ( getElementsByType ( "player" ) ) do local row = guiGridListAddRow ( playerList ) local r, g, b = getPlayerNametagColor ( player ) guiGridListSetItemText ( playerList, row, column, getPlayerName ( player ), false, false ) guiGridListSetItemColor ( playerList, row, column, r, g, b ) end end end end ) -- Close Button addEventHandler("onClientGUIClick",btn_close, function () if (source == btn_close) then guiSetVisible(window, false) showCursor(false,false) end end ) -- Send function send() local row, col = guiGridListGetSelectedItem ( playerList ) if ( row and col and row ~= -1 and col ~= -1 ) then local who = guiGridListGetItemText ( playerList, row, 1 ) local msg = tostring(guiGetText(ed_msg)) triggerServerEvent("rog:sms:send",localplayer,localplayer) if ( msg == "" ) then ouputChatBox ( "Error: You need to enter a message.",255,0,0 ) else outputChatBox("Message sent to "..who,0,255,255) end end end addEventHandler("onClientGUIClick",btn_send,send,false) -- Server function recive(player) -- LOL -- end addEvent("rog:sms:send",true) addEventHandler("rog:sms:send",recive) Link to comment
Castillo Posted January 27, 2013 Share Posted January 27, 2013 -- client side: -- GUI local resX,resY = guiGetScreenSize() local width,height = 422,217 local X = (resX/2) - (width/2) local Y = (resY/2) - (height/2) window = guiCreateWindow(X,Y,width,height,"Send A Message",false) guiWindowSetSizable(window,false) guiSetVisible(window,false) playerList = guiCreateGridList(10,25,403,109,false,window) guiGridListSetSelectionMode(playerList,2) column = guiGridListAddColumn(playerList,"Players",0.9) ed_msg = guiCreateEdit(89,138,320,38,"",false,window) btn_send = guiCreateButton(9,180,180,28,"Send!",false,window) btn_close = guiCreateButton(209,180,201,28,"Cancel",false,window) lbl_msg = guiCreateLabel(21,147,62,25,"Message:",false,window) guiSetProperty(btn_send,"HoverTextColour","ffffff000") guiSetProperty(btn_close,"HoverTextColour","fff000000") guiLabelSetColor(lbl_msg,0,255,0) guiSetFont(lbl_msg,"default-bold-small") guiEditSetMaxLength(ed_msg,80) -- Open GUI bindKey("h", "down", function ( ) guiSetVisible(window, not guiGetVisible ( window )) showCursor(guiGetVisible ( window )) if ( guiGetVisible ( window ) ) then guiGridListClear ( playerList ) if ( column ) then for id, player in ipairs ( getElementsByType ( "player" ) ) do local row = guiGridListAddRow ( playerList ) local r, g, b = getPlayerNametagColor ( player ) guiGridListSetItemText ( playerList, row, column, getPlayerName ( player ), false, false ) guiGridListSetItemColor ( playerList, row, column, r, g, b ) end end end end ) -- Close Button addEventHandler("onClientGUIClick",btn_close, function () if (source == btn_close) then guiSetVisible(window, false) showCursor(false,false) end end ) -- Send function send ( ) local row, col = guiGridListGetSelectedItem ( playerList ) if ( row and col and row ~= -1 and col ~= -1 ) then local who = guiGridListGetItemText ( playerList, row, 1 ) local msg = tostring ( guiGetText ( ed_msg ) ) local playerWho = getPlayerFromName ( who ) if ( not playerWho ) then return outputChatBox ( "Player is no longer online." ) end if ( msg == "" ) then ouputChatBox ( "Error: You need to enter a message.",255,0,0 ) else triggerServerEvent ( "rog:sms:send", localPlayer, playerWho, msg ) outputChatBox ( "Message sent to ".. who, 0, 255, 255 ) end end end addEventHandler("onClientGUIClick",btn_send,send,false) -- server side: function recive ( player, msg ) outputChatBox ( "PM from: ".. getPlayerName ( source ) ..": ".. msg, player ) end addEvent ( "rog:sms:send", true ) addEventHandler ( "rog:sms:send", root, recive ) Link to comment
xXMADEXx Posted January 27, 2013 Author Share Posted January 27, 2013 Thanks, but it didn't work So i wrote the server side: addEventHandler("rog:sms:send", function (player) outputChatBox ( "SMS From: ".. getPlayerName ( source) ..": ".. msg, player, 255, 255, 0 ) end ) addEvent("rog:sms:send",true) and its saying, something is wrong with the even handler. Link to comment
manve1 Posted January 27, 2013 Share Posted January 27, 2013 (edited) addEventHandler("rog:sms:send", root, function (player, msg) outputChatBox ( "SMS From: ".. getPlayerName ( source) ..": ".. msg, player, 255, 255, 0 ) end ) addEvent("rog:sms:send",true) Edited January 27, 2013 by Guest Link to comment
Castillo Posted January 27, 2013 Share Posted January 27, 2013 Thanks, but it didn't work So i wrote the server side: addEventHandler("rog:sms:send", function (player) outputChatBox ( "SMS From: ".. getPlayerName ( source) ..": ".. msg, player, 255, 255, 0 ) end ) addEvent("rog:sms:send",true) and its saying, something is wrong with the even handler. Copy the server side again, you had forgot to put 'root' at addEventHandler. Link to comment
xXMADEXx Posted January 27, 2013 Author Share Posted January 27, 2013 Thanks, but it didn't work So i wrote the server side: addEventHandler("rog:sms:send", function (player) outputChatBox ( "SMS From: ".. getPlayerName ( source) ..": ".. msg, player, 255, 255, 0 ) end ) addEvent("rog:sms:send",true) and its saying, something is wrong with the even handler. Copy the server side again, you had forgot to put 'root' at addEventHandler. debugscript: sms\s.lua:4 attempt to concatenate global 'msg' (a nil value) Link to comment
xXMADEXx Posted January 27, 2013 Author Share Posted January 27, 2013 (edited) Mine works here. never mind, i dont know what i did, but i guess i fixed it thank you. Edited January 27, 2013 by Guest Link to comment
Blaawee Posted January 27, 2013 Share Posted January 27, 2013 Mine works here. hum... weird. you forget the second argument in the server side Link to comment
Castillo Posted January 27, 2013 Share Posted January 27, 2013 Mine works here. hum... weird. You are obviously using manve's, since he forgot to define 'msg'. 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