Forum

> > CS2D > Scripts > [GUIDE] How to script
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch [GUIDE] How to script

45 Antworten
Seite
Zum Anfang Vorherige 1 2 3 Nächste Zum Anfang

alt Re: [GUIDE] How to script

MikuAuahDark
User Off Offline

Zitieren
user Dousea hat geschrieben
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

alt Re: [GUIDE] How to script

Raaj Nadar
User Off Offline

Zitieren
user Dousea hat geschrieben
@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 Datei existiert nicht (12800).


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

alt Re: [GUIDE] How to script

Starkkz
Moderator Off Offline

Zitieren
@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.

alt Re: [GUIDE] How to script

VADemon
User Off Offline

Zitieren
@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")

alt Re: [GUIDE] How to script

h2o1
GAME BANNED Off Offline

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

alt Re: [GUIDE] How to script

Quattro
GAME BANNED Off Offline

Zitieren
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

alt Re: [GUIDE] How to script

Starkkz
Moderator Off Offline

Zitieren
@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.
Zum Anfang Vorherige 1 2 3 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht