• Print

Author Topic: I no understand why this isn't working?  (Read 8976 times)

0 Members and 1 Guest are viewing this topic.

Offline lamb201

  • Newbie
  • *
  • Posts: 15
  • Karma: -1
I no understand why this isn't working?
« on: January 29, 2014, 11:58:12 am »
I don't know why this code isn't working:

Code: Lua
  1. function ulx.warn( calling_ply, target_ply )
  2.  
  3.         target_ply = t
  4.         numberofwarns = t:GetPData("WarnData") or 0
  5.         if numberofwarns == 0 then
  6.                 t:SetPData("WarnData", numberofwarns+1)
  7.         elseif numberofwarns == 1 then
  8.                 t:SetPData("WarnData", numberofwarns+1)
  9.                 time = 60
  10.                 t:Ban(time, "You have been warned two times! Therefor are banned for 60 minutes!")
  11.         elseif numberofwarns == 2 then
  12.                 t:SetPData("WarnData", numberofwarns+1)
  13.                 time = 1440
  14.                 t:Ban(time, "You have been warned three times! Therefor are banned for 1 day!")
  15.         elseif numberofwarns == 3 then
  16.                 t:SetPData("WarnData", numberofwarns+1)
  17.                 time = 10080
  18.                 t:Ban(time, "You have been warned three times! Therefor are banned for 1 week!")
  19.         elseif numberofwarns > 3 then
  20.                 time = 0
  21.                 t:SetPData("WarnData", numberofwarns+1)
  22.                 t:Ban(time, "You have been warned three times! Therefor are banned for 1 week!")
  23.         end
  24.  
  25.         if numberofwarns < 1 then
  26.                 ulx.fancyLogAdmin( calling_ply, "#A has warned #T for the first time! Be careful, #T", target_ply)
  27.         else
  28.  
  29.                 ulx.fancyLogAdmin( calling_ply, "#A has warned #T, and has been banned for #i minutes.", target_ply, tostring(time))
  30.         end
  31.  
  32. end
  33. local warn = ulx.command( CATEGORY_NAME, "ulx warn", ulx.warn, {"!warn", "!w"})
  34. warn:addParam{ type=ULib.cmds.PlayerArg }
  35. warn:defaultAccess( ULib.ACCESS_ADMIN )
  36. warn:help("Adds a warn to the target")
  37.  
  38. function ulx.unwarn( calling_ply, target_ply )
  39.  
  40.         numberofwarns = t:GetPData("WarnData") or 0
  41.  
  42.         if numberofwarns == 0 then
  43.                 calling_ply:PrintMessage( HUD_PRINTTALK, target_ply:Nick().."'s warns are 0, unable to remove a warn!")
  44.         else
  45.                 t:SetPData("WarnData", numberofwarns-1)
  46.                 ulx.fancyLogAdmin( calling_ply, "#A has removed one warn from #T", target_ply)
  47.         end
  48.  
  49. end
  50. local unwarn = ulx.command( CATEGORY_NAME, "ulx unwarn", ulx.unwarn, {"!unwarn", "!uw"})
  51. unwarn:addParam{ type=ULib.cmds.PlayerArg }
  52. unwarn:defaultAccess( ULib.ACCESS_ADMIN )
  53. unwarn:help("Removed a warn to the target")
  54.  
  55. function ulx.viewwarns( calling_ply, target_ply )
  56.         numberofwarns = t:GetPData("WarnData") or "0"
  57.  
  58.         calling_ply:PrintMessage( HUD_PRINTTALK, target_ply:Nick().."has ("..tostring(numberofwarns)..") warn(s)")
  59. end
  60. local vwarn = ulx.command( CATEGORY_NAME, "ulx viewwarns", ulx.viewwarns, {"!viewwarns", "!vw"})
  61. vwarn:addParam{ type=ULib.cmds.PlayerArg }
  62. vwarn:defaultAccess( ULib.ACCESS_ADMIN )
  63. vwarn:help("Views a target's WarnData.")

