Get the New Tools
#1
Hi!
If you haven't gotten the new CubeScript tools, do so at your next convenience! :D It enables many other scripts, and the ease of coding new ones.
If you downloaded it between when I first mentioned it and now, you'll want this update (I fixed a bug where add2conloop spams your console if you use it in a certain way).

The Mighty CubeScript Toolbox!
Thanks given by:
#2
I beg you, include the new cubescript math operators in there.
Thanks given by:
#3
I can't get it..... Is it some kind of framework for CubeScript?
Thanks given by:
#4
Basically yes.
Thanks given by:
#5
(16 Dec 10, 01:59PM)Gibstick Wrote: I beg you, include the new cubescript math operators in there.

[shameful]I don't have the exp you updated, or the fractions script you and Ronald were working on.[/shameful]
PM them to me or post them here and I'll speedy make another update!
Thanks given by:
#6
(16 Dec 10, 02:27PM)Andrez Wrote: I can't get it..... Is it some kind of framework for CubeScript?

It simplifies some things. Look at the scripts thread and you'll see a big script Bukz made that V-Man simplified into around three lines :)
Thanks given by:
#7
roundf = [
if (>= (+f ($arg1) 0.5) (+ ($arg1) 1.0)) [
(+ ($arg1) 1)] [
(+ ($arg1) 0)]

//Exponent script "exp 5 2" = 5^2
alias powerloop [
    (alias product (*f $base $product));
    (alias power (+f $power 1));
    (if (<f $power $pow) [powerloop] [result $product])]

alias exp [
(alias product 1);
(alias power 0);
(alias base $arg1);
if (<f $arg2 0) [alias pow (*f $arg2 -1); negexp = 1] [alias pow $arg2; negexp = 0];
if (!= $negexp 1) [powerloop base pow] [(divf 1 (powerloop base pow;))]
]
]
Thanks given by:
#8
^great post, everyone will want that... its so well described :-)
Thanks given by:
#9
If you had an inkling of cubescript knowledge you could use those like an automaton.\:D
roundf is an operator that takes one operands. Like always, it will be on the right. Use
(roundf 3.5) in your scripts, or if you want to test in-game just use
/echo (roundf number)

Exp(onent) is the same, except it takes two operands. Use (exp 2 5) or
/echo (exp 2 -5)

I kinda left the describing part to V-Man.
Thanks given by:
#10
@DES|V-Man: Thanks a lot for sharing this, its really nice :)

But I´ve got a problem, when trying to use add2conloop:

I put this rule in my autoexec.cfg:
add2conloop [
if_conline_has "you fragged teammate" [sleep 2000 [voicecom sorry "Sorry"]] []
]

its working well, but everytime I start/close the AC-Client, there is a new line appearing in my saved.cfg, like this:
alias "if_conline_list" [
if_conline_has "you fragged teammate" [sleep 2000 [voicecom sorry "Sorry"]] []
;
if_conline_has "you fragged teammate" [sleep 2000 [voicecom sorry "Sorry"]] []
;
if_conline_has "you fragged teammate" [sleep 2000 [voicecom sorry "Sorry"]] []
]

So my saved.cfg would get with the time always bigger... I dont think its so good.

Does someone have any idea, how to resolve this problem?

Thanks
Thanks given by:
#11
sputnik: you should probably type it in-game, just once. Autoexec is executed each time AC starts, so it will be added over and over and over.
Thanks given by:
#12
:/
It shouldn't now.
I updated "addcheck" to make it (really, this time) check whether the given string is already in the alias before adding it in. You should be able to either put it in autoexec.cfg or type it in-game and both will only add it once.
Do you have the tools.cfg that says
alias addcheck [if (strstr (getalias $arg1) $arg2) [] [add2alias $arg1 $arg2]]

instead of
alias addcheck [if (strstr $arg1 $arg2) [] [add2alias $arg1 $arg2]]
?
Thanks given by:
#13
@DES|V-Man&Gibstick: Thank you for your help :)

(17 Dec 10, 04:40PM)DES|V-Man Wrote: I updated "addcheck"
where is the updated file? I just download tools.zip again from http://www.akimbo.in/files/index.php?act=view&id=723 but it seems to be the same file as before (?)


alias addcheck [if (strstr (getalias $arg1) $arg2) [] [add2alias $arg1 $arg2]]
This is the Version i´ve got. I just tried to paste the other code-line instead of this, but its still the same: multiple entries for the alias "if_conline_list"..

I think I will try to type it in-game. EDIT: Done, now its working! thx
Thanks given by:
#14
Good to hear, I was kind of freaking out for a while... XD

Edit: LOL I figured it out: stats.cfg defines addcheck in the incorrect way. To fix it, change "addcheck" in stats.cfg to the correct definition. I'll fix that in the next release of the stats script. :D
Thanks given by:
#15
i would suggest the use of this one as a power script
//made by Kirin (iterative pow algorithm, exponents are forced into integers)
alias pow [
alias pow_exp $arg2
alias pow_base $arg1
if (= $pow_exp 0) [result 1] [
if (< $pow_exp 0) [*= pow_exp -1] []
-= pow_exp 1
loop i $pow_exp [*=f pow_base $arg1]
if (> $arg2 0) [result $pow_base] [result (divf 1 $pow_base)]
]
]
REASONS:
this one i made is iterative and not recursive so it's MUCH more efficient on the memory use and on the stack, plus it uses the new AC operators and it's code is shorter and it doesnt need two functions just one.
Thanks given by:
#16
Ah!
Great use of the new *= function. I believe I'll use this one.
Thanks given by:
#17
Hi again, I've got another Question :o

I´m trying to realise something like this:

// PSEUDOCODE:

if_conline_has "you (fragged || gibbed) teammate" [ ...  

// OR (better)

if_conline_has "you [a-z]* teammate" [ ...

// I hope its understandably..

but I don´t know how to make it with Cubescript-syntax. I already look in the AC-Reference, but I only find a logical OR and nothing about string-manipulation or regular expressions.

I know I could realise this with 2 rules, but I first wanted to try it that way :)

Thanks in advance
Thanks given by:
#18
if_conline_has "you fragged teammate" [] [
if_conline_has "you gibbed teammate" [] []]
etc.
As for the other method, I agree that wildcard would be a useful tool for CubeScript, but as it stands you'll have to go the other way, using exclusions instead:
if_conline_has "you" but_not "were" [
if_conline_has "teammate" [say HAHA SUCKA] [] []
Oh, and be sure to add it in using add2conloop!
Thanks given by:
#19
Alright, thank you very much for your help.

I think, in this case, the first method should be the better one, since it only have 2 comparisons per loop instead of 3 for the second method.

But if someday the new kill messages are really introduced, I have to rethink about that ;)

EDIT btw: sorry for OT
Thanks given by:
#20
HTH!
Quite on-topic, honestly. :D



Merry Christmas, everyone!
Since you've been good this year, Santa Claus has put a shiny new tools.cfg under your Christmas tree! :D This update now additionally has:
pow -- Performs an exponential calculation
roundf -- Rounds a given number to the nearest integer
average -- Averages a given list of numbers
add2menu -- Appends given code to the end of a given menu
add2mainmenu -- Appends given code to the end of the main menu
Thanks given by:
#21
***UPDATE***
I apologize to anyone who was quick enough to get this last update (now 17 hours old), it's riddled with bugs. Please be sure to download the new version to stay up to date! The new version of stats.cfg depends on it! :D
In addition to the above new features, I've modified the way "checkinit" and "initialize" work -- they now take two arguments instead of one, so you can specify what the initialized aliases contain by default. Check the documentation.
I've also realized that "if_conline_has" cannot nest as I previously thought. Sorry. It causes problems when attempted, on a scale proportional to the complexity of the nesting. XD
Thanks given by:
#22
nice script Bukz&V-Man :) keep up!!!
one small suggestion: when possible replace the special characters for colors with (c N) syntax
it's easier to read :D

