English [GUIDE] How to script

38 replies
Goto Page
To the start Previous 1 2 Next To the start
01.05.14 04:42:43 pm
Up
Ortimh
User
Offline Off
@user Avo:
Counter-Strike 2D has written:
You wrote a CS2D tutorial which could help others? We will publish it!

user Starkkz should contact user DC to add link to this post on Counter-Strike 2D website in Tutorials section.
I'm awesome ... and I really cookies
02.05.14 04:44:46 am
Up
MikuAuahDark
User
Offline Off
user Ortimh has written:
Code:
1
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

You can use not keyword instead
Code:
1
something=not something

Which set something to false if something is true and vice versa
Hello? Are you there, Tae Hanazono?
26.05.14 08:29:06 am
Up
Raaj Nadar
User
Offline Off
user Ortimh has written:
@user Raaj Nadar:
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

Also for country detector thingy, try to learn from file cs2d Starkkz's Admin Script (146).


Thanks Helped me a lot for my script....
(Y)
27.06.14 08:58:07 pm
Up
Hellcat
GAME BANNED
Offline Off
Good tutorial for newbies!
11.07.14 10:33:05 am
Up
-DIE Wolf-
User
Offline Off
Thank you! This is so useful.
IMG:https://www.gametracker.com/images/game_icons64/csgo.png
21.07.14 02:50:20 pm
Up
Rafael20x
User
Offline Off
I was looking forward to learn lua for some time, turns out it isn't much different from matlab.
26.07.14 07:45:32 pm
Up
JeeewNazi
User
Offline Off
Great. thx for sharing.
But still i dont understand the array.
26.07.14 08:00:42 pm
Up
Starkkz
Moderator
Offline Off
@user JeeewNazi: 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)
Code:
1
Variable = 7

You can later access that variable with Variable or either _G.Variable.
lol
26.07.14 09:06:36 pm
Up
VADemon
User
Offline Off
@user JeeewNazi: In addition what user Starkkz said:
As you know cs2d lua cmd addhook is a global Lua function. You call it by using
Code:
1
addhook("example", "myExampleFunction")
and because it's a global function you can also access the same function by using the table for ALL global variables _G:
Code:
1
_G.addhook("example", "myExampleFunction")
16.05.15 09:21:58 pm
Up
Starkkz
Moderator
Offline Off
If anyone is interested, I just finished the fourth cathegory from this tutorial.
lol
22.03.16 03:07:46 am
Up
wazzup
User
Offline Off
Thx and very good
Can u make
17.05.16 09:59:52 am
Up
h2o1
GAME BANNED
Offline Off
hi guys , how can i make lua that avoid remove building after a player left the game ??? pls help me
_-KTL-_
17.05.16 10:53:18 am
Up
Yates
Reviewer
Offline Off
@user h2o1: That's a server setting. cs2d cmd mp_killbuildings
19.05.16 11:38:42 am
Up
h2o1
GAME BANNED
Offline Off
@user Yates: thanks a lot √
_-KTL-_
19.08.16 12:44:03 am
Up
Task-Force
BANNED
Offline Off
its pretty hard to understand
26.03.18 10:04:00 am
Up
RogerIT
User
Offline Off
Looks great, thank you for this tutorial.
04.04.18 06:34:03 pm
Up
M3_Quick
User
Offline Off
oh this tutorial clarified many of my doubts about lua, thank you very much for your good work.
IMG:https://i.imgur.com/DCz9Dko.png
08.07.18 01:29:36 pm
Up
Quattro
User
Offline Off
Hmm in this tutorial it says to delete table you do like this:

Code:
1
2
table = {1,2,3,4,5,6,7,8,9,10}
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
table = {1,2,3,4,5,6,7,8,9,10}
for i in pairs(table) do
     table[i] = nil
end
08.07.18 05:19:59 pm
Up
Starkkz
Moderator
Offline Off
@user 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.
lol
To the start Previous 1 2 Next To the start