You are not logged in. Please log in if you wish to participate in all discussions on the website, chat with friends, and use everything we've got to offer.

Click Register below to, well, register. Derp. Enjoy your stay. ;)

If you do not have an account and wish to create one, please follow the link below.

http://www.robloxtoday.net/register

You are not connected. Please login or register

Goto page : 1, 2  Next

View previous topic View next topic Go down  Message [Page 1 of 2]

Gravyerd


Telamon
The names says it all =]
To start this tutorial you needs a basic "advanced" sintax knowleadg of robloxs lua.
This tutorial is to people that plays script builder or make free models to others people.

Function Type(value)

The function type verify the type of his parameter
These types can be "number","string","nil","userdata","table"
its usefull to detect if somenoobs sends a wrong parameter to your scripts.
Example of use
function lol(p)
if type(p) == "number" then
return p+1
end
end

you can send everything, dont return a error.
but looks without a function type:

function lol(par)
return par+1
end
b = lol(CFrame.new(1,1,1))
print(b)

(obs: CFrame is userdata)
This results an error cause CFrame is not a number, you cant put Cframe(1,1,1)+1 cause its impossible o.O differents types!

Thats quite easy, i hope, lets continue

className uses

Lots people NEVER use classname, but its needed
if you add some "Part" in game.Players at script builder, what you think that happenz?
every command script BUGS a LOT!
thats why the people thinks: "Added in players Player is!"
FIRST: when you put a script a free models, ITS FREE, everyone use, and you dont know nothing about others games!
person299 commands admin makes bugs! he is script master (or was), but at his time no ones uses that ;/

you all needs understand that conditions are made for over-use, there arent drugs!

Exemple of use
Code:
function NewP(newPlayer)
if newPlayer.className == "Player" then
...
end
end

Code:
function onClick(part)
if part.Parent.className == "Model" then
part.Parent:Remove()
end
end

Code:
function RemoveTool(player)
if player.className == "Player" then
b = player:findFirstChild("Backpack")
if b.className == "Backpack" then
c = b:findFirstChild("Tool")
if c.className == "HopperBin" then
c:remove()
end
end
end
end


Double Conditions


Peoples KNOW about className but dont about nil parameters!
a nil parameter dont exists, its like Player(), no parameters ;/
you can use the function type, thats tell you if its nil or not!
but if its a userdata, you need to know if its nil and if its a classname.
the people forget that!
Code:

function PKill(player)
if type(player) == "userdata" then
player.Character:Breakjoints()
end
end

to somthing with double condition, like that:
Code:

function PKill(player)
if type(player) == "userdata" and player.className == "Player" then
player.Character:Breakjoints()
end
end


I mean that OTHERS PEOPLE bugs your script.
Thinks a leaderboard add script
THE SCRIPTS WAITS 5 SECONDS TO ADD THE LEADERBOARD!
and if in 2.5 seconds the player leave the game?
the parameter IS NIL!
you will put leaderboard in a nil place!
well nothing happenz cause its a event and the event will happens every time... (ChildAdded)
but if someone takes your script and add something after the leaderboard code?
anyway, less errors better run


Existing madness


game.Players.Name = "Lol";
only 50% of scripts will work. (or less)
game.Workspace.Name = "Lol"
only 0% of scripts will work (OR LESS!)

Why the error happens:
Bad scripters thinks that game.Players and game.Workspace never changes.
Good scripters change the game.Players.Name to make noobs dont use ban/kick script, is sad, but prevents noob-kick's

How to detect game places without wanting the name
Code:

function GetGameMain()
local arr_find = game:GetChildren();
local lp1 = 0;
local str_txt = "";
   for lp1 = 1, #arr_find do
      if (type(arr_find[lp1]) == "userdata") then
      str_txt = arr_find[lp1].className;
         if (str_txt == "Workspace") then
         Wo = arr_find[lp1];
         elseif (str_txt == "Players") then
         Pl = arr_find[lp1];
         elseif (str_txt == "Lighting") then
         Li = arr_find[lp1];
         elseif (str_txt == "Teams") then
         Te = arr_find[lp1];
         end;
      end;
   end;
end;

GetGameMain()


Thats will found workspace,players,lighting and teams, whatever the name of this name.
and store at variables Wo,Pl,Li and Te (Workspace,Players,Lighting,Team)


Make a fake Players:

Code:
Pl = game.Players
Pl.Name = "LAWL"
a = Instance.new("Model")
a.Parent = game
a.Name = "Players" -- fake players


Gonna makes lots errors =]
DIRECT ERRORS at command scripts =]

Remove the Backpack of everyone on the script builder
No tools and no command scripts

Rename Players
no command scripts

Rename Workspace
no workspace scripts

The games is arround that =]

Remmember:
dont put:
Player.Backpack
put:
local bp = Player:findFirstChild("Backpack")
if type(bp) == "userdata" and bp.className == "Backpack" then
...

Break scripts are the soluctions when youre trapped!
When you found a auto-killer, change the game.Players or game.Workspace name! this will stop!
When you found a auto-slaver name, change the game.Players or game.Workspace name! this will stop!

Rename it back and the script dont come back (only if the scripter writer is good ._.)

The noobs that destroy your games ever are noob, you can pwn they cause that ;p
If youre banned, come with other acount and change game.Players name!
come with other account and HAVE FUN with the people that banned you (and don understand nothing any+)
just rename it back to un-break the server! =]
or ban him in his face =p


FindFirstChild

This function finds somthing inside the object by a name ;/
is not perfect, but its for things that only works if have a specify name
example:
leaderboard ~ inside a player this CANT have other name
Backpack ~ inside a player this cant have other name

Anyway, findfirstchild works to detects if somthing exists or its just your imagination .-.

ex:
if game:findFirstChild("Workspace") ~= nil then
print("game.Workspace Exists!");
end

understand?
but that most used for others things .-.

ex:
(newplayer = game.Players.Player);
local a = newPlayer:findFirstChild("Backpack")
if type(a) == "userdata" and a.className == "Backpack" then
print("There is a backpack and itsnt a fake.");


Questions
If you wanna be smart, do these question and see if you was right.

1) Improve these scripts:
a)
Code:
function onHit(p)
p:Remove()
end
script.Parent.Touched:connect(onHit)

Description: Delete's a human part without direct killing it

b)
Code:
function onHit(p)
p.Parent:BreakJoints()
end
script.Parent.Touched:connect(onHit)

Description: Direct kill a player w/ breakjoints

c)
Code:
function onHit(p)
a = game.Players:FindFirstChild(p.Parent.Name)
a.leaderboard.Cash = 10
a.BrickColor = BrickColor.new("Bright Blue")
script:Remove()
end
script.Parent.Touched:connect(onHit)

Description: Gives 10 cash for the user, disactive the giver and change the part giver to Bright Blue (to show its disactived)

2) Re-write the script and make it dont result in a error with the calls.
(it means: you modify the function and dont modify the calls, the script CANT result in a error but need work);
a)
Code:
function KillChar(player)
player.Character:BreakJoints()
end

Supose to: Kill the characte
Calls
Code:
KillChar(game.Workspace.Part);
KillChar(game.Workspace.Parent.Parent)
KillChar([[I like cookies]])
KillChar(13)
KillChar(game.Players.Player) -- This supposes to EXISTS


b)
Code:
function NoArm(player)
player.Character.LeftArm:Remove()
player.Character.RightArm:Remove()
end

Suppose to: Remove right and left legs of the player.
Calls
Code:

NoArm(game.Players.Player) -- This supposes to EXISTS
NoArm(game.Players)
NoArm(game.Workspace.Part)
NoArm(1)
NoArm()

c)
Code:
function OnPlayerEntered(newPlayer)
a = Instance.new("Hint")
a.Name = "Heayaeay";
a.Text = "YOUR NAME IS " .. newPlayer.Name -- yeah... dont forget your name in the middle of the game xp
a.Parent = newPlayer
end

Suppose to send teh msg without raising a error... nevah!
Calls
Code:

game.Players.ChildAdded:connect(OnPlayerEntered)
OnPlayerEntered("Lawl")
local b = Instance.new("Part")
b.Parent = game.Players


3) PROVE YOUR MASTERY to yourself :

Only edit the part with the color green

game.Players.Name = math.random(0,1000).. "Háh" .. math.random(100,200)
-- Put your code here --
function onPlayerAdded(new)

new.CharacterAdded:connect(function() new.Character.Name = "My slave" end);
end
game.Players.ChildAdded:connect(
onPlayerAdded())
a = Instance.new("Part")
a.Name = "lol"
a.Parent = game.Players



I will put results ... after Xd

i dont like models lots of errors and i think that is somthing for noobs ._.

Credits are mine ;/



Last edited by Gravyerd on 5/25/2010, 9:13 pm; edited 2 times in total

View user profile

DAMAGED


Moderator
Moderator
Needless to say I already like this guy alot.


____________________________
Spoiler:

~Skills ~
Scripting level - ADVANCED
Building level - EBR acceptable
'06er
Skype: Refit.
View user profile

Pikachu908


Experienced Robloxian
Experienced Robloxian
That's a lot of green stuff...

View user profile http://www.roblox.com/User.aspx?ID=794476

Gravyerd


Telamon
?
green stuff?
lol .-. what this mean? =p

View user profile

Yoshislayer


Experienced Robloxian
Experienced Robloxian
Hmm, just looking at it makes me want to eat myself... Actually it gave me an urge to eat some Raman noodles :3

View user profile http://www.roblox.com/User.aspx?ID=1174617

Alex


Special
Special
Gravyerd has always been posting things like this. He's a great help to the community.


____________________________
Evening, Guest Welcome to the Roblox Today Forums!
Hello, I am Alex. The Forum's Head Moderator.



