Forum

> > CS2D > Scripts > The Very Basic guide of CS2D Lua
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch The Very Basic guide of CS2D Lua

9 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt The Very Basic guide of CS2D Lua

sCy
User Off Offline

Zitieren
So, in this guide I teach you to make a basic script.

Items needed:
Time
Patience

So, we need to start with hook, like this:
1
addhook("spawn", "_spawn")

Now you have this one covered, we can do the function!

1
2
addhook("spawn", "_spawn")
function _spawn(id)

You may wonder why there is the ID. It is because player spawns, it takes his id what we need in script.

Also, we need to add end to the script.

Lets look of the script now:

1
2
3
addhook("spawn", "_spawn")
function _spawn(id)
end

So, this script doesnt do anything yet. But it could be made equip you weapons with parse command.
Parse allows you to enter the console command you
want to use like trigger, equip, setmaxhealth, speedmod.

1
2
3
4
addhook("spawn", "_spawn")
function _spawn(id)
	parse("equip "..id.." 30")
end

So, in spawn it equips the player with AK-47.
Thats it, basic and simple script..
But you may need some randomness to make it more fun, always spawning with AK-47 isn't that fun.
So, we use math.random to get the randomisation.

1
2
3
4
5
6
7
8
9
addhook("spawn", "_spawn")
function _spawn(id)
	local random = math.random(1, 2)
	if random == 1 then
		parse("equip "..id.." 30")
		elseif random == 2 then
		parse("equip "..id.." 32")
	end
end

Now you have the randomness between guns, so you can now possibly end with
an AK-47 or M4A1. You can also use the math.random in equip as well, like this:

1
2
3
4
addhook("spawn", "_spawn")
function _spawn(id) 
	parse("equip "..id.." "..math.random(1,89))
end

That should equip you with random item.

You may want that only CT get certain equips and Tr another. Then you can use this: player(id, "team")

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
addhook("spawn", "_spawn")
function _spawn(id)
	local random = math.random(1, 2)
	if player(id, "team") == 1 then
		if random == 1 then
			parse("equip "..id.." 30")
		elseif random == 2 then
			parse("equip "..id.." 10")
		end
	elseif player(id, "team") == 2 then
		if random == 1 then
			parse("equip "..id.." 32")
		elseif random == 2 then
			parse("equip "..id.." 11")
		end
	end
end
See? Now if you are in TR team you have possibility to get M3 or AK-47, and if your in CT you have possibility
to get XM1014 or AK-47.

I hope you got the spark to start coding

Also, take a cookie for reading.

Edit: Changed name to be better, and more info.
1× editiert, zuletzt 15.02.12 19:11:31

alt Re: The Very Basic guide of CS2D Lua

DannyDeth
User Off Offline

Zitieren
"Those who know nothing, teach."

Never has this been more true. Don't try to teach people using a hook, this is NOT a part of Lua, but rather a part of CS2D's extra bits and pieces.

alt Re: The Very Basic guide of CS2D Lua

Mechanolith
User Off Offline

Zitieren
user Time hat geschrieben
Left 4 n00b hat geschrieben
Items needed:
Time

damn

I see what you did there.

Well, if it's The very basic guide of lua it shouldn't be related to CS2D but to LUA itself, without hooks and stuff... am i right?

alt Re: The Very Basic guide of CS2D Lua

EngiN33R
Moderator Off Offline

Zitieren
Indeed. This is a strictly CS2D beginner's guide, not a pure Lua one, which was, like many before it, written by a person who has just started himself.

It's arguably fine for the very beginning. Don't take me wrong, but as you probably understand, there are a lot more things to teach, and even this can be done more efficient with some more skill. Nevertheless, I like to see people having the will and initiative to help others, but in order to teach you need to learn much more yourself first.

alt Re: The Very Basic guide of CS2D Lua

DarkLight66
User Off Offline

Zitieren
@user Mechanolith: Yes, as danny and ketamire said, this is just a basic guide of CS2D scripting, rater than lua scripting itself. Also, you are not explaining what math.random() or cs2d cmd parse does, even if their functions may be obvious, a guy with no knowledge about how cs2d or lua works may have a hard time understanding it.

alt Re: The Very Basic guide of CS2D Lua

Flacko
User Off Offline

Zitieren
The Very Basic Guide of Lua - so basic it doesn't explain shit!

You're just copypasting code. A newbie wouldn't understand crap.

It's ok to show some code and tell what it does. But you should also explain why did you use it and how does it work.
1× editiert, zuletzt 15.02.12 19:03:26
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht