2DWorlds Forums
MP Script: Tag! - Printable Version

+- 2DWorlds Forums (http://2dworlds.buildism.net/forum)
+-- Forum: 2DWorlds (http://2dworlds.buildism.net/forum/forumdisplay.php?fid=4)
+--- Forum: Scripting (http://2dworlds.buildism.net/forum/forumdisplay.php?fid=13)
+--- Thread: MP Script: Tag! (/showthread.php?tid=7412)



MP Script: Tag! - Qwertygiy - 07-30-2011

Here's a basic script you can use to make your game into a fun everlasting game of Tag!

Requirements:
  • A Box or Circle in the workspace named "ItBase", where It goes to start being It
  • A map that's fun for playing tag in

Script:
[lua]
local messages = {"Not enough players :<", "Starting game!", "Choosing %s for it...", "%s is it!", "%s has been tagged and is now it!"}


function waitFor(time)
local old = os.time()
while true do
sleep(0.001)
if os.time() - old == time then
break end end end

function Message(string, time)
game:message(string)
waitFor(time)
game:message()
end

while true do
waitFor(5)
local players = game.Players:getChildren()
if #players < 2 then
Message(messages[1], 3)
else
Message(messages[2], 3)
break end end

waitFor(1)

local playerit = nil
for q = 1, 10 do
local players = game.Players:getChildren()
playerit = players[math.random(1, #players)]
Message(string.format(messages[3], playerit.Name), 0.5)
end

Message(string.format(messages[4], playerit.Name), 3)

playerit.Character.Body.Position = game.World.ItBase.Position
playerit.Character.Body.Label.Text = "It!"
playerit.Character.Body.Fixed = true
waitFor(5)
playerit.Character.Body.Fixed = false

local enabled = true
local itconnect = nil

function Tag(player, hit)
if hit.Name == "Body" then
enabled = false
Message(string.format(messages[5], hit.Parent.Name), 2)
player.Character.Body.Label.Text = player.Name
hit.Label.Text = "It!"
itconnect:disconnect()
hit.Position = game.World.ItBase.Position
hit.Fixed = true
waitFor(5)
hit.Fixed = false
itconnect = link(hit.Collided, function(hit)
Tag(game.Players[hit.Parent.Name], hit)
end)
end end


itconnect = link(playerit.Character.Body.Collided, function(hit)
Tag(playerit, hit)
end)
[/lua]


RE: MP Script: Tag! - Ice - 07-30-2011

Yesss!

Now we need someone who is able to host a server.


RE: MP Script: Tag! - Qwertygiy - 07-30-2011

I'm going to try to re-set up my laptop for it...


RE: MP Script: Tag! - Glome - 07-31-2011

Very nice! I'm probably going to change this and make it into a Hide and Seek. Big Grin