简体   繁体   English

团队检查武器经销商加里的 mod darkrp 游戏模式

[英]team checking weapon dealer garry's mod darkrp gamemode

I want to make a npc system if some players in this job "weapon dealer" npc can't be used我想制作一个NPC系统,如果这个职业“武器经销商”的一些玩家无法使用npc

i tried this but didn't work我试过这个,但没有用

i put this code on lua/entities/npc/init.lua我把这段代码放在 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对不起,我试图学习的糟糕代码

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.你做错了 if 语句,要检查 if 语句中的某个东西是否等于其他东西,你需要使用 == 而不是 = 因为使用单个等号告诉它你正在设置数据而不是检查数据。

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;就计算出有多少人在做你目前没有做的工作来告诉代码计算团队中的人数而言,gmod 有一个函数; https://wiki.facepunch.com/gmod/team.NumPlayers 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;很难确切地说如何修复您的代码,因为您没有提供太多细节,例如 pl 来自何处,但这并不是太重要,我会这样做;

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) (我知道这篇文章很旧,但更多的回应是为了帮助任何有相同类型问题的人)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM