Forum

> > CS2D > Scripts > Extending native functions
Forums overviewCS2D overview Scripts overviewLog in to reply

English Extending native functions

28 replies
Page
To the start Previous 1 2 Next To the start

old Re: Extending native functions

Avo
User Off Offline

Quote
Everythink is really awesome, but I have one question. Why "Love API"? I miss Ohaz as a moderator, but why "love"?

old Re: Extending native functions

Livia
User Off Offline

Quote
Do you find it too girlish? I think love is the best word to describe US.de community so why not use it.

on topic: Is there something missing in L{insert_anything_here} API?

old Re: Extending native functions

Infinite Rain
Reviewer Off Offline

Quote
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)

old Re: Extending native functions

Livia
User Off Offline

Quote
@user Infinite Rain: Very good idea. I almost forgot hudtxt!

I added a small TODO list:
https://github.com/tarjoilija/lapi/blob/master/TODO

Edit: Done.
Spoiler >
edited 1×, last 24.09.13 04:23:49 pm

old Re: Extending native functions

KimKat
GAME BANNED Off Offline

Quote
@user Livia: I like the name of Love API even if it's not the best choice of name for Lua stuff I still admire it though. Unreal Software does need some love. About the L{} thing, is there hudtxt2, sv_sound and sv_sound2? could be useful things to include if not already implemented of course, can you tell me if you have them in the Love API?

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')"

old Re: Extending native functions

Livia
User Off Offline

Quote
@user KimKat: There's plenty of things included that hasn't been documented yet. Current status is very unstable and things may change in the near future. All feedback is taken into account.

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
-- 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).

old Re: Extending native functions

Livia
User Off Offline

Quote
Sorry for bumping an old thread but Love API is not dead yet!

@user 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
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
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
local p = Player(1)

-- will trigger only once
p.onSpawn(function()
	p.shake(200)
end)
To the start Previous 1 2 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview