Advertisement
Guest User

POD/Seat protection E2 code

a guest
Dec 22nd, 2014
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.76 KB | None | 0 0
  1. @name Fancy Seat Secure_v3
  2. @inputs Pod:wirelink
  3. @persist O:entity Path:string [L Whitelist]:table
  4.  
  5. #[## Chatcommands:
  6. .sscs mode <>
  7. .sscs action <>
  8. .sscs lock
  9. .sscs eject
  10. .sscs kill
  11. #lock triggers the state, so if already locked it will be unlocked!
  12. .sscs whitelist add <>
  13.  
  14. EXAMPLES:
  15. .sscs mode owneronly
  16. .sscs mode freeforall
  17. .sscs mode secured
  18. .sscs action kill
  19. .sscs action eject
  20. .sscs lock
  21. .sscs unlock
  22. .sscs eject
  23. .sscs kill
  24. .sscs whitelist add gary
  25. .sscs whitelist remove gary
  26. .sscs whitelist players
  27.  
  28. ##Changelog:
  29. ..V3
  30. -Added .sscs eject
  31. -Added .sscs kill
  32.  
  33. ]###
  34. if ( first() | duped() ){
  35.     O = owner()
  36.     L = table("Name" = "[G.Tech] S.S.C.S.",
  37.         "Action" = "Eject",# = "Terminate"
  38.         "Mode" = "Secured",
  39.         "Version" = 3,
  40.         "Last_Modifyed" = "20.Dez.2014"
  41.         )
  42.     L["ChatPrefix",array] = array(vec(255, 150, 0),L["Name",string],vec()+255,": ")
  43.    
  44.     Whitelist = table(
  45.         "STEAM_0:0:20302138" = 1,#Allowing Gary, the coder to enter your seats. He is nice and always asks :)
  46.         "STEAMID OF SOMEONE ELSE" = 1
  47.         )
  48.     Whitelist[O:steamID(),number] = 1#This sets the owner on the whitelist
  49.     L["Whitelist",table] = Whitelist
  50.     Path = (L["Name",string]:replace("[",""):replace("]",""):replace(" ","_"):replace(".","")+L["Version",number]+".txt")
  51.     runOnChat(1)
  52.     runOnTick(1)
  53.     runOnLast(1)
  54.     runOnFile(1)
  55.    
  56.     setName(L["Name",string]+"\nMode: "+L["Mode",string]+"\nSeat Security Control System\nVersion: "+L["Version",number]+"\n from "+L["Last_Modifyed",string])
  57.    
  58.     function msg(Ary:array){ printColor(L["ChatPrefix",array]:add(Ary)) }
  59.     function msg(Text:string){ msg(array(Text)) }
  60.     function msgError(Ary:array){ msg(Ary:add(array(vec(255,0,0)," [ERROR]"))) }
  61.     function msgError(Text:string){ msgError(array(Text)) }
  62.     function msgErrorNoPod(){ msgError("Please wire the SSCS-E2 to a Pod-Controller!") }
  63.     function msgErrorNoSeat(){ msgError("Please link the pod to a seat!") }
  64.     function nope(Plr:entity){
  65.         msg(array(vec(0,0,255),Plr:name(),vec()+255," tried to enter your Seat! ["+L["Action",string]+"ed]"))
  66.         Plr:printColorDriver(L["ChatPrefix",array]:add(array("NO! Baaaaaad!")))
  67.        
  68.         Pod[L["Action",string],number] = 1
  69.     }
  70.     function nope(Plr:entity,Action:string){
  71.         msg(array(vec(0,0,255),Plr:name(),vec()+255," tried to enter your Seat! ["+Action+"ed]"))
  72.         Plr:printColorDriver(L["ChatPrefix",array]:add(array("NO! Baaaaaad!")))
  73.        
  74.         Pod[Action,number] = 1
  75.     }
  76.     function wrongCommand(){ msgError(array("Wrong command!",vec(255,0,0))) }
  77.     function backup(){ stoptimer("backup"), timer("backup",0) }
  78.     function backup(Num){ stoptimer("backup"), timer("backup",Num) }
  79.     function lock(){ soundStop(1), Pod["Entity",entity]:soundPlay(1,0,"buttons/lever4.wav") }
  80.     function unlock(){ soundStop(1), Pod["Entity",entity]:soundPlay(1,0,"buttons/lever8.wav") }
  81.    
  82.     timer("check for pod",0)
  83.     timer("load",200)
  84. }
  85.  
  86. ##-- Pod and Seat checking --##
  87. if ( !Pod["Entity",entity]:isValid() ){
  88.     if ( !->Pod & clk("check for pod") ){ msgErrorNoPod() }
  89.     if ( ->Pod & clk("check for seat") ){ msgErrorNoSeat() }
  90.     if ( changed(->Pod) & ->Pod ){ timer("check for seat",50) }
  91. }
  92. #-Not working properly lol-#
  93. #[
  94. elseif ( changed(Pod["Entity",entity]:isValid()) & !Pod["Entity",entity]:isValid() ){
  95.     msgErrorNoSeat()
  96. }
  97. if ( changed(->Pod) & !->Pod ){
  98.     msgErrorNoPod()
  99. }]#
  100.  
  101.  
  102. if ( L["loaded",number] & changed(Pod["Entity",entity]) & Pod["Entity",entity] | changed(L["loaded",number]) & L["loaded",number] & Pod["Entity",entity] ){
  103.     printColor(L["ChatPrefix",array]:add(array("Security wired and ready for use! For Example: \".sscs mode owneronly\" look in the E2 on top are all available commands.")))
  104.     if ( L["Locked",number] ){
  105.         lock()
  106.     }else{
  107.         unlock()
  108.     }
  109.     L["loaded",number] = 0
  110. }
  111.  
  112. if ( Pod["Entity",entity] ){
  113.     if ( L["Mode",string] == "Secured" ){
  114.         D = Pod["Entity",entity]:driver()
  115.         if ( D & Whitelist[D:steamID(),number] == 0 ){
  116.             nope(D)
  117.         }
  118.     }elseif ( L["Mode",string] == "OwnerOnly" ){
  119.         D = Pod["Entity",entity]:driver()
  120.         if ( D & D != O ){
  121.             nope(D)
  122.         }
  123.     }
  124.     Pod["Lock",number] = L["Locked",number]
  125. }
  126.  
  127. if ( chatClk(O) & lastSaid():sub(1,5) == ".sscs" ){
  128.     if ( lastSaid():left(6) != ".sscs " ){
  129.         wrongCommand()
  130.     }else{
  131.         LS = lastSaid():sub(7)
  132. #        print("Debug:"+LS)
  133.         hideChat(1)
  134.         LSx = LS:explode(" ")
  135.         if ( LSx[1,string]:lower() == "action" ){
  136.             if ( LSx[2,string]:lower() == "eject" ){
  137.                 if ( L["Action",string] == "Eject" ){
  138.                     msgError(array("Action mode is already set as EJECT"))
  139.                 }else{
  140.                     L["Action",string] = "Eject"
  141.                     msg(array("Action mode changed to: ",vec(0,255,0),"EJECT"))
  142.                     backup(500)
  143.                 }
  144.             }elseif ( LSx[2,string]:lower() == "terminate" | LSx[2,string]:lower() == "kill" ){
  145.                 if ( L["Action",string] == "Terminate" ){
  146.                     msgError(array("Action mode is already set as TERMINATE"))
  147.                 }else{
  148.                     L["Action",string] = "Terminate"
  149.                     msg(array("Action mode changed to: ",vec(0,255,0),"TERMINATE"))
  150.                     backup(500)
  151.                 }
  152.             }else{
  153.                 wrongCommand()
  154.             }
  155.         }elseif ( LSx[1,string]:lower() == "mode" ){
  156.             A1 = array("owneronly","oo","owner","o")
  157.             A2 = array("freeforall","f4a","ffa")
  158.             A3 = array("secured","s","fuck")
  159.             if ( LSx[2,string]:lower() == A1[1,string] | LSx[2,string]:lower() == A1[2,string] | LSx[2,string]:lower() == A1[3,string] | LSx[2,string]:lower() == A1[4,string]){
  160.                 if ( L["Mode",string] == "OwnerOnly" ){
  161.                     msgError(array("Operating mode is already set as OwnerOnly"))
  162.                 }else{
  163.                     L["Mode",string] = "OwnerOnly"
  164.                     msg(array("Operating mode changed to: ",vec(0,255,0),"OWNERONLY"))
  165.                     backup(500)
  166.                 }
  167.             }elseif ( LSx[2,string]:lower() == A2[1,string] | LSx[2,string]:lower() == A2[2,string] | LSx[2,string]:lower() == A2[3,string] ){
  168.                 if ( L["Mode",string] == "FreeForAll" ){
  169.                     msgError(array("Operating mode is already set as FreeForAll"))
  170.                 }else{
  171.                     L["Mode",string] = "FreeForAll"
  172.                     msg(array("Operating mode changed to: ",vec(0,255,0),"FREEFORALL"))
  173.                     backup(500)
  174.                 }
  175.             }elseif ( LSx[2,string]:lower() == A3[1,string] | LSx[2,string]:lower() == A3[2,string] | LSx[2,string]:lower() == A3[3,string] ){
  176.                 if ( L["Mode",string] == "Secured" ){
  177.                     msgError(array("Operating mode is already set as Secured"))
  178.                 }else{
  179.                     L["Mode",string] = "Secured"
  180.                     msg(array("Operating mode changed to: ",vec(0,255,0),"SECURED"))
  181.                     backup(500)
  182.                 }
  183.             }else{
  184.                 wrongCommand()
  185.             }
  186.         }elseif ( LSx[1,string]:lower() == "eject" ){
  187.             D = Pod["Entity",entity]:driver()
  188.             if ( D ){
  189.                 nope(D,"Eject")
  190.             }else{
  191.                 msgError(array("No player inside!"))
  192.             }
  193.         }elseif ( LSx[1,string]:lower() == "kill" | LSx[1,string]:lower() == "terminate" ){
  194.             D = Pod["Entity",entity]:driver()
  195.             if ( D ){
  196.                 nope(D,"Terminate")
  197.             }else{
  198.                 msgError(array("No player inside!"))
  199.             }
  200.         }elseif ( LSx[1,string]:lower() == "lock" ){
  201.             if ( L["Locked",number] ){
  202.                 L["Locked",number] = 0
  203.                 msg(array("Seat ",vec(0,255,0),"UNLOCKED!"))
  204.                 unlock()
  205.                 backup(500)
  206.             }else{
  207.                 L["Locked",number] = 1
  208.                 msg(array("Seat ",vec(0,255,0),"LOCKED!"))
  209.                 lock()
  210.                 backup(500)
  211.             }
  212.         }elseif ( LSx[1,string]:lower() == "unlock" ){
  213.             if (  L["Locked",number] == 0 ){
  214.                 msgError(array("Seat is already unlocked!"))
  215.             }else{
  216.                 L["Locked",number] = 0
  217.                 msg(array("Seat ",vec(0,255,0),"UNLOCKED!"))
  218.                 unlock()
  219.                 backup(500)
  220.             }
  221.         }elseif ( LSx[1,string]:lower() == "whitelist" | LSx[1,string]:lower() == "white" ){
  222.             Ply = findPlayerByName(LSx[3,string]:lower())
  223.             A1 = array("list","showlist","l","players")
  224.             if ( !Ply ){
  225.                 msgError(array("No player found!"))
  226.             }elseif ( LSx[2,string]:lower() == "add" ){
  227.                 if ( Whitelist[Ply:steamID(),number] ){
  228.                     msgError(array(vec(0,255,0),Ply:name(),vec()+255," is already on the list!"))
  229.                 }else{
  230.                     Whitelist[Ply:steamID(),number] = 1
  231.                     msg(array(vec(0,255,0),Ply:name(),vec()+255," was set on the Whitelist!"))
  232.                     backup(500)
  233.                 }
  234.             }elseif ( LSx[2,string]:lower() == "remove" ){
  235.                 if ( Whitelist[Ply:steamID(),number] == 0 ){
  236.                     msgError(array(vec(0,255,0),Ply:name(),vec()+255," is not on the list!"))
  237.                 }else{
  238.                     Whitelist[Ply:steamID(),number] = 0
  239.                     msg(array(vec(0,255,0),Ply:name(),vec()+255," was removed from the Whitelist!"))
  240.                     backup(500)
  241.                 }
  242.             }elseif (LSx[2,string]:lower() == "" | LSx[2,string]:lower() == A1[1,string] | LSx[2,string]:lower() == A1[2,string] | LSx[2,string]:lower() == A1[3,string] | LSx[2,string]:lower() == A1[4,string] ){
  243.                 Plrs = array()
  244.                 foreach(K,Plr:entity = players()){
  245.                     if ( Whitelist[Plr:steamID(),number] ){
  246.                         Plrs:pushString(Plr:name())
  247.                     }
  248.                 }
  249.                 msg(array("Whitelisted: ("+Plrs:count()+"/"+Whitelist:count()+"):\n ",vec(255,0,0),Plrs:concat("\n ")))
  250.             }else{
  251.                 wrongCommand()
  252.             }
  253.         }else{
  254.             wrongCommand()
  255.         }
  256.     }
  257. }
  258.  
  259.  
  260. ##-- Saving and loading --##
  261.  
  262. if ( clk("load") ){
  263.     if ( fileCanLoad() ){fileLoad(Path)
  264.         msg("Loading file :\""+Path+"\"")
  265.     }else{
  266.         msgError("File couldnt be loaded! Retrying...")
  267.         timer("load",500)
  268.     }
  269. }
  270.  
  271. if ( fileClk(Path) ){
  272.     if ( fileLoaded() ){
  273.         Length = vonEncode(L):length()
  274.         Data = fileRead()
  275.         if ( Data:length() >= Length ){
  276.             L = vonDecodeTable(Data)
  277.             Whitelist = L["Whitelist",table]
  278.             msg("Data loaded!")
  279.             L["loaded",number] = 1
  280.         }else{
  281.             msgError("No data loaded!")
  282.             msg("Saving standard settings...")
  283.             backup()
  284.         }
  285.     }else{
  286.         msgError("No data loaded!")
  287.         msg("Saving standard settings!")
  288.         backup()
  289.     }
  290. }
  291.  
  292. if ( clk("backup") ){
  293.     if ( fileCanWrite() ){
  294.         Data = vonEncode(L)
  295.         fileWrite(Path,Data)
  296.        
  297.         msg("Data backupped!")
  298.         setName(L["Name",string]+"\nMode: "+L["Mode",string]+"\nSeat Security Control System\nVersion: "+L["Version",number]+"\n from "+L["Last_Modifyed",string])
  299.     }else{
  300.         msgError("Couldn't write file! Retrying...")
  301.         backup(500)
  302.     }
  303. }elseif( last() ){
  304.     if ( fileCanWrite() ){
  305.         Data = vonEncode(L)
  306.         fileWrite(Path,Data)
  307.        
  308.         msg("Data backupped!")
  309.     }
  310.     msg("Goodbye. :)\n")
  311. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement