• Print

Author Topic: PVP command / lua help  (Read 8025 times)

0 Members and 1 Guest are viewing this topic.

Offline Vaporouscreeper

  • Newbie
  • *
  • Posts: 22
  • Karma: 0
    • TheBox steam group
PVP command / lua help
« on: March 24, 2018, 07:28:16 am »
I'm making a pvp and build code and when i testing it, it's say that requires a target but the code is to target the person calling the command
Code: Lua
  1.  
  2. local CATEGORY_NAME = "Testing"
  3.  
  4. local inPvP = list.Set("InPVP","pvping",{})
  5. local players = player.GetAll()
  6.  
  7. function ulx.enablePvP(calling_ply)
  8.         if not list.Contains("InPvP",calling_ply) then
  9.                 list.Add("InPvP",calling_ply)
  10.                 ulx.fancyLogAdmin(calling_ply,false,"#A has entered PvP")
  11.                 print(inPvP)
  12.         else
  13.                 ULib.tsayError(calling_ply,"You're already in PvP")
  14.                 print(inPvP)
  15.         end
  16. end
  17. local enablePvP = ulx.command(CATEGORY_NAME, "ulx enpvp", ulx.enablePvP, "!enpvp", false)
  18. enablePvP:addParam{type=ULib.cmds.PlayerArg}
  19. enablePvP:defaultAccess(ULib.ACCESS_ADMIN)
  20. enablePvP:help("Enters in PvP")
  21.  
I'm a Moderator on a server called TheBox. and i'm mostly active on it

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: PVP command / lua help
« Reply #1 on: March 24, 2018, 07:29:06 am »
I'm making a pvp and build code and when i testing it, it's say that requires a target but the code is to target the person calling the command
Code: Lua
  1.  
  2. local CATEGORY_NAME = "Testing"
  3.  
  4. local inPvP = list.Set("InPVP","pvping",{})
  5. local players = player.GetAll()
  6.  
  7. function ulx.enablePvP(calling_ply)
  8.         if not list.Contains("InPvP",calling_ply) then
  9.                 list.Add("InPvP",calling_ply)
  10.                 ulx.fancyLogAdmin(calling_ply,false,"#A has entered PvP")
  11.                 print(inPvP)
  12.         else
  13.                 ULib.tsayError(calling_ply,"You're already in PvP")
  14.                 print(inPvP)
  15.         end
  16. end
  17. local enablePvP = ulx.command(CATEGORY_NAME, "ulx enpvp", ulx.enablePvP, "!enpvp", false)
  18. enablePvP:addParam{type=ULib.cmds.PlayerArg}
  19. enablePvP:defaultAccess(ULib.ACCESS_ADMIN)
  20. enablePvP:help("Enters in PvP")
  21.  
Because you have a PlayerArg param.

Sent using Tapatalk. Owner of iViscosity Gaming.

I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline Vaporouscreeper

  • Newbie
  • *
  • Posts: 22
  • Karma: 0
    • TheBox steam group
Re: PVP command / lua help
« Reply #2 on: March 24, 2018, 07:33:45 am »
Thanks ;D
I'm a Moderator on a server called TheBox. and i'm mostly active on it

Offline Vaporouscreeper

  • Newbie
  • *
  • Posts: 22
  • Karma: 0
    • TheBox steam group
Re: PVP command / lua help
« Reply #3 on: March 24, 2018, 09:15:58 pm »
im getting a lua error when i try to use this command
Code: Lua
  1. function ulx.inpvp(calling_ply)
  2.         if not timer.Exists(calling_ply:Nick()) then
  3.                 if inPvP.Count() != 0 then
  4.                         calling_ply:ChatPrint(table.concat(inPvP,", ").." is in PvP")
  5.                 else
  6.                         calling_ply:ChatPrint("No one is in PvP")
  7.                 end
  8.                 timer.Create("check",60,1,function()
  9.                         timer.Remove(calling_ply:Nick())
  10.                 end)
  11.         else
  12.                 ULib.tsayError(calling_ply,"I told you who is in pvp")
  13.         end
  14. end
  15. local inpvp = ulx.command(CATEGORY_NAME, "ulx pvp", ulx.inpvp, "!pvp", false)
  16. fenablePvP:defaultAccess(ULib.ACCESS_ADMIN)
  17. fenablePvP:help("Checks who is in PvP")
  18.  
lua error
Code: [Select]
addons/ulx/lua/ulx/modules/sh/pvp.lua:3: attempt to call field 'Count' (a nil value)
I'm a Moderator on a server called TheBox. and i'm mostly active on it

Offline Vaporouscreeper

  • Newbie
  • *
  • Posts: 22
  • Karma: 0
    • TheBox steam group
Re: PVP command / lua help
« Reply #4 on: March 24, 2018, 09:21:26 pm »
never mind, fixed it my self i had inPvP.Count() it should been table.Count(inPvP)
I'm a Moderator on a server called TheBox. and i'm mostly active on it

Offline Vaporouscreeper

  • Newbie
  • *
  • Posts: 22
  • Karma: 0
    • TheBox steam group