one suggestion for the devs: add a on_conline_update event, so this kind of scripts will get a huge performance boost, they are checking every frame for updates using strstr a consistent number of times, with such a alias the check would happen only when necessary.
when i get a good slice of time i'll make&send the patch :D

EDIT.
into console.cpp near line 108 (in SVN) replace the old conoutf with this one
void conoutf(const char *s, ...)
{
    defvformatstring(sf, s, s);
    clientlogf("%s", sf);
    con.addline(sf);
    delete[] conline; conline=newstring(sf);
    // execute onconline event
    const char *onconline = getalias("onconline");
    if(onconline && onconline[0]) { addsleep(0, onconline); }
}
and u'll have a onconline event to be used like this:
onconline = [
all checks... blah blah
]
Thanks given by:
#23
I agree, the form-feed special character is annoying...
But I'm sure you meant to post this in the stats thread. :-P
Thanks given by:
#24
New update to tools.cfg today!
This update adds the promising "curplayers" command by Bukz -- with modifications made by myself and Wifey. ;-)
Thanks given by:
#25
Does add2menu not work within loops? For instance, trying to get a menu to dynamically list all player names on the server whenever it's opened:
alias genkickmenu [
    loop a (curplayers) [
        add2menu nkick [menuitemvar [concat (findpn $a)]]
    ]
    add2menu nkick [
        menuitem [] -1
        menuitem [        OK] [closemenu nkick]
    ]
]

newmenu nkick
menuinit [genkickmenu]

Only 1 name ever shows up, cn 0. :(

Edit:

NVM, what that is trying to do is currently not possible. Thanks for clearing it up V-Man. :P
Thanks given by:
#26
By way of explanation:
1) "add2menu" merely adds to the end of a menu, meaning every time it's used, a new line is added to the given menu.
2) When the menu above is generated, you're the only person in the "server."
3) If the contents of the menu are to be dynamic (and look good), we will need to ability to delete menus so that we can rebuild them, similar to the way binds and aliases are abused these days.
Thanks given by:
#27
(19 Jan 11, 03:48AM)DES|V-Man Wrote: By way of explanation:
1) "add2menu" merely adds to the end of a menu, meaning every time it's used, a new line is added to the given menu.
2) When the menu above is generated, you're the only person in the "server."
3) If the contents of the menu are to be dynamic (and look good), we will need to ability to delete menus so that we can rebuild them, similar to the way binds and aliases are abused these days.
Abused or used heh :D

* eftertanke calls a vote: Add dynamic config (stored in RAM or summit') support..
Thanks given by:
#28
LOL, well, if you look at the way tools like add2bind or add2alias work, they basically re-define a bind or alias completely. The fact that it happens to be what it was before, plus a given addition, is what makes it convenient. It's likely that this wasn't one of the originally intended uses for these commands, so consider it a workaround.

Explain your idea about dynamic config?
Thanks given by:
#29
(19 Jan 11, 04:09AM)DES|V-Man Wrote: LOL, well, if you look at the way tools like add2bind or add2alias work, they basically re-define a bind or alias completely. The fact that it happens to be what it was before, plus a given addition, is what makes it convenient. It's likely that this wasn't one of the originally intended uses for these commands, so consider it a workaround.

Explain your idea about dynamic config?

Your machine uses RAM to store information on a temporary basis, know? It would be nice to see an implementation that stores configuration options temporarily and discards them.

Servers do that for demos, and that's much more data right?

EDIT: Woops.
Thanks given by:
#30
Technically, the configuration is in the RAM when you load the game -- at game start, each individual configuration setting is plugged in as the game loads.
If you wanted to make the saved.cfg temprary, I'm sure you could add a line in assaultcube.bat that renames saved.cfg and starts a new one, giving the effect you're describing.
Thanks given by: