ULX

Author Topic: Listing Players Weapons by String  (Read 5027 times)

0 Members and 3 Guests are viewing this topic.

Offline Bite That Apple

  • Hero Member
  • *****
  • Posts: 858
  • Karma: 416
  • Apple Innovations 2010®
    • Fun 4 Everyone Gaming
Listing Players Weapons by String
« on: January 13, 2015, 09:22:43 PM »
I've been trying to find a way to list a specific player's weapons, using this command ply:GetWeapons() Though, I don't want that outputs stuff. I just want the string name of the weapon, not the userdata, I don't know what to do with that, and I don't know how to fix it. Help appreciated plz :(

Code: [Select]
for k, v in pairs(ply:GetWeapons()) do
MsgN(v)
end

OUTPUT

Code: [Select]
Weapon [113][weapon_crowbar]
Weapon [114][weapon_pistol]
Weapon [115][weapon_smg1]
Weapon [117][weapon_frag]
Weapon [119][weapon_physcannon]
Weapon [120][weapon_crossbow]
Weapon [121][weapon_shotgun]
Weapon [122][weapon_357]
Weapon [123][weapon_rpg]
Weapon [124][weapon_ar2]
Weapon [125][gmod_tool]
Weapon [128][gmod_camera]
Weapon [129][weapon_physgun]
Quote from: John F. Kennedy 1963
A man may die, nations may rise and fall, but an idea lives on.

Offline Avoid

  • Full Member
  • ***
  • Posts: 142
  • Karma: 42
Re: Listing Players Weapons by String
« Reply #1 on: January 14, 2015, 03:39:14 AM »
Hello,
maybe this clientsided function may be of use to you: weapon:GetPrintName()

Hope this was somewhat useful,
Avoid

Offline Bite That Apple

  • Hero Member
  • *****
  • Posts: 858
  • Karma: 416
  • Apple Innovations 2010®
    • Fun 4 Everyone Gaming
Re: Listing Players Weapons by String
« Reply #2 on: January 14, 2015, 05:32:53 PM »
Hello,
maybe this clientsided function may be of use to you: weapon:GetPrintName()

Hope this was somewhat useful,
Avoid

ply:GetWeapons() is a server side command.
Quote from: John F. Kennedy 1963
A man may die, nations may rise and fall, but an idea lives on.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Listing Players Weapons by String
« Reply #3 on: January 14, 2015, 07:29:30 PM »
BTA, this same challenge has been discussed somewhere among these forums before.
Likely in Dev corner, but i'm not going to swear to that.
Do some searching for Getweapon or other base lua words and you'll likely find it.
Overall, I think net messages or send lua from server to client had to be done.
Now that I've typed this much, I think I even remember MrPresident having a good solution.

EDIT -
http://forums.ulyssesmod.net/index.php/topic,7697.0.html
Not fully what you want (not full list), but, at least it shows how to do what a person is holding according to the server.
« Last Edit: January 14, 2015, 07:31:52 PM by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Bite That Apple

  • Hero Member
  • *****
  • Posts: 858
  • Karma: 416
  • Apple Innovations 2010®
    • Fun 4 Everyone Gaming
Re: Listing Players Weapons by String
« Reply #4 on: January 14, 2015, 08:22:41 PM »
BTA, this same challenge has been discussed somewhere among these forums before.
Likely in Dev corner, but i'm not going to swear to that.
Do some searching for Getweapon or other base lua words and you'll likely find it.
Overall, I think net messages or send lua from server to client had to be done.
Now that I've typed this much, I think I even remember MrPresident having a good solution.

EDIT -
http://forums.ulyssesmod.net/index.php/topic,7697.0.html
Not fully what you want (not full list), but, at least it shows how to do what a person is holding according to the server.

I can do that without an issue, I'm just looking for a way to like a players entire weapons by string, instead of table, because I don't understand tables enough to actually somehow make it work.

----

On another topic, is there a way to check is a players is Noclipping, because the command PlayerNoClip is very buggy. I might as well just come out and see what I'm searching for or trying to make.

I'm trying to make it so that when a player is in noclip, there weapon gets switched to Physigun, and they can not equip a any other weapon. Also, or I'm trying to make it so that when a player enters noclip, all their weapons get removed, and they're only given physgun and tool gun. If anyone can direct me in the correct direction, that would be nice.
Quote from: John F. Kennedy 1963
A man may die, nations may rise and fall, but an idea lives on.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Listing Players Weapons by String
« Reply #5 on: January 14, 2015, 08:36:50 PM »
I believe GetClass() is what you want.
Experiencing God's grace one day at a time.

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Re: Listing Players Weapons by String
« Reply #6 on: January 15, 2015, 03:41:28 AM »
"On another topic, is there a way to check is a players is Noclipping"

PlayerNoClip is called when a player wants to turn on/off noclip
You can probably do stuff like that with that hook

Offline Bite That Apple

  • Hero Member
  • *****
  • Posts: 858
  • Karma: 416
  • Apple Innovations 2010®
    • Fun 4 Everyone Gaming
Re: Listing Players Weapons by String
« Reply #7 on: January 15, 2015, 01:51:58 PM »
"On another topic, is there a way to check is a players is Noclipping"

