• Print

Author Topic: VIP  (Read 5224 times)

0 Members and 1 Guest are viewing this topic.

Offline BlackDeft

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
VIP
« on: April 13, 2016, 11:46:02 am »
Hi i want to create a vip using ulx
but if i create a script with one i want to give him some more healt and speed i get this error :



[ERROR] lua/viptest.lua:2: attempt to call method 'IsUserGroup' (a nil value)
  1. fn - lua/viptest.lua:2
   2. unknown - addons/ulib_557962238/lua/ulib/shared/hook.lua:110
    3. Spawn - [C]:-1
     4. unknown - gamemodes/base/gamemode/player.lua:115



 my script at that moment look :

local function spawn( ply )
   if ( Player( 2 ):IsUserGroup( "VIP" ) ) then

      SetPlayerSpeed( ply , 300, 80 )
   end
end
hook.Add( "PlayerSpawn", "some_unique_name", spawn )


can someone tell me whats wrong ?

Offline Buzzkill

  • Respected Community Member
  • Full Member
  • *****
  • Posts: 176
  • Karma: 59
    • The Hundred Acre Bloodbath
Re: VIP
« Reply #1 on: April 13, 2016, 01:31:35 pm »
Code: [Select]
  if ( Player( 2 ):IsUserGroup( "VIP" ) ) then

Why Player(2)?  Should by ply, like the other two references to it in your script.


Quote
"some_unique_name"

You really should change that to something, um... unique.  :)

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: VIP
« Reply #2 on: May 10, 2016, 06:14:33 pm »
Hi i want to create a vip using ulx
but if i create a script with one i want to give him some more healt and speed i get this error :



--snipped error



 my script at that moment look :

--Snipped code
can someone tell me whats wrong ?
I know this is fairly old and the OP didn't post anything new, but I'm just putting this here for future reference if anyone needs.


Especially if you try to load it in a singleplayer game, this error is no surprise. If you have ( Player( 2 ):IsUserGroup it's going to find the usergroup of that person. If you're in singleplayer, there is no one with the ID of 2, so it becomes a nil value. All you'd need to do is ( Player( ply ) because your function has the variable ply.

If you change it to just
Code: Lua
  1. local function spawn( ply )
  2.    if ( Player( ply ):IsUserGroup( "VIP" ) ) then
  3.     SetPlayerSpeed( ply , 300, 80 )
  4.    end
  5. end
  6. hook.Add( "PlayerSpawn", "some_unique_name", spawn )

It should work just fine :)
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline dankpepe

  • Jr. Member
  • **
  • Posts: 51
  • Karma: 1
Re: VIP
« Reply #3 on: May 13, 2016, 08:52:51 am »
Or you could just use UTeam, no need for lua.

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Re: VIP
« Reply #4 on: May 13, 2016, 09:43:02 am »
Or you could just use UTeam, no need for lua.
UTeam doesn't work on every gamemode.
bw81@ulysses-forums ~ % whoami
Homepage

  • Print