-1

I want to make a npc system if some players in this job "weapon dealer" npc can't be used

i tried this but didn't work

i put this code on lua/entities/npc/init.lua

if pl:Team() = TEAM_DEALER > 0 then
    chat.AddText(Color(255, 0, 0), "Someone is doing Weapon Dealer job  you cant use the npc.Go and buy on weapon dealer!!")
    return end

sorry for my shitty code i trying to learn

mjos
  • 1
  • 1
  • Welcome to Stack overflow, your question needs some work. Can you explain what error you are getting or what is wrong with your attempted implementation? as 1 note `pl:Team() = TEAM_DEALER` this is an assignment not a check that these are equal, need to use `==` – Nifim May 24 '19 at 18:46
  • thx `for k, v in pairs(player.GetAll()) do if v:Team() == TEAM_DEALER then return end end` – mjos May 24 '19 at 19:57

1 Answers1

0

You have done the if statement wrong, to check if something is equal to something else in an if statement you need to use == rather than = as using a single equals sign tells it you are setting data rather than checking data.

In terms of working out how many people are doing the job you currently are doing nothing to tell the code to count the number of people on a team, gmod has a function for that; https://wiki.facepunch.com/gmod/team.NumPlayers

It is hard to say exactly how to fix your code as you have not provided much detail such as where pl is coming from but that is not too important, the way I would do this is;

if team.NumPlayers(TEAM_DEALER) > 0 then
    chat.AddText(Color(255, 0, 0), "Someone is doing Weapon Dealer job  you cant use the npc.Go and buy on weapon dealer!!")
    return
end

Also, you should learn to use prints to debug, using a print and checking console can help show how far the code is getting and can help show where the issue is.

(I know this post is old but more responding to help anyone with the same type of issue)