xXMADEXx Posted March 29, 2013 Share Posted March 29, 2013 Hello everybody! Today ill be teaching you how to make a basic jail system. So, lets not waste any time and get started. First, you will need to make a function, that only an admin can execute. function onPlayerJail(player) local chat = outputChatBox -- Lets define "chat" to "outputChatBox" just to save some time if(isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)),aclGetGroup("Admin")) then -- Check if the player is in the Admin ACL group. else -- And if their not in the admin ACL chat("Jail: Your not an admin.",player,255,0,0) -- this is really going to do: outputChatBox("Jail: Your not an admin.",player,255,0,0) end end So, now that we have the admin lock on, we can get started on the other player functions . So, now is what you want to do is change "function onPlayerJail(player)" to "function onPlayerJail(player,command,player2,time,reason)". This will make it, so that you can create a timer until the jailed person is released, it will let you select a player to be jailed, and you can enter a reason for them to be jailed. Now that we have that, we will need to get the player to be jailed, and put them into the jail cell, if all the arguments return true. When you finish your code, it should look somthing like this: jailx, jaily, jailz = 1516, -1462, 10 -- You can change to custom cordinates. jailInterior = 0 jailDimension = 0 releaseX, releaseY, releaseZ = 1546, -1675, 14 -- the release cordinates of the jail releaseInterior = 0-- The interior that they will be released to releaseDimension= 0 -- The dimension that they will be released to. function onPlayerJail(player,command,player2,timer,reason) timer = timer -- I just do this incase, for the timer function. local chat = outputChatBox -- Lets define "chat" to "outputChatBox" just to save some time prisoner = getPlayerFromName(player2) -- This will get the player who you wan tto jail. if(isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)),aclGetGroup("Admin")) then -- Check if the player is in the Admin ACL group. if (timer) then if (prisoner) then -- if "player2" is a valid player then --- Here Is Where Most of the coding will take place. --- setElementPosition(prisoner,jailx, jaily, jailz) -- Take them to jail setElementInterior(prisoner,jailInterior) -- If they where in an interior, set them to your jails interior setElementDimension(prisoner,jailDimension) -- set them to the jail dimension (opsional) chat("Jail: "..getPlayerName(player).." has jailed "..player2.." for "..timer.." seconds.",root,255,0,0) chat("Jail: Reason: "..reason,root,255,0,0) jailTimer = ( -- Set the timer, of the player to be released. function () chat("Jail: "..player2.." has been released from jail.",255,255,0) setElementPosition(prisoner,releaseX, releaseY, releaseZ)-- Set their position when they get released SetElementDimension(prisoner,releaseDimension) -- set they dimensioon to the release dimension setElementInterior(prisoner,releaseInterior) -- set their interior to the defined release interior end, timer * 1000, 1 -- Will convert the timer into miliseconds. ) -- End the timer function else chat("Jail: "..player2.." isn't a valid player.",player,255,0,0) end else chat("Jail: /"..command.." [prisoner] [time(seconds)] [reason]",player,255,0,0) -- If they didn't enter a time, then outputChatBox that message. end else -- And if their not in the admin ACL chat("Jail: Your not an admin.",player,255,0,0) -- this is really going to do: outputChatBox("Jail: Your not an admin.",player,255,0,0) end end addCommandHandler("jail",onPlayerJail) This code may NOT work, i haven't tested it. If it doesn't work, its most likely just a spelling error. I hope this helped you. And please, don't just take the code, study it to help you with LUA. Link to comment
ixjf Posted March 29, 2013 Share Posted March 29, 2013 Your code is wrong, as you said, it's a spelling error (you wrote setElementDimension with a capital 's'). And please use local variables WHEREVER you can. There may be other errors but I haven't checked the whole code. Link to comment
xXMADEXx Posted March 29, 2013 Author Share Posted March 29, 2013 Your code is wrong, as you said, it's a spelling error (you wrote setElementDimension with a capital 's'). And please use local variables WHEREVER you can.There may be other errors but I haven't checked the whole code. Read write below the final code Link to comment
ixjf Posted March 29, 2013 Share Posted March 29, 2013 Read write below the final code Your code is wrong, as you said, it's a spelling error (you wrote setElementDimension with a capital 's'). And please use local variables WHEREVER you can.There may be other errors but I haven't checked the whole code. Link to comment
Sasu Posted March 30, 2013 Share Posted March 30, 2013 This code may NOT work, i haven't tested it. If it doesn't work, its most likely just a spelling error. Link to comment
Recommended Posts