PlayerNoClip is called when a player wants to turn on/off noclip
You can probably do stuff like that with that hook

On another topic, is there a way to check is a players is Noclipping, because the command PlayerNoClip is very buggy.

------------------------------------

I believe GetClass() is what you want.

Thank you, that's what I was looking for, but sadly, due to the fact that PlayerNoClip is so buggy, my idea failed, but I got it to work with other means.
Quote from: John F. Kennedy 1963
A man may die, nations may rise and fall, but an idea lives on.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Listing Players Weapons by String
« Reply #8 on: January 15, 2015, 09:01:53 PM »
players entire weapons by string, instead of table, because I don't understand tables enough to actually somehow make it work.

Until you learn, your going to be extremely limited in anything you can do in lua, or any programming language for that matter.
Table. Array. Matrix. 3 common terms across various languages.
Learn them Padawan.

Additionally, though I've not done any research what-so-ever, I question playernoclip actually being buggy, instead of just not being used correctly.
We use it in ULX with no issue we know of.

« Last Edit: January 15, 2015, 09:06:46 PM by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Bite That Apple

  • Hero Member
  • *****
  • Posts: 858
  • Karma: 416
  • Apple Innovations 2010®
    • Fun 4 Everyone Gaming
Re: Listing Players Weapons by String
« Reply #9 on: January 16, 2015, 02:55:17 AM »
Until you learn, your going to be extremely limited in anything you can do in lua, or any programming language for that matter.
Table. Array. Matrix. 3 common terms across various languages.
Learn them Padawan.

I worded it incorrectly, let me try again. I understand tables, but I don't know library enough to actually use all features. There are just some things I don't feel the need to do use unless I really need them, and I'll typically get lucky and get them to work, others; well then we're in this type of situation that I was in.

Additionally, though I've not done any research what-so-ever, I question playernoclip actually being buggy, instead of just not being used correctly.
We use it in ULX with no issue we know of.

Code:
(Whether or not the timer is there doesn't make a difference to the error, it will still error out, and not work)
This simple little piece of code should work, and it DOES, but only half way. This does give the message to the player saying they should not kill while in noclip, but then gives the error which will be located below. Now if you say I'm using it wrong still, obviously my basic understanding of hooks has changed.

Code: [Select]
[1] -- SERVER SIDE
[2]
[3]function DisableNoclipNoWeps2( ply )
[4] timer.Simple(0.5, function()
[5] if ply:GetMoveType() == 8 then
[6] umsg.Start("PlayerNoNoclipKill", ply)
[7] umsg.String("You are now in noclip do not kill people while in noclip!")
[8] umsg.End()
[9] end
[10] end)
[11]end
[12]hook.Add("PlayerNoClip", "DisableNoclipNoWeps2", DisableNoclipNoWeps2)

ERROR:

Code: [Select]
[Dev Apple|191|STEAM_0:0:35379784] Lua Error:

[ERROR] addons/apple_noclip_noweapons/lua/autorun/sv_noclip_no.lua:6: attempt to index global 'umsg' (a nil value)
  1. unknown - addons/apple_noclip_noweapons/lua/autorun/sv_noclip_no.lua:6
« Last Edit: January 16, 2015, 02:56:50 AM by Bite That Apple »
Quote from: John F. Kennedy 1963
A man may die, nations may rise and fall, but an idea lives on.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Listing Players Weapons by String
« Reply #10 on: January 16, 2015, 10:21:34 AM »
What's the client side code you're using to deliver the string to player's attention?


"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Bite That Apple

  • Hero Member
  • *****
  • Posts: 858
  • Karma: 416
  • Apple Innovations 2010®
    • Fun 4 Everyone Gaming
Re: Listing Players Weapons by String
« Reply #11 on: January 21, 2015, 12:23:15 AM »
What's the client side code you're using to deliver the string to player's attention?

Code: [Select]
function PlayerSpawnNoKill(data)
chat.AddText(Color(255,255,0),data:ReadString())
end
usermessage.Hook("PlayerSpawnNoKill", PlayerSpawnNoKill)
Quote from: John F. Kennedy 1963
A man may die, nations may rise and fall, but an idea lives on.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Listing Players Weapons by String
« Reply #12 on: January 21, 2015, 06:52:22 PM »
Did you grab from the wrong client side code of your file?
Your noclip user message is named "PlayerNoNoclipKill"
Client side code you posted looks like its from another user message regarding spawn instead of noclip.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Bite That Apple

  • Hero Member
  • *****
  • Posts: 858
  • Karma: 416
  • Apple Innovations 2010®
    • Fun 4 Everyone Gaming
Re: Listing Players Weapons by String
« Reply #13 on: January 22, 2015, 12:58:01 AM »
Did you grab from the wrong client side code of your file?
Your noclip user message is named "PlayerNoNoclipKill"
Client side code you posted looks like its from another user message regarding spawn instead of noclip.

I have three user messages in the client side code, I just copied the first one, because I just thought it was relating to the server side, but it looks like I did it out of order. Either way, it still gives an error.
Quote from: John F. Kennedy 1963
A man may die, nations may rise and fall, but an idea lives on.