Any ideas?
« Last Edit: January 29, 2014, 12:24:22 pm by lamb201 »

Offline Eccid

  • Full Member
  • ***
  • Posts: 115
  • Karma: 11
  • Hey, come on... We just met...
    • Terror Abound! Steam Group
Re: I no understand why this isn't working?
« Reply #1 on: January 29, 2014, 09:43:43 pm »
What errors are you getting?

Offline lamb201

  • Newbie
  • *
  • Posts: 15
  • Karma: -1
Re: I no understand why this isn't working?
« Reply #2 on: January 30, 2014, 09:59:38 am »
It's not echoing atall, and not working.

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: I no understand why this isn't working?
« Reply #3 on: January 30, 2014, 10:11:12 am »
No errors at all?
Also, where is "CATEGORY_NAME" specified in your code?
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline lamb201

  • Newbie
  • *
  • Posts: 15
  • Karma: -1
Re: I no understand why this isn't working?
« Reply #4 on: January 30, 2014, 10:30:16 am »
It's in util.lua in moduals/sh,
It's defined at the top of the file.
Code: Lua
  1. CATEGORY_NAME = "Utility"
« Last Edit: January 30, 2014, 10:31:51 am by lamb201 »

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: I no understand why this isn't working?
« Reply #5 on: January 30, 2014, 11:10:17 am »
It's in util.lua in moduals/sh,
It's defined at the top of the file.
Code: Lua
  1. CATEGORY_NAME = "Utility"
I was just making sure.
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline Eccid

  • Full Member
  • ***
  • Posts: 115
  • Karma: 11
  • Hey, come on... We just met...
    • Terror Abound! Steam Group
Re: I no understand why this isn't working?
« Reply #6 on: January 30, 2014, 12:45:04 pm »
Well, you're setting the variable "t" backwards, so that target_ply = t. Switch it around and make it local in each function, so at the beginning of all three functions put
Code: Lua
  1. local t = target_ply

Give me a bit to look at it in gmod and I'll see if I notice anything else.

Offline lamb201

  • Newbie
  • *
  • Posts: 15
  • Karma: -1
Re: I no understand why this isn't working?
« Reply #7 on: January 30, 2014, 12:50:55 pm »
I just noticed that, I changed it on all of them but I still don't get it working for !warn.

Offline lamb201

  • Newbie
  • *
  • Posts: 15
  • Karma: -1
Re: I no understand why this isn't working?
« Reply #8 on: January 30, 2014, 12:55:49 pm »
Also if numberofwarns == 0 then does't seem to be working, I can unwarn someone with 0 warns.

Offline Cobalt

  • Full Member
  • ***
  • Posts: 216
  • Karma: 44
  • http://steamcommunity.com/id/__yvl/
Re: I no understand why this isn't working?
« Reply #9 on: January 30, 2014, 01:53:59 pm »
ulx.fancyLogAdmin( calling_ply, "#A has warned #T, and has been banned for #i minutes.", target_ply, tostring(time))

Change #i to #s

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Re: I no understand why this isn't working?
« Reply #10 on: January 30, 2014, 02:56:42 pm »
Are you sure PData is returning a number and not a string?
Not really sure how it works, otherwise I would know... :p

EDIT: This marks my 100th post and my Full member promotion! :D
bw81@ulysses-forums ~ % whoami
Homepage

Offline lamb201

  • Newbie
  • *
  • Posts: 15
  • Karma: -1
Re: I no understand why this isn't working?
« Reply #11 on: January 30, 2014, 03:30:14 pm »
PData returns as it was set, which is a value.

Offline Cobalt

  • Full Member
  • ***
  • Posts: 216
  • Karma: 44
  • http://steamcommunity.com/id/__yvl/
