Noki Posted January 31, 2014 Share Posted January 31, 2014 (edited) Hello, I made this AFK script (client sided) and I cannot get it to work. It just returns bad arguments at 'isPedInVehicle' and 'isPedOnGround'. local theVehicle = getPedOccupiedVehicle(localPlayer) function afkCommand(localPlayer) if isPedInVehicle(localPlayer) then outputChatBox("You must be on foot to use this command.", localPlayer, 255, 255, 255) elseif isPedOnGround(localPlayer) then if (getElementPosition(localPlayer) ~= 0) 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) elseif (getElementDimension(localPlayer) >= 10) then outputChatBox("You will be returned to the main dimension in 5 seconds", localPlayer, 255, 255, 255) setTimer(function () setElementDimension(localPlayer, 0) setElementFrozen(localPlayer, false) end, 5000, 1) end end end addCommandHandler("afk", afkCommand) If someone could help me, or guide me in the right direction, I'd much appreciate it. Thank you, MTA community. Edited February 3, 2014 by Guest Link to comment
Cruze Posted January 31, 2014 Share Posted January 31, 2014 Try that local theVehicle = getPedOccupiedVehicle(localPlayer) function afkCommand(localPlayer) if (isPedInVehicle(localPlayer)) then outputChatBox("You must be on foot to use this command.", localPlayer, 255, 255, 255) elseif (isPedOnGround(localPlayer)) then if (getElementPosition(localPlayer) ~= 0) then outputChatBox("You will be AFK in 5 seconds", localPlayer, 255, 255, 255) setTimer(function () setElementPosition(localPlayer, math.random(10 - 1000)) setElementFrozen(localPlayer, true) end, 5000, 1) elseif (getElementPosition(localPlayer) >= 10) then outputChatBox("You will be returned to the main dimension in 5 seconds", localPlayer, 255, 255, 255) setTimer(function () setElementPosition(localPlayer, 0) setElementFrozen(localPlayer, false) end, 5000, 1) end end end addCommandHandler("afk", afkCommand) Link to comment
Baseplate Posted January 31, 2014 Share Posted January 31, 2014 You need to put 4 args at setElementPosition, you specified 2 only. That's first, second, no need for that "localPlayer" at first line, just delete it. Link to comment
Noki Posted January 31, 2014 Author Share Posted January 31, 2014 I was just realised I put position instead of dimension... Amateur mistake. Thank you, anyway. Link to comment
Noki Posted February 1, 2014 Author Share Posted February 1, 2014 I still need help. It still won't work, and returns bad arguments on isPedInVehicle and isPedOnGround. I've tried everything. Link to comment
pa3ck Posted February 1, 2014 Share Posted February 1, 2014 It's server side, right? Also, move this inside your function: local theVehicle = getPedOccupiedVehicle(localPlayer) Link to comment
Noki Posted February 1, 2014 Author Share Posted February 1, 2014 It is client side, but I am willing to change it, so long as it works. getPedOccupiedVehicle was for an earlier check, so I didn't use it. Link to comment
Noki Posted February 3, 2014 Author Share Posted February 3, 2014 I have tried, but it still outputs debug messages. It says there are bad arguments on 'isPedInVehicle' and 'isPedOnGround'. Once again, all help would be much appreciated, and you will be rewarded. Link to comment
WASSIm. Posted February 3, 2014 Share Posted February 3, 2014 try this. but make it server side is better function afkCommand( ) if (isPedOnGround(localPlayer)) then if (getElementDimension(localPlayer) < 10) then 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) elseif (getElementDimension(localPlayer) >= 10) then outputChatBox("You will be returned to the main dimension in 5 seconds", 255, 255, 255) setTimer(function () setElementDimension(localPlayer, 0) setElementFrozen(localPlayer, false) end, 5000, 1) end else outputChatBox("You must be on foot to use this command.", 255, 255, 255) end end addCommandHandler("afk", afkCommand) Link to comment
Cruze Posted February 4, 2014 Share Posted February 4, 2014 function afkCommand( ) if (isPedOnGround(client)) then if (getElementDimension(client) < 10) then outputChatBox("You will be AFK in 5 seconds", client, 255, 255, 255) setTimer(function () setElementDimension(client, math.random(10 - 1000)) setElementFrozen(client, true) end, 5000, 1) elseif (getElementDimension(client) >= 10) then outputChatBox("You will be returned to the main dimension in 5 seconds", client, 255, 255, 255) setTimer(function () setElementDimension(client, 0) setElementFrozen(client, false) end, 5000, 1) end else outputChatBox("You must be on foot to use this command.", client, 255, 255, 255) end end addCommandHandler("afk", afkCommand) Link to comment
Gtagasje Posted February 4, 2014 Share Posted February 4, 2014 Server side: function afkCommand(thePlayer, cmd) 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 ) elseif getElementDimension(thePlayer) >= 10 and getElementDimension(thePlayer) <= 1000 then outputChatBox("You will be returned to the main dimension in 5 seconds", thePlayer, 255, 255, 255) setTimer( function() setElementDimension(thePlayer, 0) setElementFrozen(thePlayer, false) end, 5000, 1 ) end else outputChatBox("You must be on the ground to use this command.", thePlayer, 255, 255, 255) end end end addCommandHandler("afk", afkCommand) Note: To make this script to work, don't make it client side. If you make it client side it will not work due to the arguments given in certain functions. Link to comment
Cruze Posted February 4, 2014 Share Posted February 4, 2014 what are u doing ? Changed from clientside ("localPlayer" works on client only) to serverside ("client" works on server only) 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