• Print

Author Topic: How to add weapons or more hp to a Rank User ?  (Read 10329 times)

0 Members and 1 Guest are viewing this topic.

Offline Schiaffino

  • Jr. Member
  • **
  • Posts: 88
  • Karma: 1
How to add weapons or more hp to a Rank User ?
« on: May 29, 2012, 07:07:36 pm »
hi , well i work with a rank system that i fix and change some things but i want to know how can i add items in a rank or how i can insert more hp on a rank

Rank Level 1: 100 HP
Rank Level 2: 110 HP
Rank Level 3: 140 HP
Rank Level 4: 170 HP
Rank Level 5: 200 HP
Rank Level 6: 210 HP
Rank Level 7: 220 HP
Rank Level 8: 240 HP
Rank Level 9 ..... ETC...

Code: Lua
  1.   RANK EXAMPLE
  2.  
  3.                 PlayerRanks[3] = {}
  4.                 PlayerRanks[3].Name = "Member Lv 2 CGamers"
  5.                 PlayerRanks[3].Time = 2400
  6.  
  7.  

And if i want when the player join to add an item on this rank i supose that is this:

Code: Lua
  1.  RANK ADD ITEM ON sv_gamemode_functions.lua area: function GM:PlayerSpawn(ply)
  2.  
  3.         if ply:PlayerRanks[17]
  4.         then ply:Give ("weapon_crowbar")
  5.         end
  6.  
  7.  

Im right or this is not the way to add items by the rank of the user ?

THanks for the support :)

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: How to add weapons or more hp to a Rank User ?
« Reply #1 on: May 29, 2012, 07:14:38 pm »
does the rank addon you use include the ply:PlayerRanks meta function? This is not something that is built in by default and it is not a part of ULib.


If that function actually does exist, then yes, that is how you would do it.

Code: [Select]
if ply:PlayerRanks[17] then
ply:Give("weapon_crowbar")
ply:SetMaxHealth(150)
end

the 150 being whatever you want the health to be.

that code would go in the PlayerSpawn hook of the gamemode or you could hook it separately to avoid breaking anything.
« Last Edit: May 29, 2012, 07:18:26 pm by MrPresident »

Offline Schiaffino

  • Jr. Member
  • **
  • Posts: 88
  • Karma: 1
Re: How to add weapons or more hp to a Rank User ?
« Reply #2 on: May 29, 2012, 07:23:16 pm »
All Functions that the system use.

Code: Lua
  1.  
  2. function ToHoursMinutesSeconds(curtime)
  3.         function DrawIDTime()
  4.         function DrawIcons()
  5.         function UpdateTimeHUD()
  6.         function TimeUpdate()
  7.         function TimeSyncHook(um)
  8.         function meta:GetTimeSpent()
  9.         function meta:SetTimeSpent(newtime)
  10.         function meta:GetRank()
  11.         function UpdateTime()
  12.         function TimeSyncHook()
  13.         function InitialSpawnSync(pl)
  14.  
  15.  

Wich of one i can use to make a system to give health and guns ?
( i think one of those that use time so i can give guns by the time )

:P

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: How to add weapons or more hp to a Rank User ?
« Reply #3 on: May 29, 2012, 07:31:13 pm »
You would want to use the GetRank() meta. I don't know how it returns so you might want to figure that out first.. but here is some code that would work for you.



Code: [Select]
function CustomSpawn(ply)
     if ply:GetRank() == 1 then
          ply:Give("whatever weapon")
          ply:SetMaxHealth(some number here)
     end
end
hook.Add( "PlayerSpawn", "CustomSpawn", CustomSpawn )

Offline Schiaffino

  • Jr. Member
  • **
  • Posts: 88
  • Karma: 1
Re: How to add weapons or more hp to a Rank User ?
« Reply #4 on: May 29, 2012, 07:39:32 pm »
look this is the

Code: Lua
  1.  Lua CODE
  2.  
  3.         function meta:GetRank()
  4.                 if not PlayersTime[self:SteamID()] then PlayersTime[self:SteamID()] = self:GetTimeSpent() end
  5.                 local curtime = PlayersTime[self:SteamID()]
  6.                 local final = 1
  7.                 for i = 1, table.getn(PlayerRanks) do
  8.                         if curtime >= PlayerRanks[i].Time then final = i end
  9.                 end
  10.                 return final;
  11.         end
  12.  
  13.  


