Price. Posted October 22, 2014 Share Posted October 22, 2014 so basically I was trying to make that if you do /afk you go to another dimension and when you press W ,S,D or A buttons, you get back to main dimension as you're back from afk, but idk got some errors when I put local player gives me error Line 32: attempt to compare a number with boolean line 31: Bad argument @ 'getElementDimension' [expected element at argument 1, got nil] and some errors when i do /afk line 7: Bad argument @ 'isPedinVehicle' [Expected ped at argument 1, got string 'afk'] same error at line 2 'getPedOccupiedVehicle same @ line 10:'isPedonGround' function afkCommand(thePlayer, cmd, r, g, b) local theVehicle = getPedOccupiedVehicle ( thePlayer ) local level = getPlayerWantedLevel ( thePlayer ) if ( level > 0 ) then outputChatBox("You cannot go AFK while being wanted!", thePlayer, 255, 255, 255) else if isPedInVehicle(thePlayer) then outputChatBox("You must be on foot to use this command.", thePlayer, 255, 255, 255) else if isPedOnGround(thePlayer) then if getElementDimension(thePlayer) < 10 then outputChatBox("You will be AFK in 5 seconds", thePlayer, 255, 255, 255) setTimer( function() setElementDimension(thePlayer, math.random(10, 1000)) setElementFrozen(thePlayer, true) end, 5000, 1 ) end else outputChatBox("You must be on the ground to use this command.", thePlayer, 255, 255, 255) end end end end addCommandHandler("afk", afkCommand) function returnafk (button, press, thePlayer, r, g, b ) if (press) then if button == "w" or button == "s" or button == "d" or button == "a" then local dimPlr = getElementDimension(thePlayer) if ((dimPlr >= 10) and (dimPlr <= 1000)) then setElementDimension(thePlayer, 0) setElementFrozen(thePlayer, false) outputChatBox("You are no longer AFK", thePlayer, 255, 255, 255) end end end end addEventHandler("onClientKey", root, returnafk) Link to comment
Anubhav Posted October 22, 2014 Share Posted October 22, 2014 function afkCommand(thePlayer, cmd, r, g, b) local theVehicle = getPedOccupiedVehicle ( thePlayer ) local level = getPlayerWantedLevel ( thePlayer ) if ( level > 0 ) then outputChatBox("You cannot go AFK while being wanted!", thePlayer, 255, 255, 255) else if theVehicle then outputChatBox("You must be on foot to use this command.", thePlayer, 255, 255, 255) else if isPedOnGround(thePlayer) then if getElementDimension(thePlayer) < 10 then outputChatBox("You will be AFK in 5 seconds", thePlayer, 255, 255, 255) setTimer( function() setElementDimension(thePlayer, math.random(10, 1000)) setElementFrozen(thePlayer, true) end, 5000, 1 ) end else outputChatBox("You must be on the ground to use this command.", thePlayer, 255, 255, 255) end end end end addCommandHandler("afk", afkCommand) function returnafk (button, press, thePlayer, r, g, b ) if (press) then if button == "w" or button == "s" or button == "d" or button == "a" then local dimPlr = getElementDimension(thePlayer) if ((dimPlr >= 10) and (dimPlr <= 1000)) then setElementDimension(thePlayer, 0) setElementFrozen(thePlayer, false) outputChatBox("You are no longer AFK", thePlayer, 255, 255, 255) end end end end addEventHandler("onClientKey", root, returnafk) Link to comment
Moderators IIYAMA Posted October 22, 2014 Moderators Share Posted October 22, 2014 (edited) clientside addCommandHandler has a differed syntax: Serverside: player playerSource, string commandName, [string arg1, string arg2, ...] Clientside: string commandName, [string arg1, string arg2, ...] Use at clientside localPlayer instead. (DON'T DEFINE localPlayer INSIDE THE FUNCTION) Edited October 22, 2014 by Guest Link to comment
Price. Posted October 22, 2014 Author Share Posted October 22, 2014 line 3: bad argument @'getPedOccupiedVehicle' [Expected ped at argument 1, got string 'afk'] line 11: Bad argument @'isPedonGround [Expected ped at argument 1, got string 'afk'] line 22: bad argument @'outputchatbox' [Expected bool at argument 5, got number '255'] I've tried using localplayer and thePlayer, both same result Link to comment
Moderators IIYAMA Posted October 22, 2014 Moderators Share Posted October 22, 2014 Please convert you code to clientside, follow the instructions of my post before. Link to comment
Price. Posted October 22, 2014 Author Share Posted October 22, 2014 did the same you requested and its already in client side, same. Link to comment
Moderators IIYAMA Posted October 22, 2014 Moderators Share Posted October 22, 2014 The file is clientside, the code you are using is not. Post it again if you followed my instructions. Link to comment
Price. Posted October 22, 2014 Author Share Posted October 22, 2014 tried removing all definitions from function and got this 1 only error line 13: bad argument @'outputChatbox"[Expected number at argument 2, got player function afkCommand() local theVehicle = getPedOccupiedVehicle ( localPlayer ) local level = getPlayerWantedLevel ( localPlayer ) if ( level > 0 ) then outputChatBox("You cannot go AFK while being wanted!", localPlayer, 255, 255, 255) else if theVehicle then outputChatBox("You must be on foot to use this command.", localPlayer, 255, 255, 255) else if isPedOnGround(localPlayer) then if getElementDimension(localPlayer) < 10 then outputChatBox("You will be AFK in 5 seconds", localPlayer, 255, 255, 255) setTimer( function() setElementDimension(localPlayer, math.random(10, 1000)) setElementFrozen(localPlayer, true) end, 5000, 1 ) end else outputChatBox("You must be on the ground to use this command.", localPlayer, 255, 255, 255) end end end end addCommandHandler("afk", afkCommand) function returnafk (button, press, r, g, b ) if (press) then if button == "w" or button == "s" or button == "d" or button == "a" then local dimPlr = getElementDimension(localPlayer) if ((dimPlr >= 10) and (dimPlr <= 1000)) then setElementDimension(localPlayer, 0) setElementFrozen(localPlayer, false) outputChatBox("You are no longer AFK", localPlayer, 255, 255, 255) end end end end addEventHandler("onClientKey", root, returnafk) Link to comment
Moderators IIYAMA Posted October 22, 2014 Moderators Share Posted October 22, 2014 See syntax of clientside outputChatBox and serverside outputChatBox, then you know what you are doing wrong. Server bool outputChatBox ( string text [, element visibleTo=getRootElement(), int r=231, int g=217, int b=176, bool colorCoded=false ] ) Client bool outputChatBox ( string text [, int r=231, int g=217, int b=176, bool colorCoded=false ] ) Clientside doesn't need a target to send it too, since it happens on the client his pc. Link to comment
Price. Posted October 22, 2014 Author Share Posted October 22, 2014 oooooh wow, such a stupid mistake . thanks for solving this for me, uhm just 1 more thing I wanted to try that if you do /afk too you get |AFK beside your name but I got no idea to start with Link to comment
Moderators IIYAMA Posted October 22, 2014 Moderators Share Posted October 22, 2014 Try this: Serverside addEvent("afkStatus",true) addEventHandler("afkStatus",root, function (status) if status then setPlayerName (client,getPlayerName(client).. "|AFK") else local name = string.gsub(getPlayerName(client),"|AFK", "") if name then setPlayerName (client,name) end end end) Set afk triggerServerEvent("afkStatus",localPlayer,true) Set not afk. triggerServerEvent("afkStatus",localPlayer,false) Link to comment
Price. Posted October 22, 2014 Author Share Posted October 22, 2014 nothing in debug and my name doesnt change Client function afkCommand() local theVehicle = getPedOccupiedVehicle ( localPlayer ) local level = getPlayerWantedLevel ( localPlayer ) if ( level > 0 ) then outputChatBox("You cannot go AFK while being wanted!", 255, 255, 255) else if theVehicle then outputChatBox("You must be on foot to use this command.", 255, 255, 255) else if isPedOnGround(localPlayer) then if getElementDimension(localPlayer) < 10 then triggerServerEvent("afkStatus",localPlayer,true) outputChatBox("You will be AFK in 5 seconds" , 255, 255, 255) setTimer( function() setElementDimension(localPlayer, math.random(10, 1000)) setElementFrozen(localPlayer, true) end, 5000, 1 ) else outputChatBox("You must be on the ground to use this command.", 255,255,255) end end end end end addCommandHandler("afk", afkCommand) function returnafk (button, press, r, g, b ) if (press) then if button == "w" or button == "s" or button == "d" or button == "a" then local dimPlr = getElementDimension(localPlayer) if ((dimPlr >= 10) and (dimPlr <= 1000)) then triggerServerEvent("afkStatus",localPlayer,false) setElementDimension(localPlayer, 0) setElementFrozen(localPlayer, false) outputChatBox("You are no longer AFK", 255, 255, 255) end end end end addEventHandler("onClientKey", root, returnafk) server addEvent("afkStatus",true) addEventHandler("afkStatus",root, function (status) if status then setPlayerName (client,getPlayerName(client).. "|AFK") else local name = string.gsub(getPlayerName(client),"|AFK", "") if name then setPlayerName (client,name) end end end) Link to comment
Moderators IIYAMA Posted October 22, 2014 Moderators Share Posted October 22, 2014 add some manually debug inside your code: outputDebugString("write here which part of the code get executed") Also make sure your name isn't too long. ( Maximum player name length is 22 characters. ) Link to comment
Price. Posted October 22, 2014 Author Share Posted October 22, 2014 still nothing, should it be added like that? Client: function afkCommand() ouputDebugString("write here which part of the code get executed") local theVehicle = getPedOccupiedVehicle ( localPlayer ) local level = getPlayerWantedLevel ( localPlayer ) if ( level > 0 ) then outputChatBox("You cannot go AFK while being wanted!", 255, 255, 255) else if theVehicle then outputChatBox("You must be on foot to use this command.", 255, 255, 255) else if isPedOnGround(localPlayer) then if getElementDimension(localPlayer) < 10 then triggerServerEvent("afkStatus",localPlayer,true) outputChatBox("You will be AFK in 5 seconds" , 255, 255, 255) setTimer( function() setElementDimension(localPlayer, math.random(10, 1000)) setElementFrozen(localPlayer, true) end, 5000, 1 ) else outputChatBox("You must be on the ground to use this command.", 255,255,255) end end end end end addCommandHandler("afk", afkCommand) function returnafk (button, press, r, g, b ) if (press) then if button == "w" or button == "s" or button == "d" or button == "a" then local dimPlr = getElementDimension(localPlayer) if ((dimPlr >= 10) and (dimPlr <= 1000)) then triggerServerEvent("afkStatus",localPlayer,false) setElementDimension(localPlayer, 0) setElementFrozen(localPlayer, false) outputChatBox("You are no longer AFK", 255, 255, 255) end end end end addEventHandler("onClientKey", root, returnafk) Link to comment
Moderators IIYAMA Posted October 22, 2014 Moderators Share Posted October 22, 2014 you copied it too fast, I made a typo. outputDebugString Add it at every part of the code you aren't sure it does get executed.(like server side for example) Link to comment
Price. Posted October 22, 2014 Author Share Posted October 22, 2014 same nothing appears client: function afkCommand() outputDebugString local theVehicle = getPedOccupiedVehicle ( localPlayer ) local level = getPlayerWantedLevel ( localPlayer ) if ( level > 0 ) then outputChatBox("You cannot go AFK while being wanted!", 255, 255, 255) else if theVehicle then outputChatBox("You must be on foot to use this command.", 255, 255, 255) else if isPedOnGround(localPlayer) then if getElementDimension(localPlayer) < 10 then outputDebugString triggerServerEvent("afkStatus",localPlayer,true) outputDebugString outputChatBox("You will be AFK in 5 seconds" , 255, 255, 255) setTimer( function() setElementDimension(localPlayer, math.random(10, 1000)) setElementFrozen(localPlayer, true) end, 5000, 1 ) else outputChatBox("You must be on the ground to use this command.", 255,255,255) end end end end end addCommandHandler("afk", afkCommand) function returnafk (button, press, r, g, b ) if (press) then if button == "w" or button == "s" or button == "d" or button == "a" then local dimPlr = getElementDimension(localPlayer) if ((dimPlr >= 10) and (dimPlr <= 1000)) then outputDebugString triggerServerEvent("afkStatus",localPlayer,false) outputDebugString setElementDimension(localPlayer, 0) setElementFrozen(localPlayer, false) outputChatBox("You are no longer AFK", 255, 255, 255) end end end end addEventHandler("onClientKey", root, returnafk) server outputDebugString addEvent("afkStatus",true) addEventHandler("afkStatus",root, function (status) if status then setPlayerName (client,getPlayerName(client).. "|AFK") else local name = string.gsub(getPlayerName(client),"|AFK", "") outputDebugString if name then setPlayerName (client,name) end end end) PS: the afk is related to chat, like when you say any word having any of these letters"A,W,S or D" you get back from AFK Link to comment
Moderators IIYAMA Posted October 22, 2014 Moderators Share Posted October 22, 2014 You have to use outputDebugString the same as outputChatBox, does nothing else then outputChatBox in to your debug. These debug logs are meant for you, so you can see what is going on. addEvent("afkStatus",true) addEventHandler("afkStatus",root, function (status) outputDebugString("serverside part executed") if status then setPlayerName (client,getPlayerName(client).. "|AFK") outputDebugString("set to afk") else local name = string.gsub(getPlayerName(client),"|AFK", "") if name then outputDebugString("set to not afk") setPlayerName (client,name) end end end) Sorry I do not have notepad ++ on my mac...... so no tabs. Link to comment
Price. Posted October 22, 2014 Author Share Posted October 22, 2014 same nothing client function afkCommand() outputDebugString("set to not afk") local theVehicle = getPedOccupiedVehicle ( localPlayer ) local level = getPlayerWantedLevel ( localPlayer ) if ( level > 0 ) then outputChatBox("You cannot go AFK while being wanted!", 255, 255, 255) else if theVehicle then outputChatBox("You must be on foot to use this command.", 255, 255, 255) else if isPedOnGround(localPlayer) then if getElementDimension(localPlayer) < 10 then outputDebugString("set to not afk") triggerServerEvent("afkStatus",localPlayer,true) outputDebugString("set to not afk") outputChatBox("You will be AFK in 5 seconds" , 255, 255, 255) setTimer( function() setElementDimension(localPlayer, math.random(10, 1000)) setElementFrozen(localPlayer, true) end, 5000, 1 ) else outputChatBox("You must be on the ground to use this command.", 255,255,255) end end end end end addCommandHandler("afk", afkCommand) function returnafk (button, press, r, g, b ) if (press) then if button == "w" or button == "s" or button == "d" or button == "a" then local dimPlr = getElementDimension(localPlayer) if ((dimPlr >= 10) and (dimPlr <= 1000)) then outputDebugString("set to not afk") triggerServerEvent("afkStatus",localPlayer,false) outputDebugString("set to not afk") setElementDimension(localPlayer, 0) setElementFrozen(localPlayer, false) outputChatBox("You are no longer AFK", 255, 255, 255) end end end end addEventHandler("onClientKey", root, returnafk) server addEvent("afkStatus",true) addEventHandler("afkStatus",root, function (status) outputDebugString("serverside part executed") if status then setPlayerName (client,getPlayerName(client).. "|AFK") outputDebugString("set to afk") else local name = string.gsub(getPlayerName(client),"|AFK", "") if name then outputDebugString("set to not afk") setPlayerName (client,name) end end end) Link to comment
Moderators IIYAMA Posted October 22, 2014 Moderators Share Posted October 22, 2014 What do you mean with nothing? You are the one who needs to debugging it, show me the debug results. and it is stupid to use the same debug text all over the script, you need to write what happens there. Not just copy my text, so you don't know what part of the code get executed. Don't forget the /debugscript 3 Link to comment
Price. Posted October 22, 2014 Author Share Posted October 22, 2014 k changed the texts only, it doesnt matter as long as it doesn't show anything in char nor /debugscript 3 not even in server console Client function afkCommand() outputDebugString("testing this section") local theVehicle = getPedOccupiedVehicle ( localPlayer ) local level = getPlayerWantedLevel ( localPlayer ) if ( level > 0 ) then outputChatBox("You cannot go AFK while being wanted!", 255, 255, 255) else if theVehicle then outputChatBox("You must be on foot to use this command.", 255, 255, 255) else if isPedOnGround(localPlayer) then if getElementDimension(localPlayer) < 10 then outputDebugString("trying to figure it out") triggerServerEvent("afkStatus",localPlayer,true) outputDebugString("just another test") outputChatBox("You will be AFK in 5 seconds" , 255, 255, 255) setTimer( function() setElementDimension(localPlayer, math.random(10, 1000)) setElementFrozen(localPlayer, true) end, 5000, 1 ) else outputChatBox("You must be on the ground to use this command.", 255,255,255) end end end end end addCommandHandler("afk", afkCommand) function returnafk (button, press, r, g, b ) if (press) then if button == "w" or button == "s" or button == "d" or button == "a" then local dimPlr = getElementDimension(localPlayer) if ((dimPlr >= 10) and (dimPlr <= 1000)) then outputDebugString("random text") triggerServerEvent("afkStatus",localPlayer,false) outputDebugString("another test") setElementDimension(localPlayer, 0) setElementFrozen(localPlayer, false) outputChatBox("You are no longer AFK", 255, 255, 255) end end end end addEventHandler("onClientKey", root, returnafk) addEvent("afkStatus",true) addEventHandler("afkStatus",root, function (status) outputDebugString("serverside part executed") if status then setPlayerName (client,getPlayerName(client).. "|AFK") outputDebugString("set to afk") else local name = string.gsub(getPlayerName(client),"|AFK", "") if name then outputDebugString("set to not afk") setPlayerName (client,name) end end end) Link to comment
Price. Posted October 22, 2014 Author Share Posted October 22, 2014 What does not work? sorry for double reply but uhm as I said I wanted to do as when i do /afk a text |AFK gets added BESIDES his name not to change his entire name to AFK but to put |AFK besides his name, and actually Nothing really happens with the code so we are trying to debug the script manually still nothing happens. Link to comment
TAPL Posted October 22, 2014 Share Posted October 22, 2014 I tested the code and it work except it won't work if your name was long. Link to comment
Price. Posted October 22, 2014 Author Share Posted October 22, 2014 I called my self Price in-game, does it add "|AFK" beside your name? I'am testing on local server on MTA Link to comment
TAPL Posted October 22, 2014 Share Posted October 22, 2014 http://i.imgur.com/M6yASj3.jpg http://i.imgur.com/ZyZPqHK.jpg 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