Re: PVP command / lua help
« Reply #5 on: March 25, 2018, 01:52:48 am »
I have a command to target yourself when called but it adds everyone in the server
Code: Lua
  1. function ulx.enablePvP(calling_ply)
  2.         if table.KeyFromValue(inPvP,calling_ply)!=calling_ply:EntIndex() then
  3.                 table.insert(inPvP,calling_ply:EntIndex(),calling_ply)
  4.                 PrintTable(inPvP)
  5.                 ulx.fancyLogAdmin(calling_ply,false,"#A has entered into PvP mode")
  6.                 calling_ply:SetMoveType(MOVETYPE_WALK)
  7.                 calling_ply:DisallowNoclip( true )
  8.                 calling_ply:DisallowSpawning( true )
  9.                 calling_ply:GodDisable()
  10.                 if calling_ply:InVehicle() then
  11.                         calling_ply:ExitVehicle()
  12.                         calling_ply:DisallowVehicles( true )
  13.                 else
  14.                         calling_ply:DisallowVehicles( true )
  15.                 end
  16.         else
  17.                 ULib.tsayError(calling_ply,"You're already in PvP mode")
  18.                 print(table.KeyFromValue(inPvP,calling_ply))
  19.         end
  20. end
  21.  
I'm a Moderator on a server called TheBox. and i'm mostly active on it

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: PVP command / lua help
« Reply #6 on: March 25, 2018, 01:47:17 pm »
What happens if you place the PrintTable before the first if statement? Does it show everyone there too?
I'm guessing you have other code that's inserted all your players into inPvP, or would be erroring different (see below).

Also
Code: [Select]
table.KeyFromValue(inPvP,calling_ply)!=calling_ply:EntIndex(I'm pretty sure that's not going to evaluate the way you expect, and think it could very well be true most of the time.
Due to
Code: [Select]
table.insert(inPvP,calling_ply:EntIndex(),calling_ply)line, that simply inserts into the spot in the array, it doesn't necessarily make that new insertion entindex the key.
And, if it's out of bounds, will likely give you an error.
Say you have one player in inPVP, if you try to insert in position 4 because the calling_player's EntIndex is four, Lua doesn't like that.
Here's rough example lua code from Tutorial's point -  http://tpcg.io/TgtzuV (when loaded, click "execute" and watch output error "out of bounds")
(I don't have account there, so not sure how long that link exists)
It fails. table.insert tries to insert at position 4 and fails for my table with only 2 in it, so I think your table is already large enough not to error.
Something else is likely adding everyone, not this code.



« Last Edit: March 25, 2018, 01:52:19 pm by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: PVP command / lua help
« Reply #7 on: March 27, 2018, 03:52:29 pm »
<Merged all lua related questions / unlocked topic>
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Vaporouscreeper

  • Newbie
  • *
  • Posts: 22
  • Karma: 0
    • TheBox steam group
Re: PVP command / lua help
« Reply #8 on: March 27, 2018, 04:47:29 pm »
just found out that it's not adding the person into the table but my code acting like there is.
btw I'm using inPvP[ent:EntIndex()] = ent
I'm a Moderator on a server called TheBox. and i'm mostly active on it

Offline Vaporouscreeper

  • Newbie
  • *
  • Posts: 22
  • Karma: 0
    • TheBox steam group
Re: PVP command / lua help
« Reply #9 on: March 27, 2018, 05:06:20 pm »
Now im getting a problem with damage
- = problem

when the atk and vic is not in pvp the atk will freeze
when the atk in not in pvp and vic is the atk will atk will freeze
- when the atk is in pvp and vic is not the atk does not freeze
- when the atk and vic is in pvp atk the atk freeze

Code: Lua
  1. hook.Add("EntityTakeDamage","workings",function(atk,dmg)
  2.         atk = dmg:GetAttacker()
  3.         vic = dmg:GetInflictor()
  4.         if not atk:IsWorld() then      
  5.                 print(table.FindNext(inPvP,vic))
  6.                 --print(table.KeyFromValue(inPvP,atk))
  7.                 --print(table.KeyFromValue(inPvP,vic))
  8.                 PrintTable(inPvP)
  9.                 if table.FindNext(inPvP,atk)!=atk then
  10.                         if atk:InVehicle() then
  11.                                 atk:ExitVehicle()
  12.                         else
  13.                                 atk:Lock()
  14.                                 timer.Create(atk:Nick(),2,1,function()
  15.                                         atk:UnLock()
  16.                                 end)
  17.                         end
  18.                 elseif table.FindNext(inPvP,vic)!=vic then
  19.                         if atk:InVehicle() then
  20.                                 atk:ExitVehicle()
  21.                         else
  22.                                 atk:Lock()
  23.                                 timer.Create(atk:Nick(),2,1,function()
  24.                                         atk:UnLock()
  25.                                 end)
  26.                         end
  27.                 end
  28.         end
  29. end)
  30.  
prints for debuging
Player [1][VaporousCreeper]
1   =   Player [1][VaporousCreeper]

Edit: the vic var is acting as atk var

« Last Edit: March 29, 2018, 07:22:32 am by Vaporouscreeper »
I'm a Moderator on a server called TheBox. and i'm mostly active on it

Offline Vaporouscreeper

  • Newbie
  • *
  • Posts: 22
  • Karma: 0
    • TheBox steam group
Re: PVP command / lua help
« Reply #10 on: March 29, 2018, 09:01:43 am »
Everything is done on this project
Thanks to everyone that helped me out ;D
I'm a Moderator on a server called TheBox. and i'm mostly active on it

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: PVP command / lua help
« Reply #11 on: March 29, 2018, 04:29:26 pm »
Welcome. Thanks for keeping iViscosity and I sharp.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Vaporouscreeper

  • Newbie
  • *
  • Posts: 22
  • Karma: 0
    • TheBox steam group
Re: PVP command / lua help
« Reply #12 on: March 29, 2018, 04:55:11 pm »
No worrys
I'm a Moderator on a server called TheBox. and i'm mostly active on it

  • Print