Offline Schiaffino

  • Jr. Member
  • **
  • Posts: 88
  • Karma: 1
Re: How to add weapons or more hp to a Rank User ?
« Reply #5 on: May 29, 2012, 07:53:41 pm »
Sorry for doble post , but other way is that when the user get Rank Example: 5 change his group to Regular User like the APromote.

and then i just edit the    if ply:IsUserGroup("regular")  with this...

There is a posibility ? if you need the code i can give it to you in PM.

:) please =)

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: How to add weapons or more hp to a Rank User ?
« Reply #6 on: May 29, 2012, 07:55:22 pm »
okay then the code I posted is the right format. Just have something like this...

Code: [Select]
function CustomSpawn(ply)
     if ply:GetRank() == 1 then
          ply:Give("whatever weapon")
          ply:SetMaxHealth(some number here)
     elseif ply:GetRank() == 2 then
          ply:Give("whatever weapon")
          ply:SetMaxHealth(some number here)
     elseif ply:GetRank() == 3 then
          ply:Give("whatever weapon")
          ply:SetMaxHealth(some number here)
     elseif ply:GetRank() == 4 then
          ply:Give("whatever weapon")
          ply:SetMaxHealth(some number here)
     elseif ply:GetRank() == 5 then
          ply:Give("whatever weapon")
          ply:SetMaxHealth(some number here)
     end
end
hook.Add( "PlayerSpawn", "CustomSpawn", CustomSpawn )

and so on... remember to set the weapon and health to what you want.

Offline Schiaffino

  • Jr. Member
  • **
  • Posts: 88
  • Karma: 1
Re: How to add weapons or more hp to a Rank User ?
« Reply #7 on: May 29, 2012, 07:58:37 pm »
Mr sorry for this stupid question but i add your code to the sv_gamemode_functions.lua or in the same Timer system ?

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: How to add weapons or more hp to a Rank User ?
« Reply #8 on: May 29, 2012, 08:23:54 pm »
create a new file called (whatever).lua and put the code in that. Place that file in your garrysmod/lua/autorun/server folder.

Offline Schiaffino

  • Jr. Member
  • **
  • Posts: 88
  • Karma: 1
Re: How to add weapons or more hp to a Rank User ?
« Reply #9 on: May 29, 2012, 08:49:20 pm »
no problem if i put this

Code: Lua
  1.  
  2. function CustomSpawn(ply)
  3.      if ply:GetRank() == 1 then
  4.           ply:Give("whatever weapon")
  5.           ply:SetMaxHealth(some number here)
  6.      elseif ply:GetRank() == 2 then
  7.           ply:Give("whatever weapon")
  8.           ply:SetMaxHealth(some number here)
  9.      elseif ply:GetRank() == 3 then
  10.           ply:Give("whatever weapon")
  11.           ply:SetMaxHealth(some number here)
  12.      elseif ply:GetRank() == 4 then
  13.           ply:Give("whatever weapon")
  14.           ply:SetMaxHealth(some number here)
  15.      elseif ply:GetRank() == 5 then
  16.           ply:Give("whatever weapon")
  17.           ply:SetMaxHealth(some number here)
  18.      end
  19. end
  20. hook.Add( "PlayerSpawn", "CustomSpawn", CustomSpawn )
  21.  
  22.  

like this

Code: Lua
  1.  
  2. function CustomSpawn(ply)
  3.      if ply:GetRank() == 1 then
  4.           ply:Give("whatever weapon")
  5.           ply:SetMaxHealth(some number here)
  6.      else
  7. if ply:GetRank() == 2 then
  8.           ply:Give("whatever weapon")
  9.           ply:SetMaxHealth(some number here)
  10.      else
  11. if ply:GetRank() == 3 then
  12.           ply:Give("whatever weapon")
  13.           ply:SetMaxHealth(some number here)
  14.      else
  15. if ply:GetRank() == 4 then
  16.           ply:Give("whatever weapon")
  17.           ply:SetMaxHealth(some number here)
  18.      else
  19. if ply:GetRank() == 5 then
  20.           ply:Give("whatever weapon")
  21.           ply:SetMaxHealth(some number here)
  22.      end
  23. end
  24. hook.Add( "PlayerSpawn", "CustomSpawn", CustomSpawn )
  25.  
  26.  

