I'm having issues with my script having a minimum number of players to actually do something. I am getting this error though.
[quote]
[ERROR] addons/droptest/lua/autorun/psdrops_1.lua:171: attempt to call method 'Nick' (a nil value)
1. Chat - addons/droptest/lua/autorun/psdrops_1.lua:171
2. func - addons/droptest/lua/autorun/psdrops_1.lua:164
3. unknown - lua/includes/modules/net.lua:31
[/quote]
SERVER
[lua]
local players = {}
for _, ply in pairs(player.GetAll()) do
if IsValid(ply) then table.insert(players, ply)
end
if #players > 1 then
ply = table.Random(players)
net.Start("net_Chat")
net.WriteEntity(ply)
net.WriteString(RandomRare())
net.Broadcast()
end
[/lua]
CLIENT
[lua]
net.Receive("net_Chat", function()
local ply = net.ReadEntity()
local rare = net.ReadString()
Chatfunction(ply, rare)
end)
function Chatfunction(ply, rare)
chat.AddText(ply:Nick() .. " has found " .. rare .. " item!")
end
[/lua]
So if 1 player is on the server the script will not continue. When a second player joins the server they'll be dropped immediately, but the script will still run. They get this error:
[quote]
[ERROR] addons/droptest/lua/autorun/drops_2.lua:174: attempt to call method 'Nick' (a nil value)
1. Chat - addons/droptest/lua/autorun/drops_2.lua:174
2. func - addons/droptest/lua/autorun/drops_2.lua:167
3. unknown - lua/includes/modules/net.lua:31
[/quote]
In chat it will print
[quote]unconnected has just found a common item![/quote]
I purchased a script that wasn't as it appeared, so when I went to rewrite it I was successful besides this one problem. The point of this is to stop AFKers from getting items over night.
i am so confused by what you are doing i can't even help you.
-snip-
alright, here it comes.
[lua]
local players = {}
for _, ply in pairs(player.GetAll()) do
if IsValid(ply) then table.insert(players, ply)
end
[/lua]
why are you checking if the player is valid? why would player.GetAll() return an invalid player?
why are you copying the results of player.GetAll() into a redundant local table? You're taking a table of players, and just putting it into another table.
[lua]local players = player.GetAll();[/lua]
[lua]
[ERROR] addons/droptest/lua/autorun/drops_2.lua:174: attempt to call method 'Nick' (a nil value)
[/lua]
means you're trying to use the Method(function) Nick on something that isn't a player object, and is a nil.
We can't help you because you didn't include the whole file, how the hell are we suppose to know what line 174 is?
[QUOTE]
I purchased a script that wasn't as it appeared, so when I went to rewrite it I was successful besides this one problem. The point of this is to stop AFKers from getting items over night.[/QUOTE]
what did it appear to be? because i can't even tell you remotely what this script even is, this is like the output of someone who literally has [i]no idea[/i] how to script at all. who did you buy this from? how much was it?
The point of this script is not to get afkers to do anything. It has absolutely NOTHING related to afk detection what so ever.
[QUOTE=Handsome Matt;42865297]uhh that's not how you define a function, learn the language first please.[/QUOTE]
out of all the things wrong with this script, that's the one thing he did right?
I was originally just using player.GetAll() because the wiki states that it does not include players that are not connected, but it appeared untrue because I was getting a players name returned as unconnected player.
I asked another person for assistance and he had to suggest was "IsValid(ply)"
I make a table full of players because after I count the players on the server I add duplicates entries into the table to increase certain odds for players that are VIP, Regulars, ect.
I realize that is what the error is but why would I be getting that error if I am using player.GetAll()
[quote=Gmod Wiki]Gets all the current players in the server (not including connecting clients). [/quote]
I've added you on steam, but I didn't want to just post the whole file here because some of the work is not mine. It would belong to Phoenixf129. This is what I bought [url=http://coderhire.com/scripts/view/518] CoderHire[/url], but because he advertised using the word "rare" I actually thought it had the concept of rare drops...
Sorry, you need to Log In to post a reply to this thread.