Re: I no understand why this isn't working?
« Reply #12 on: January 30, 2014, 04:58:31 pm »
Pretty sure pdata always returns a string.

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Re: I no understand why this isn't working?
« Reply #13 on: January 30, 2014, 05:23:21 pm »
Pretty sure pdata always returns a string.
if it does, he'd have to run tonumber()...
I'd try that if i were you, lamb.
bw81@ulysses-forums ~ % whoami
Homepage

Offline Eccid

  • Full Member
  • ***
  • Posts: 115
  • Karma: 11
  • Hey, come on... We just met...
    • Terror Abound! Steam Group
Re: I no understand why this isn't working?
« Reply #14 on: January 30, 2014, 05:26:36 pm »
Pretty sure pdata always returns a string.

This is true, you need to convert it from a number, which is why it was failing to do most things. What you posted worked, it just needed to be tweaked a bit. Check out what I have and you can see what was missing.

Code: [Select]
CATEGORY_NAME = "test"

function ulx.warn( calling_ply, target_ply )
local t = target_ply

numberofwarns = tonumber(t:GetPData("WarnData")) or 0
print(numberofwarns)
if numberofwarns == 0 then
t:SetPData("WarnData", numberofwarns+1)
t:PrintMessage( HUD_PRINTTALK, "You have been warned fro the first time, becareful "..t:Nick())
elseif numberofwarns == 1 then
t:SetPData("WarnData", numberofwarns+1)
time = 60
t:Ban(time, "You have been warned two times! Therefor are banned for 60 minutes!")
elseif numberofwarns == 2 then
t:SetPData("WarnData", numberofwarns+1)
time = 1440
t:Ban(time, "You have been warned three times! Therefor are banned for 1 day!")
elseif numberofwarns == 3 then
t:SetPData("WarnData", numberofwarns+1)
time = 10080
t:Ban(time, "You have been warned three times! Therefor are banned for 1 week!")
elseif numberofwarns > 3 then
time = 0
t:SetPData("WarnData", numberofwarns+1)
t:Ban(time, "You have been warned five times! Therefor are banned permanently!")
end

if numberofwarns > 1 then
ulx.fancyLogAdmin( calling_ply, "#A has warned #T, and has been banned for #s minutes.", target_ply, tostring(time))
end

end
local warn = ulx.command( CATEGORY_NAME, "ulx warn", ulx.warn, {"!warn", "!w"})
warn:addParam{ type=ULib.cmds.PlayerArg }
warn:defaultAccess( ULib.ACCESS_ADMIN )
warn:help("Adds a warn to the target")

function ulx.unwarn( calling_ply, target_ply )
local t = target_ply
numberofwarns = tonumber(t:GetPData("WarnData")) or 0

if numberofwarns == 0 then
calling_ply:PrintMessage( HUD_PRINTTALK, target_ply:Nick().."'s warns are 0, unable to remove a warn!")
return
else
t:SetPData("WarnData", numberofwarns-1)
ulx.fancyLogAdmin( calling_ply, "#A has removed one warn from #T", target_ply)
end

end
local unwarn = ulx.command( CATEGORY_NAME, "ulx unwarn", ulx.unwarn, {"!unwarn", "!uw"})
unwarn:addParam{ type=ULib.cmds.PlayerArg }
unwarn:defaultAccess( ULib.ACCESS_ADMIN )
unwarn:help("Removed a warn to the target")

function ulx.viewwarns( calling_ply, target_ply )
local t = target_ply
numberofwarns = tonumber(t:GetPData("WarnData")) or "0"

calling_ply:PrintMessage( HUD_PRINTTALK, target_ply:Nick().."has ("..tostring(numberofwarns)..") warn(s)")
end
local vwarn = ulx.command( CATEGORY_NAME, "ulx viewwarns", ulx.viewwarns, {"!viewwarns", "!vw"})
vwarn:addParam{ type=ULib.cmds.PlayerArg }
vwarn:defaultAccess( ULib.ACCESS_ADMIN )
vwarn:help("Views a target's WarnData.")

  • Print