Forum

> > CS2D > Scripts > [GUIDE] How to script
Forums overviewCS2D overview Scripts overviewLog in to reply

English [GUIDE] How to script

45 replies
Page
To the start Previous 1 2 3 Next To the start

old Re: [GUIDE] How to script

MikuAuahDark
User Off Offline

Quote
user Dousea has written
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
1
something=not something
Which set something to false if something is true and vice versa

old Re: [GUIDE] How to script

Raaj Nadar
User Off Offline

Quote
user Dousea has written
@user Raaj Nadar:
-- 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 File does not exist (12800).


Thanks Helped me a lot for my script....
(Y)

old Re: [GUIDE] How to script

Starkkz
Moderator Off Offline

Quote
@user 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)
1
Variable = 7
You can later access that variable with Variable or either _G.Variable.

old Re: [GUIDE] How to script

VADemon
User Off Offline

Quote
@user Ajmin: In addition what user Starkkz said:
As you know cs2d lua cmd addhook is a global Lua function. You call it by using
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:
1
_G.addhook("example", "myExampleFunction")

old Re: [GUIDE] How to script

h2o1
GAME BANNED Off Offline

Quote
hi guys , how can i make lua that avoid remove building after a player left the game ??? pls help me

old Re: [GUIDE] How to script

Quattro
GAME BANNED Off Offline

Quote
Hmm in this tutorial it says to delete table you do like this:

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:

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

old Re: [GUIDE] How to script

Starkkz
Moderator Off Offline

Quote
@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.
To the start Previous 1 2 3 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview