[GUIDE] How to script
43 replies @
Avo:
Starkkz should contact
DC to add link to this post on Counter-Strike 2D website in Tutorials section.

Counter-Strike 2D has written:
You wrote a CS2D tutorial which could help others? We will publish it!


I'm awesome ... and I really like cookies.

Code:
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
if (something) then
-- Change "something" variable value to false
something = false
-- If otherwise (false)
else
-- Change "something" variable value to true
something = true
end
-- Change "something" variable value to false
something = false
-- If otherwise (false)
else
-- Change "something" variable value to true
something = true
end
You can use not keyword instead
Code:
1
something=not something
Which set something to false if something is true and vice versa



@
Raaj Nadar:
Also for country detector thingy, try to learn from
Starkkz's Admin Script (146).

Code:
-- Create random new variable which has false value
something = false
-- Add new "say" hook which triggered when player say something to "sayhook" function
addhook ("say", "sayhook")
-- Create new function for "say" hook
function sayhook (id, message)
-- Check if "message" is "!something"
if (message == "!something") then
-- Check if "something" variable is true
if (something) then
-- Change "something" variable value to false
something = false
-- If otherwise (false)
else
-- Change "something" variable value to true
something = true
end
end
end
something = false
-- Add new "say" hook which triggered when player say something to "sayhook" function
addhook ("say", "sayhook")
-- Create new function for "say" hook
function sayhook (id, message)
-- Check if "message" is "!something"
if (message == "!something") then
-- Check if "something" variable is true
if (something) then
-- Change "something" variable value to false
something = false
-- If otherwise (false)
else
-- Change "something" variable value to true
something = true
end
end
end
Also for country detector thingy, try to learn from


Thanks Helped me a lot for my script....

(Y)
@
Ajmin: The arrays are the same as tables, it's like a list where you can store variables.
_G is a table. It contains all the memory of the current Lua state (the variables)
You can later access that variable with Variable or either _G.Variable.

_G is a table. It contains all the memory of the current Lua state (the variables)
Code:
1
Variable = 7
You can later access that variable with Variable or either _G.Variable.
@
Ajmin: In addition what
Starkkz said:
As you know
addhook is a global Lua function. You call it by using


As you know

Code:
and because it's a global function you can also access the same function by using the table for ALL global variables _G:1
addhook("example", "myExampleFunction")
Code:
1
_G.addhook("example", "myExampleFunction")
hi guys , how can i make lua that avoid remove building after a player left the game ??? pls help me

_-KTL-_
Hmm in this tutorial it says to delete table you do like this:
But this way you don't delete the table, it is left as garbage. If you care about optimization you have to delete every value from the table to fully delete it like this:
Code:
1
2
2
table = {1,2,3,4,5,6,7,8,9,10}
table = nil
table = nil
But this way you don't delete the table, it is left as garbage. If you care about optimization you have to delete every value from the table to fully delete it like this:
Code:
1
2
3
4
2
3
4
table = {1,2,3,4,5,6,7,8,9,10}
for i in pairs(table) do
table[i] = nil
end
for i in pairs(table) do
table[i] = nil
end
Best match: https://www.youtube.com/watch?v=je2Q2XR2Zys
@
Quattro: new comers may not know what garbage collection is, I prefer not to add terms that they're probably going to forget through the tutorial. They will figure out themselfes when they're more advanced in the topic.
