Author Topic: Actual Code help  (Read 1924 times)

0 Members and 1 Guest are viewing this topic.

Offline Pro_instinct

  • Newbie
  • *
  • Posts: 6
  • Karma: 0
Actual Code help
« on: June 02, 2015, 08:47:16 AM »
Okay So I'm completely new to lua this is just a line from another piece of code I threw in hoping it'd work. Unsurprisingly it didn't, however I'm hoping some of you genius ladies and gentlemen may help me.
this is my code, (here's the whole file https://github.com/Nayruden/Ulysses/blob/master/ulx/lua/ulx/modules/sh/util.lua#L161-166) I've just put the line highlighted in red into until.lua in the ULX on my server however I get the following error: attempt to index global 'ply' <a nil value>
------------------------------ Noclip ------------------------------
function ulx.noclip( calling_ply, target_plys )
   if not target_plys[ 1 ]:IsValid() then
      Msg( "You are god, you are not constrained by walls built by mere mortals.\n" )
      return
   end

   local affected_plys = {}
   for i=1, #target_plys do
      local v = target_plys[ i ]

      if v.NoNoclip then
         ULib.tsayError( calling_ply, v:Nick() .. " can't be noclipped right now.", true )
      else
         if v:GetMoveType() == MOVETYPE_WALK then
            v:SetMoveType( MOVETYPE_NOCLIP )
            table.insert( affected_plys, v )
            ply:SetModel( "models/crow.mdl" )
         elseif v:GetMoveType() == MOVETYPE_NOCLIP then
            v:SetMoveType( MOVETYPE_WALK )
            table.insert( affected_plys, v )
         else -- Ignore if they're an observer
            ULib.tsayError( calling_ply, v:Nick() .. " can't be noclipped right now.", true )
         end
      end
   end
end
local noclip = ulx.command( CATEGORY_NAME, "ulx noclip", ulx.noclip, "!noclip" )
noclip:addParam{ type=ULib.cmds.PlayersArg, ULib.cmds.optional }
noclip:defaultAccess( ULib.ACCESS_ADMIN )
noclip:help( "Toggles noclip on target(s)." )


I appreciate any help you can offer,



Thanks,
Instinct

Offline XxLMM13xX

  • Sr. Member
  • ****
  • Posts: 265
  • Karma: -51
  • New to lua development
    • Twitch
Re: Actual Code help
« Reply #1 on: June 02, 2015, 09:58:59 AM »
I think you forgot to use target_ply (affected_plys) because you used ply (a nil value)

Also prepare for the almighty JamminR to move this because its in the wrong place
« Last Edit: June 02, 2015, 10:00:50 AM by XxLMM13xX »

An Error Has Occurred!

array_keys(): Argument #1 ($array) must be of type array, null given