Forum
CS2D Scripts Extending native functionsExtending native functions
28 replieson topic: Is there something missing in L{insert_anything_here} API?
Livia has written
I think love is the best word to describe US.de community so why not use it.
Lol.
OT: You could also make every copy of a cosnole command into a function, smth like:
Console:hudtxt2(blah)
I added a small TODO list:
https://github.com/tarjoilija/lapi/blob/master/TODO
Edit: Done.
edited 1×, last 24.09.13 04:23:49 pm
Maybe shortening stuff to save memory or lines of code would be desirable, as it would affect the load times of the Lua scripts. Kind of user-friendly. The JQuery library also compress their code to save memory and stuff like such. Maybe you could do a similar thing, by creating a minified version and a standard version. It would be much appreciated.
lua "function P(o)parse(o)end" lua "P('sv_sound2 1 wc3tft_2d/entangleroots.ogg')"
There's no such thing as hudtxt2 in Love API. It's just Hudtxt(ply, id) where ply is a player object. Passing zero as a first parameter would cause the script to use regular hudtxt instead of player specific hudtxt2. Shortcut for this is ply:hudtxt(id).
Let me give you an example of a very simple hudtxt:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
-- called when player joins the server Hook('join', function(ply) -- create hudtxt for current player with id of 1 local txt = ply:hudtxt(1) -- e.g. Welcome, Livia local message = Color(20, 220, 20) .. "Welcome, " .. ply.name -- show hudtxt in player's screen at bottom left corner txt:show(message, 10, 420, 0) -- after 5 seconds (5000 milliseconds) Timer(5000, function() -- hide the message txt:hide() end) end)
I don't think compressing is necessary. It would only make debugging very hard (it's already).
@ MikuAuahDark: Timers are also objects that you can destroy with remove() method. I'm sorry but the documentation is very poor.
1
2
3
4
5
2
3
4
5
local my_timer = Timer(2000, function() msg("hello world") end) my_timer:remove()
I also added a simple way of iterating playerobjects:
1
2
3
4
2
3
4
Player.each_living(function(p) p.health = 100 p:msg("healed") end)
I'll probably also add a simple plugin which let's you create one-tigger-only hooks like:
1
2
3
4
5
6
2
3
4
5
6
local p = Player(1) -- will trigger only once p.onSpawn(function() 	p.shake(200) end)