Now I have read couple go tutorials and know the basics of lua so I decided to try make my first script. I want to make a script for jailbreak that allows the warden to separate the prisoners into 2 teams using colour red and blue. Just by pushing a button like f2, and then to be able to return them to normal using the same button.
I though that this wouldn't be too hard for a first script but I might be mistaken. Either way, I don't know where to start. I watched more tutorials and guide but I have no idea what class would it go under. If I know where to start I might be able to figure out the rest.
I bet it's really obvious and I probably already read something on how to do something like that but like I said I never done one before and I am kind of stuck.
You can laugh as much as you want I really don't mind xD I do know it's probably dead easy
Thanks to anyone who is willing to help!
[code]
local pris = TEAM_ENEMY -- your team number or constant
local red,blue,all,need = {},{},team.GetPlayers(pris)
need=math.floor(#all/2) -- half of all
while #red < need do -- make red
local outpl=table.Random(all)
table.insert(red,outpl)
table.RemoveByValue(all,outpl)
if IsValid(outpl) and outpl:IsPlayer() then
outpl:SetPlayerColor(Vector(1,0,0))
end
end
while #blue < need do -- make blue
local outpl=table.Random(all)
table.insert(blue,outpl)
table.RemoveByValue(all,outpl)
if IsValid(outpl) and outpl:IsPlayer() then
outpl:SetPlayerColor(Vector(0,0,1))
end
end
if #all>0 then -- if last one
for _,v in pairs(all) do
if math.random(1,2) == 1 then
table.insert(red,v)
v:SetPlayerColor(Vector(1,0,0))
else
table.insert(blue,v)
v:SetPlayerColor(Vector(0,0,1))
end
end
end
[/code]
It should work.
[code]local red, blue = {}, {}
hook.Add( "ShowTeam", "asignTeam", function( ply )
local target = ply:GetEyeTrace().Entity or false
if not target or not target:IsPlayer() then return end
if not table.HasValue( red, target ) then
table.insert( red, target )
target:SetColor( Color( 255, 0, 0 ) )
else
table.insert( blue, target )
target:SetColor( Color( 0, 0, 255 ) )
end
end )[/code]
Untested, but you should be able to catch a grasp of how it should be done.
Plus, this way is way better than having while loops.
Thanks that's a big help :)
Sorry, you need to Log In to post a reply to this thread.