Hello again.I am working on friendly fire script.It should work like this:when a CP shoots another CP,he will get message(for example Watch out!).Because I am noob in LUA (I started yesterday :smile:),i get this in return [lua\friendly_fire_warning_.lua:2] 'then' expected near 'PlayerTeam'.
Here is the code:
[CODE]local MyHookFunction = function()
if PlayerTeam(TEAM_POLICE)():KeyDown(IN_ATTACK)PlayerTeam(TEAM_POLICE) then
add.ChatText("Watch out!")
end
end
hook.Add("Think", "My button hook", MyHookFunction)[/CODE]
I will be very thankful to anyone who will help me to solve this.
Forez
Don't use a Think hook to check for this. There are hooks that are much more suitable for this, such as [b][url=wiki.garrysmod.com/?title=Gamemode.PlayerHurt]Gamemode.PlayerHurt [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b].
Check if the attacker and victim are on the same team ([b][url=http://wiki.garrysmod.com/?title=Player.Team]Player.Team [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]).
If they are, print a message to the attacker ([b][url=http://wiki.garrysmod.com/?title=Player.ChatPrint]Player.ChatPrint [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]).
You should also have a look at [URL="http://wiki.garrysmod.com/?title=Lua_Tutorial_Series"][B]this[/B][/URL].
Thank you for your reply.I am very unsure about this part:
[CODE]if Player.Team(TEAM_POLICE)():KeyDown(IN_ATTACK)Player.Team(TEAM_POLICE)[/CODE]
Also I am not sure how I can make that message appear only to attacker.
Thank you.
EDIT:Here is the code I wrote after your post.
[QUOTE]local MyHookFunction = function()
if Player.Team(TEAM_POLICE)():KeyDown(IN_ATTACK)Player.Team(TEAM_POLICE) then
Player.ChatPrint("Watch out!")
end
end
hook.Add("Gamemode.PlayerHurt", "My button hook", MyHookFunction)[/QUOTE]
You're supposed to click the link, not paste it into your code. Read the examples on the pages, they will explain everything. Also, for the love of good, read the tutorials I linked.
PS: No, I do not give out advice or fix your code through Steam chat. Sorry.
Problem solved,thank you for your advice.
Sorry, you need to Log In to post a reply to this thread.