• How do I create two factions?
    27 replies, posted
As the title, how could I create two factions? You can't damage any NPC/player in your own faction. I haven't tried a single line of code myself, yet. Just want to know if it's simple or hard.
It's simple.
[QUOTE=_nonSENSE;26965761]It's simple.[/QUOTE] Great response. My guess is something like the teams, team_bla1, team_blabla1, bla2, blabla2. and if you're a bla1, you cant damage a blabla1, but bla2
Yes, that works. Have look at this link: [b][url=wiki.garrysmod.com/?title=Gamemode.PlayerShouldTakeDamage]Gamemode.PlayerShouldTakeDamage [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
-_- create teams in shared.lua [lua] shared.lua team.SetUp( 1, "Me", Color( 0, 0, 255, 255 ) ) team.SetUp( 2, "Your Mom", Color( 255, 128, 201, 255 ) ) team.SetUp( 3, "Spectators", Color( 0, 0, 0, 255 ) ) [/lua] As for no team killing, [lua] init.lua function GM:PlayerShouldTakeDamage(victim, pl) if pl:IsPlayer() == 1 then //If the attacker is a player if pl:Team() == victim:Team() then //If the player is a player hater return false // then deny the player hater end end end [/lua]
Those are some pretty awful line comments. Also, pl:IsPlayer() returns a bool, so compare it to a bool.
[QUOTE=Andriko1;26983010]-_- create teams in shared.lua [lua] shared.lua team.SetUp( 1, "Me", Color( 0, 0, 255, 255 ) ) team.SetUp( 2, "Your Mom", Color( 255, 128, 201, 255 ) ) team.SetUp( 3, "Spectators", Color( 0, 0, 0, 255 ) ) [/lua] As for no team killing, [lua] init.lua function GM:PlayerShouldTakeDamage(victim, pl) if pl:IsPlayer() == 1 then //If the attacker is a player if pl:Team() == victim:Team() then //If the player is a player hater return false // then deny the player hater end end end [/lua][/QUOTE] no need to do "==1 " with IsPlayer(), since its true or false, just do: if x:IsPlayer() ( if x is a player, true) or if !x:IsPlayer() ( if x is not (!) a player, false)
[QUOTE=Andriko1;26983010]-_- create teams in shared.lua [lua] shared.lua team.SetUp( 1, "Me", Color( 0, 0, 255, 255 ) ) team.SetUp( 2, "Your Mom", Color( 255, 128, 201, 255 ) ) team.SetUp( 3, "Spectators", Color( 0, 0, 0, 255 ) ) [/lua] As for no team killing, [lua] init.lua function GM:PlayerShouldTakeDamage(victim, pl) if pl:IsPlayer() == 1 then //If the attacker is a player if pl:Team() == victim:Team() then //If the player is a player hater return false // then deny the player hater end end end[/QUOTE] It would be for the best to not actually just set them on a new team. 2 teams, multiple factions. This way he doesn't have to go and set new spawn points for every single team.
[QUOTE=_nonSENSE;26983069]Those are some pretty awful line comments. Also, pl:IsPlayer() returns a bool, so compare it to a bool.[/QUOTE] The code is simple and self explanatory, and last time I checked, 1 and 0 are bools
The only annoying part about this is the fact you want both npcs and players in the same faction to not hurt eachover.
[QUOTE=Zephilinox;26983114]no need to do "==1 " with IsPlayer(), since its true or false, just do: if x:IsPlayer() ( if x is a player, true) or if !x:IsPlayer() ( if x is not (!) a player, false)[/QUOTE] comparing it to 1, 0, true, or false is my style, keep your style to yourself
[QUOTE=Andriko1;26983195]last time I checked, 1 and 0 are bools[/QUOTE] a boolean is true or false [EDITLINE] asdas [/EDITLINE] 1 and 0 are integers, they are different data types.
[QUOTE=Andriko1;26983010]-_- create teams in shared.lua [lua] shared.lua team.SetUp( 1, "Me", Color( 0, 0, 255, 255 ) ) team.SetUp( 2, "Your Mom", Color( 255, 128, 201, 255 ) ) team.SetUp( 3, "Spectators", Color( 0, 0, 0, 255 ) ) [/lua] As for no team killing, [lua] init.lua function GM:PlayerShouldTakeDamage(victim, pl) if pl:IsPlayer() then //If the attacker is a player if pl:Team() == victim:Team() then //If the player is a player hater return false // then deny the player hater end end return true --you must return true here otherwise nobody would get damaged. end[/lua][/QUOTE] Fixed the code there
[QUOTE=Andriko1;26983195]The code is simple and self explanatory, and last time I checked, 1 and 0 are bools[/QUOTE] No. Its misleading. A bool returns true or false., not 1 or 0.
>.< are you sure? [url]http://wiki.garrysmod.com/?title=Gamemode.PlayerShouldTakeDamage[/url]
[QUOTE=Andriko1;26983402]>.< are you sure?[/QUOTE] [QUOTE=c-unit;26983195]a boolean is true or false 1 and 0 are integers, they are different data types.[/QUOTE]
look at my previous edit
[QUOTE=Andriko1;26983216]comparing it to 1, 0, true, or false is my style, keep your style to yourself[/QUOTE] It's not a style, its the only way to do it, unless you want to waste time and do an unecessary " == true " after it. from the wiki link you posted: [lua] function GM:PlayerShouldTakeDamage( victim, pl ) if pl:IsPlayer() /* look to your left, theres no == 1 */ then -- check the attacker is player if( pl:Team() == victim:Team() and GetConVarNumber( "mp_friendlyfire" ) == 0 ) then -- check the teams are equal and that friendly fire is off. return false -- do not damage the player end end return true -- damage the player end [/lua]
[QUOTE=Andriko1;26983454]look at my previous edit[/QUOTE] [img]http://gyazo.com/e9ffc4c6876e08afca9e320ec5ae1a0a.png[/img] :frog:
... it said pl:IsPlayer() == 1 until you edited it for god sakes just stop spamming this thread, 1/0 is accepted as boolean in multiple languages, just stop, other people have questions too and this is still at the top even when I have an answer Loures is the only guy who helped other than me
[QUOTE=Andriko1;26983594]... it said pl:IsPlayer() == 1 until you edited it[/QUOTE] -snip-
True, it was == 1 before "Zack" edited it today.
[QUOTE=Andriko1;26983594]... it said pl:IsPlayer() == 1 until you edited it for god sakes just stop spamming this thread, 1/0 is accepted as boolean in multiple languages, just stop, other people have questions too and this is still at the top even when I have an answer Loures is the only guy who helped other than me[/QUOTE] Its not good practice.
[QUOTE=Andriko1;26983594]Loures is the only guy who helped[/QUOTE] Anyways back to helping the man. What you could do is make a NWString and if they click button1 ply:SetNWString("Faction Name"). then if ply:GetNWString() == "Faction Name" then do stuff
--snip-- nobody cares anyways
To create two factions you should use teams. [b][url=wiki.garrysmod.com/?title=Team]Team Library [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] I am unsure about what you mean about a faction but you should read up on the Team library listed above. @Andriko1 nice backseat moderation.
[QUOTE=Andriko1;26983737]Omg, I don't care, stop posting after this[/QUOTE] Then that would go against the point of the thread, which is to answer the OP's question. [QUOTE=_nonSENSE;26965761]It's simple.[/QUOTE] Never mind, found it.
[QUOTE=Andriko1;26983594]... it said pl:IsPlayer() == 1 until you edited it for god sakes just stop spamming this thread, 1/0 is accepted as boolean in multiple languages, just stop, other people have questions too and this is still at the top even when I have an answer Loures is the only guy who helped other than me[/QUOTE] You clearly don't know the difference between a comparison and a boolean, so please try to conform to standard Lua practise when helping for Lua questions - which means that 0 and 1 are both treated as non nil, and so will pass in an if statement, but neither are true or false.
Sorry, you need to Log In to post a reply to this thread.