thomasfn

Untitled

Aug 20th, 2011
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.95 KB | None | 0 0
  1. function PLUGIN:Init()
  2.    
  3.     svr.AddFlag( "money" )
  4.    
  5.     self:Command( "money", self.Money, { FLAG_MONEY } )
  6.    
  7.     self:Hook( "player.connect", self.PlayerConnect )
  8.  
  9. end
  10.  
  11. function PLUGIN:Money( ply, args )
  12.     if not args[1] then
  13.         ply:Print("2^-------ZConomy-------")
  14.         ply:Print("10^Your Balance: " .. self:GetMoney( ply ) .. " " .. svr.Config:GetString( "ZConomyCurrency" ))
  15.     elseif args[1] then
  16.         if args[1] == "pay" then
  17.             if args[2] then
  18.                 if args[3] then
  19.                     local Amount = tonumber( args[3] )
  20.                     if Server.GetPlayer( args[2] ) then
  21.                         local ply2 = Server.GetPlayer( args[2] )
  22.                         local PlayerMoney = self:GetMoney( ply )
  23.                         local Player2Money = self:GetMoney( ply2 )
  24.                    
  25.                         if ply.Username == ply2.Username then
  26.                             ply:Print("4^You can't pay yourself.") 
  27.                         else
  28.                             local NewPlayerMoney = PlayerMoney - Amount
  29.                             local NewPlayer2Money = Player2Money + Amount
  30.                    
  31.                    
  32.                                 if PlayerMoney >= Amount then
  33.                                     self:SetMoney( ply, NewPlayerMoney )
  34.                                     self:SetMoney( ply2, NewPlayer2Money )
  35.                                     ply:Print("2^-------ZConomy-------")
  36.                                     ply:Print("10^You payed " .. Amount .. " " .. svr.Config:GetString( "ZConomyCurrency" ) .. " to " .. args[2])
  37.                                     ply2:Print("2^-------ZConomy-------")
  38.                                     ply2:Print("10^You got " .. Amount .. " " .. svr.Config:GetString( "ZConomyCurrency" ) .. " from " .. ply.Username)
  39.                                    
  40.                                
  41.                                
  42.                                 else
  43.                                     ply:Print("4^You don't have that money!")
  44.                                 end
  45.                         end
  46.                     else
  47.                         ply:Print("4^That Player doesnt exist or is offline.")
  48.                     end
  49.            
  50.                 else
  51.                     ply:Print("4^Syntax: -/money pay <name> <amount> - Gives <amount> money to <name>.")
  52.                 end
  53.             else
  54.                 ply:Print("4^Syntax: -/money pay <name> <amount> - Gives <amount> money to <name>.")
  55.             end
  56.         else
  57.             ply:Print("4^Syntax: -/money - Shows your balance.")
  58.             ply:Print("4^Syntax: -/money pay <name> <amount> - Gives <amount> money to <name>.")
  59.         end
  60.     else
  61.         ply:Print("4^Syntax: -/money - Shows your balance.")
  62.         ply:Print("4^Syntax: -/money pay <name> <amount> - Gives <amount> money to <name>.")
  63.     end    
  64. end
  65.  
  66. function PLUGIN:SetMoney( ply, val )
  67.     local data = svr.PlayerData( ply )
  68.     data.Money = val
  69.     svr.SetPlayerPData( ply, val )
  70. end
  71.  
  72. function PLUGIN:GetMoney( ply )
  73.     local data = svr.PlayerData( ply )
  74.     return data.Money
  75. end
  76.  
  77.  
  78. function PLUGIN:PlayerConnect( ply )
  79.     if (svr.Config:GetNumber( "ZConomyInstalled" ) ~= 1) then
  80.         svr.Config:SetNumber( "ZConomyStartMoney", 500 )
  81.         svr.Config:SetString( "ZConomyCurrency", "Dollars" )
  82.         svr.Config:SetNumber( "ZConomyInstalled", 1 )
  83.         return
  84.     end
  85.    
  86.     if (svr.GetPlayerPDataN( ply, "ZConomyNoStartMoney" ) ~= 1) then
  87.  
  88.         svr.SetPlayerPData( ply, "ZConomyMoney", svr.Config:GetNumber( "ZConomyStartMoney" ) )
  89.         svr.SetPlayerPData( ply, "ZConomyNoStartMoney", 1 )
  90.     end
  91.    
  92.     local data = svr.PlayerData( ply )
  93.     data.Money = svr.GetPlayerPDataN( ply, "ZConomyMoney" )
  94. end
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101. PLUGIN:FinishLoad()
Advertisement
Add Comment
Please, Sign In to add comment