Author Topic: GetPData Error?  (Read 2475 times)

0 Members and 1 Guest are viewing this topic.

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
GetPData Error?
« on: October 13, 2013, 12:05:54 PM »
Being the terrible coder I am, I attempted to make a "ulx slapnr" command. It's not working, I'm using PData to store the the amount of damage to be slapped next round (bender180 helped me with that). This is also my first time trying to code a ULX command, so bear with me for any mistakes I do/have done.
I'm receiving this error every time I'm trying to use the command.
Code: [Select]
L 10/13/2013 - 12:01:56: Lua Error:
[ERROR] addons/decicus_ttt/lua/ulx/modules/sh/decicus_ttt_main.lua:9: attempt to call method 'GetPData' (a nil value)
  1. call - addons/decicus_ttt/lua/ulx/modules/sh/decicus_ttt_main.lua:9
   2. __fn - addons/ulib/lua/ulib/shared/commands.lua:943
    3. unknown - addons/ulib/lua/ulib/shared/commands.lua:1296
     4. Run - lua/includes/modules/concommand.lua:69
      5. unknown - addons/ulib/lua/ulib/shared/commands.lua:1310
       6. unknown - lua/includes/modules/concommand.lua:69
This is my code (oh lord please don't yell at me for doing mistakes). Line 1 in this code table is actually line 6. So line 9, would be line 4:
Code: [Select]
function ulx.slapnr ( calling_ply, target_ply, dmg_num )
if not GetConVarString("gamemode") == "terrortown" then ULib.tsayError( calling_ply, gamemode_error, true ) --Taken from Bender and Skillz' TTT module. Checks if the gamemode is actually TTT.
else
local slap_dmg = tonumber(target_ply:GetPData("slapnr_dmg")) or 0 --Shortcut to the PData. PData stores the damage needed to be done next round. WHY ISNT THIS WORKING :(
if dmg_num < 0 then
ULib.tsayError(calling_ply, "Damage can't be negative.", true) --Damage can't be less than 0.
elseif dmg_num > 99 then
ULib.tsayError(calling_ply, "You can't slap with more than 99!", true) --Damage can't be more than 99, as that will kill the person. This isn't a "slay next round".
elseif dmg_num == 0 then
target_ply:RemovePData("slapnr_dmg") --If the damage is 0, it will remove the PData. 0 = No slap.
else
if dmg_num ~= slap_dmg then
target_ply:SetPData("slapnr_dmg", dmg_num) --This sets a new slap damage, overrides a previous one if existant.
slapnr_msg = ("#A is slapping #T for ".. tostring(slap_dmg) .." damage next round.")
elseif dmg_num == slap_dmg then
ULib.tsayError(calling_ply, "This amount of damage is already set to the target!", true) --Example: If the target already has a slapnr on them, if someone tries to do it again with the same amount of damage, they'll get notified.
else
target_ply:SetPData("slapnr_dmg", dmg_num) --This sets the slap damage.
slapnr_msg = ("#A is slapping #T for ".. tostring(slap_dmg) .." damage next round.")
end
end
ulx.fancyLogAdmin( calling_ply, slapnr_msg, target_ply )
end
end
--ULX Command things here.
local slapnr = ulx.command( CATEGORY_NAME, "ulx slapnr", ulx.slapnr, "!slapnr" )
slapnr:addParam{ type=ULib.cmds.PlayersArg }
slapnr:addParam{ type=ULib.cmds.NumArg, min=1, default=50, hint="damage", ULib.cmds.round }
slapnr:defaultAccess( ULib.ACCESS_ADMIN )
slapnr:help( "Slaps a target next round. If you don't put any number in, it will default to 50." )

What I have tried to do is to change this:
Code: [Select]
local slap_dmg = tonumber(target_ply:GetPData("slapnr_dmg")) or 0to this:
Code: [Select]
local slap_dmg = tonumber(target_ply:GetPData("slapnr_dmg", 0))It printed the same error, so I really have no clue what is needed to fix this.

Feel free to correct anything else I've done wrong, any help is appreciated.
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: GetPData Error?
« Reply #1 on: October 13, 2013, 01:47:23 PM »
Either change "PlayersArg" to "PlayerArg" or handle the table of players properly.
Experiencing God's grace one day at a time.

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: GetPData Error?
« Reply #2 on: October 13, 2013, 03:55:42 PM »
I'll try that first thing and see if that helps. Thanks for the tip!
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: GetPData Error?
« Reply #3 on: October 13, 2013, 10:45:23 PM »
That actually fixed it. Thanks Megiddo!
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: GetPData Error?
« Reply #4 on: October 14, 2013, 07:00:38 AM »
Did you ever doubt me? ;)
Experiencing God's grace one day at a time.