I joined ROBLOX, December 29th, 2007!
I was one of the first to join this lovely forum, invited by Clayton himself. The memories. Ah.
Administrators have too much power, therefore my position suits me just fine!
View user profile http://www.robloxtoday.com

Pikachu908


Experienced Robloxian
Experienced Robloxian
I can't script. So I reffer those letters, numbers and symbols as green stuff.

View user profile http://www.roblox.com/User.aspx?ID=794476

Gravyerd


Telamon
Oooh results *-*

1)a)
Code:
function onHit(part)
if part ~= nil and part.Parent ~= nil and part.Parent.className == "Model" and game.Players:findFirstChild(part.Parent.Name) ~= nil and game.Players:findFirstChild(part.Parent.Name).className == "Player" then
part:Remove()
end
end
script.Parent.Touched:connect(onHit)


Code makes sure's that is a player that has touched.

1)b)

Code:
function onHit(part)
if part ~= nil and part.Parent ~= nil and part.Parent.className == "Model" and game.Players:findFirstChild(part.Parent.Name) ~= nil and game.Players:findFirstChild(part.Parent.Name).className == "Player" then
game.Players:findFirstChild(part.Parent.Name):BreakJoints()
end
end
script.Parent.Touched:connect(onHit)


1)c)
Code:
function onHit(p)
if part ~= nil and part.Parent ~= nil and part.Parent.className == "Model" and game.Players:findFirstChild(part.Parent.Name) ~= nil and game.Players:findFirstChild(part.Parent.Name).className == "Player" and script.Parent.BrickColor ~= BrickColor.new("Bright Blue")  then
local a = game.Players:findFirstChild(part.Parent.Name)
local b = a:FindFirstChild("leaderboard")
if b ~= nil then
local c = b:FindFirstChild("Cash");
if c ~= nil then c.Value = c.Value+10 end
script.Parent.BrickColor.new("Bright Blue")
end
end
end
end

script.Parent.Touched:connect(onHit)

Important notes:
There was errors, like leaderboard.cash = 10, this dont add, and no check of the color of the wall, roblox have a delay to remove, you can hit 2 times at the brick before this dissapear (if youre ninja...)
and the script does a.Brickcolor, this "a" is a player...

2)a)

Code:
function KillChar(player)
if type("player") == "userdata" and player.className == "Player" then
player.Character:BreakJoints()
end;
end;
KillChar(game.Workspace.Part);
KillChar(game.Workspace.Parent.Parent)
KillChar([[I like cookies]])
KillChar(13)
KillChar(game.Players.Player) -- This supposes to EXISTS


2)b)
Code:

function NoArm(player)
if type("player") == "userdata" and player.className == "Player" then
local b = player.Character
if b ~= nil and b:findFirstChild("LeftArm") ~= nil and b:findFirstChild("RightArm") ~= nil then
b:findFirstChild("LeftArm"):Remove()
b:findFirstChild("RightArm"):Remove()
end
end
end
NoArm(game.Players.Player) -- This supposes to EXISTS
NoArm(game.Players)
NoArm(game.Workspace.Part)
NoArm(1)
NoArm()



2)c)
Code:

function OnPlayerEntered(newPlayer)
if type("player") == "userdata" and player.className == "Player" then
a = Instance.new("Hint")
a.Name = "Heayaeay";
a.Text = "YOUR NAME IS " .. newPlayer.Name
a.Parent = newPlayer
end;
end

game.Players.ChildAdded:connect(OnPlayerEntered)
OnPlayerEntered("Lawl")
local b = Instance.new("Part")
b.Parent = game.Players


3)
game.Players.Name = math.random(0,1000).. "Háh" .. math.random(100,200)
local find = game:GetChildren()
for lp = 0,#find do
if find[lp] ~= nil and find[lp].className == "Players" then
find[lp].Name == "Player";
end
end


function onPlayerAdded(new)

new.CharacterAdded:connect(function() new.Character.Name = "My slave" end);
end
game.Players.ChildAdded:connect(
function(p) if type(p) == "userdata" and p.className == "Player" then onPlayerAdded(p) end end)
a = Instance.new("Part")
a.Name = "lol"
a.Parent = game.Players

Have fun
And if you gonna make a model for noobs (this ever happenz) dont forget putting great models!
Cause noobs have greats ideas. They just want to create their game without your credit ;p

View user profile

myqpalzm147XX


Good Robloxian
Good Robloxian
Wow

View user profile

Alex


Special
Special
Wow indeed.


____________________________
Evening, Guest Welcome to the Roblox Today Forums!
Hello, I am Alex. The Forum's Head Moderator.



I joined ROBLOX, December 29th, 2007!
I was one of the first to join this lovely forum, invited by Clayton himself. The memories. Ah.
Administrators have too much power, therefore my position suits me just fine!
View user profile http://www.robloxtoday.com

View previous topic View next topic Back to top  Message [Page 1 of 2]

Goto page : 1, 2  Next

Permissions in this forum:
You cannot reply to topics in this forum