thanks.
« Last Edit: May 29, 2012, 08:57:40 pm by Schiaffino »

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: How to add weapons or more hp to a Rank User ?
« Reply #10 on: May 29, 2012, 08:59:58 pm »
you would need to use end.. not else if you want to do it that way.. but that works too.

Offline Schiaffino

  • Jr. Member
  • **
  • Posts: 88
  • Karma: 1
Re: How to add weapons or more hp to a Rank User ?
« Reply #11 on: May 29, 2012, 09:13:30 pm »
i test this code

Code: Lua
  1.  
  2. function CustomSpawn(ply)
  3.  
  4.      if ply:GetRank() == 1 then
  5.           ply:SetMaxHealth(100)
  6.                   end  
  7.          if ply:GetRank() == 2 then
  8.           ply:SetMaxHealth(120)
  9.                   end    
  10.          if ply:GetRank() == 3 then
  11.           ply:SetMaxHealth(140)
  12.                   end    
  13.          if ply:GetRank() == 4 then
  14.           ply:SetMaxHealth(160)
  15.                   end      
  16.          if ply:GetRank() == 5 then
  17.           ply:SetMaxHealth(180)
  18.                   end      
  19.           if ply:GetRank() == 6 then
  20.           ply:SetMaxHealth(200)
  21.                   end              
  22.          if ply:GetRank() == 7 then
  23.           ply:SetMaxHealth(210)
  24.                   end              
  25.          if ply:GetRank() == 8 then
  26.              ply:SetMaxHealth(215)
  27.                  end               
  28.          if ply:GetRank() == 9 then
  29.           ply:SetMaxHealth(230)
  30.                                   end              
  31.          if ply:GetRank() == 10 then
  32.           ply:SetMaxHealth(240)
  33.                                   end              
  34.          if ply:GetRank() == 11 then
  35.           ply:SetMaxHealth(250)
  36.                                   end              
  37.          if ply:GetRank() == 12 then
  38.           ply:SetMaxHealth(260)
  39.                                   end              
  40.          if ply:GetRank() == 13 then
  41.           ply:SetMaxHealth(270)
  42.                   ply:Give("weapon_crowbar")
  43.                                   end              
  44.          if ply:GetRank() == 14 then
  45.           ply:SetMaxHealth(280)
  46.                                   end              
  47.          if ply:GetRank() == 15 then
  48.           ply:SetMaxHealth(290)
  49.                                   end
  50.          if ply:GetRank() == 16 then
  51.           ply:SetMaxHealth(300)
  52.                                   end
  53.          if ply:GetRank() == 17 then
  54.           ply:SetMaxHealth(310)
  55.                                   end              
  56.          if ply:GetRank() == 18 then
  57.           ply:SetMaxHealth(320)
  58.                                   end              
  59.          if ply:GetRank() == 19 then
  60.           ply:SetMaxHealth(340)
  61.                                   end              
  62.          if ply:GetRank() == 20 then
  63.           ply:SetMaxHealth(360)
  64.                                   end              
  65.          if ply:GetRank() == 21 then
  66.           ply:SetMaxHealth(400)
  67.           ply:Give("weapon_smg1")
  68. end
  69. end
  70.  
  71. hook.Add( "PlayerSpawn", "CustomSpawn", CustomSpawn )
  72.  
  73.  

But do not give the health when im on a X.Rank... :S
its like this file is not loading

Offline Schiaffino

  • Jr. Member
  • **
  • Posts: 88
  • Karma: 1
Re: How to add weapons or more hp to a Rank User ?
« Reply #12 on: May 29, 2012, 09:18:23 pm »
( I TEST THE GUNS ON THE RANKS AND WORK )

ITS JUST THE HP THAT'S NOT WORK i also search on

Sv_gamemode_functions and the function of hp have this:

        then ply:SetHealth(100)
    else
        ply:SetHealth(tonumber(GetConVarNumber("startinghealth")) or 100)

so im going to test and i told you ! =)

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: How to add weapons or more hp to a Rank User ?
« Reply #13 on: May 29, 2012, 09:20:19 pm »
yeah.. do ply:SetHealth(same as maxhealth) as well..

it is setting their max health but not setting their total.

Offline Schiaffino

  • Jr. Member
  • **
  • Posts: 88
  • Karma: 1
Re: How to add weapons or more hp to a Rank User ?
« Reply #14 on: May 29, 2012, 09:26:04 pm »
mm something is happening with the command of HP cause is not setting the max hp or the ( hp on the start )
mmm

  • Print