Author Topic: Any way to write a script like PHP/Javascript  (Read 9747 times)

Paradox

  • Posts: 2612
  • Turrets: +253/-250
    • Paradox Designs
Any way to write a script like PHP/Javascript
« on: July 14, 2006, 01:13:22 am »
Ok, i am good at binds and such, but i havnt figured out a way to write a dynamic bind. What i mean is a bind where it takes a variable (integer), exicutes it, then incriments the variable (as a integer) for the next run. What i would plan to do this with is make a script that renames  unnameds. For example. Unnamed player connects. I hit the bind, it renames unnamed noob1, and increments 1 to 2 for the next time. Another unnamed connects, i hit the bind, and he becomes noob2, and the variable is increased.

∧OMG ENTROPY∧

[EVIL]Unknown

  • Posts: 263
  • Turrets: +1/-1
    • http://www.evil-clan.com
Any way to write a script like PHP/Javascript
« Reply #1 on: July 14, 2006, 01:46:48 am »
good idea..idk how to do this but one would have to make sure it carries over to next time to connect so it doesnt reset to 1 again
url=http://userbars.org][/url]


vcxzet

  • Guest
Any way to write a script like PHP/Javascript
« Reply #2 on: July 14, 2006, 02:13:09 am »
just the crc32 of their ip  :roll:

Paradox

  • Posts: 2612
  • Turrets: +253/-250
    • Paradox Designs
Any way to write a script like PHP/Javascript
« Reply #3 on: July 14, 2006, 04:10:07 am »
No, i want a soloution that works any time, particularly the ability to use Booleans like IF, OR, AND, NOT, NOR, and the ability to use loops, and increments.

∧OMG ENTROPY∧

rasz_pl

  • Guest
Any way to write a script like PHP/Javascript
« Reply #4 on: July 14, 2006, 05:44:48 am »
that would need an awfull lot ofthings to ve variables exposed to this script engine

Teiman

  • Posts: 286
  • Turrets: +0/-0
Re: Any way to write a script like PHP/Javascript
« Reply #5 on: July 14, 2006, 08:40:46 am »
Quote from: "Paradox"
Ok, i am good at binds and such, but i havnt figured out a way to write a dynamic bind. What i mean is a bind where it takes a variable (integer), exicutes it, then incriments the variable (as a integer) for the next run. What i would plan to do this with is make a script that renames  unnameds. For example. Unnamed player connects. I hit the bind, it renames unnamed noob1, and increments 1 to 2 for the next time. Another unnamed connects, i hit the bind, and he becomes noob2, and the variable is increased.



option a) Add a javascript engine to quake. Spidermonkey seems easy to embed. Then you need to hardcoded a few functions to able javascript interact with cvars and ccommands.

option b) Enhance the console sintax with conditionals. Already done with quakeism code at quakeworld engines.

problem a) People will start using this for evil stuff.
problem b) etc

chompers

  • Posts: 224
  • Turrets: +4/-0
Any way to write a script like PHP/Javascript
« Reply #6 on: July 15, 2006, 04:45:48 am »
Yeah, there are good reasons you can't have conditional logic and stuff in your bind configs, the details are a bit hazy now, but I recall the whole reasoning behind the clunky vstr syntax (as opposed to quake 1 style aliases) was to reduce the abuse potential of bind scripts.

You CAN do the incremental thing you're talking about though, for example here is a script which cycles up or down through 20 or so gamma values:

Code: [Select]

// gamma
set b05 "r_gamma 0.5; echo gamma 0.5; bind KP_PLUS vstr b06; bind KP_MINUS vstr b05"
set b06 "r_gamma 0.6; echo gamma 0.6; bind KP_PLUS vstr b07; bind KP_MINUS vstr b05"
set b07 "r_gamma 0.7; echo gamma 0.7; bind KP_PLUS vstr b08; bind KP_MINUS vstr b06"
set b08 "r_gamma 0.8; echo gamma 0.8; bind KP_PLUS vstr b09; bind KP_MINUS vstr b07"
set b09 "r_gamma 0.9; echo gamma 0.9; bind KP_PLUS vstr b10; bind KP_MINUS vstr b08"
set b10 "r_gamma 1.0; echo gamma 1.0; bind KP_PLUS vstr b11; bind KP_MINUS vstr b09"
set b11 "r_gamma 1.1; echo gamma 1.1; bind KP_PLUS vstr b12; bind KP_MINUS vstr b10"
set b12 "r_gamma 1.2; echo gamma 1.2; bind KP_PLUS vstr b13; bind KP_MINUS vstr b11"
set b13 "r_gamma 1.3; echo gamma 1.3; bind KP_PLUS vstr b14; bind KP_MINUS vstr b12"
set b14 "r_gamma 1.4; echo gamma 1.4; bind KP_PLUS vstr b15; bind KP_MINUS vstr b13"
set b15 "r_gamma 1.5; echo gamma 1.5; bind KP_PLUS vstr b16; bind KP_MINUS vstr b14"
set b16 "r_gamma 1.6; echo gamma 1.6; bind KP_PLUS vstr b17; bind KP_MINUS vstr b15"
set b17 "r_gamma 1.7; echo gamma 1.7; bind KP_PLUS vstr b18; bind KP_MINUS vstr b16"
set b18 "r_gamma 1.8; echo gamma 1.8; bind KP_PLUS vstr b19; bind KP_MINUS vstr b17"
set b19 "r_gamma 1.9; echo gamma 1.9; bind KP_PLUS vstr b20; bind KP_MINUS vstr b18"
set b20 "r_gamma 2.0; echo gamma 2.0; bind KP_PLUS vstr b21; bind KP_MINUS vstr b19"
set b21 "r_gamma 2.1; echo gamma 2.1; bind KP_PLUS vstr b22; bind KP_MINUS vstr b20"
set b22 "r_gamma 2.2; echo gamma 2.2; bind KP_PLUS vstr b23; bind KP_MINUS vstr b21"
set b23 "r_gamma 2.3; echo gamma 2.3; bind KP_PLUS vstr b24; bind KP_MINUS vstr b22"
set b24 "r_gamma 2.4; echo gamma 2.4; bind KP_PLUS vstr b25; bind KP_MINUS vstr b23"
set b25 "r_gamma 2.5; echo gamma 2.5; bind KP_PLUS vstr b25; bind KP_MINUS vstr b24"
//defaults to 1.6
vstr b16


What you want is simpler, I think:
Code: [Select]

set un1 "say !rename UnnamedPlayer noob1; bind F7 vstr un2"
set un2 "say !rename UnnamedPlayer noob2; bind F7 vstr un3"
set un3 "say !rename UnnamedPlayer noob3; bind F7 vstr un4"
set un4 "say !rename UnnamedPlayer noob4; bind F7 vstr un5"
set un5 "say !rename UnnamedPlayer noob5; bind F7 vstr un1"
bind F7 vstr un1

zeta

  • Posts: 200
  • Turrets: +2/-0
Any way to write a script like PHP/Javascript
« Reply #7 on: July 15, 2006, 04:51:25 am »
lol its so funny, there is so many unamed noobs, its like havent u ever played a Q3 engine game before?????
img]http://img50.imageshack.us/img50/6568/mysig0va.jpg[/img]

David

  • Spam Killer
  • *
  • Posts: 3543
  • Turrets: +249/-273
Any way to write a script like PHP/Javascript
« Reply #8 on: August 06, 2006, 08:08:26 pm »
or get the server owner to make a thing to puck up the stdin and stdout of the server, and everytime it see's unnamed player connected, it can send the rename command.
Any maps not in the MG repo?  Email me or come to irc.freenode.net/#mg.
--
My words are mine and mine alone.  I can't speak for anyone else, and there is no one who can speak for me.  If I ever make a post that gives the opinions or positions of other users or groups, then they will be clearly labeled as such.
I'm disappointed that people's past actions have forced me to state what should be obvious.
I am not a dev.  Nothing I say counts for anything.

kevlarman

  • Posts: 2737
  • Turrets: +291/-295
Re: Any way to write a script like PHP/Javascript
« Reply #9 on: August 06, 2006, 10:01:55 pm »
Quote from: "Teiman"

problem a) People will start using this for evil stuff.
problem b) etc

he's right, conditional branching was left out of the scripting system for a reason, on the other hand, if the server will accept input from stdin, then it is trivial to write a bash/perl/python/whatever script to listen to the server's stdout and rename unnamedplayers when it sees them. the only problem with this solution is that it deprives people of the pleasure of seeing someone renamed to something like DancesWithCampers.
Quote from: Asvarox link=topic=8622.msg169333#msg169333
Ok let's plan it out. Asva, you are nub, go sit on rets, I will build, you two go feed like hell, you go pwn their asses, and everyone else camp in the hallway, roger?
the dretch bites.
-----
|..d| #
|.@.-##
-----

David

  • Spam Killer
  • *
  • Posts: 3543
  • Turrets: +249/-273
Re: Any way to write a script like PHP/Javascript
« Reply #10 on: August 06, 2006, 10:40:53 pm »
Quote from: "kevlarman"
Quote from: "Teiman"
the only problem with this solution is that it deprives people of the pleasure of seeing someone renamed to something like DancesWithCampers.


thay could have a list of names :)
Any maps not in the MG repo?  Email me or come to irc.freenode.net/#mg.
--
My words are mine and mine alone.  I can't speak for anyone else, and there is no one who can speak for me.  If I ever make a post that gives the opinions or positions of other users or groups, then they will be clearly labeled as such.
I'm disappointed that people's past actions have forced me to state what should be obvious.
I am not a dev.  Nothing I say counts for anything.

kevlarman

  • Posts: 2737
  • Turrets: +291/-295
Re: Any way to write a script like PHP/Javascript
« Reply #11 on: August 06, 2006, 10:45:43 pm »
Quote from: "David"
thay could have a list of names :)
you're absolutely right, i should totally do that, anyone know if the server will take commands from stdin?
Quote from: Asvarox link=topic=8622.msg169333#msg169333
Ok let's plan it out. Asva, you are nub, go sit on rets, I will build, you two go feed like hell, you go pwn their asses, and everyone else camp in the hallway, roger?
the dretch bites.
-----
|..d| #
|.@.-##
-----

next_ghost

  • Posts: 892
  • Turrets: +3/-6
Re: Any way to write a script like PHP/Javascript
« Reply #12 on: August 07, 2006, 03:11:22 pm »
Quote from: "kevlarman"
you're absolutely right, i should totally do that, anyone know if the server will take commands from stdin?


Can you type commands when you run tremded? Of course you can. Those commands come from stdin :D
If my answer to your problem doesn't seem helpful, it means I won't help you until you show some effort to fix your problem yourself!
1.2.0 release's been delayed for 5:48:00 already because of stupid questions.

kevlarman

  • Posts: 2737
  • Turrets: +291/-295
Re: Any way to write a script like PHP/Javascript
« Reply #13 on: August 07, 2006, 05:00:05 pm »
Quote from: "next_ghost"
Quote from: "kevlarman"
you're absolutely right, i should totally do that, anyone know if the server will take commands from stdin?


Can you type commands when you run tremded? Of course you can. Those commands come from stdin :D
for some reason my tremulous install doesn't have tremded.x86, so i couldn't test it.
Quote from: Asvarox link=topic=8622.msg169333#msg169333
Ok let's plan it out. Asva, you are nub, go sit on rets, I will build, you two go feed like hell, you go pwn their asses, and everyone else camp in the hallway, roger?
the dretch bites.
-----
|..d| #
|.@.-##
-----

AssciateLinuxProgr-[SOUP]

  • Posts: 20
  • Turrets: +0/-0
Any way to write a script like PHP/Javascript
« Reply #14 on: August 07, 2006, 09:38:27 pm »
OK help i do here.

First daclare variables in java c#:

DECLARED OPEN SOURCE CODEs (YOU CAN USE)

sat class.varable mod_medistation;
if class.varable != null;
sat integar 1;
if integar = 1;
than {
        print.screen mod_medistation /say "YOU ARE VERY DAMAGED I HEAL YOU"
        print.screen player /say "THANKS YOU FOR WOUND FIX MEDISTATION"      
}
elseif
      {
print.screen player /say "I NO HEALED NOW"
}
endif

OK LET KNOW IF PROBLAM HAPPANS

Paradox

  • Posts: 2612
  • Turrets: +253/-250
    • Paradox Designs
Any way to write a script like PHP/Javascript
« Reply #15 on: August 07, 2006, 10:35:04 pm »
Does that work for trem?

∧OMG ENTROPY∧

AssciateLinuxProgr-[SOUP]

  • Posts: 20
  • Turrets: +0/-0
Any way to write a script like PHP/Javascript
« Reply #16 on: August 07, 2006, 10:53:47 pm »
Quote from: "Paradox"
Does that work for trem?


Ja of coarse it will I am programmar

phaedrus

  • Posts: 104
  • Turrets: +1/-1
Re: Any way to write a script like PHP/Javascript
« Reply #17 on: August 07, 2006, 10:56:59 pm »
Quote from: "next_ghost"
Quote from: "kevlarman"
you're absolutely right, i should totally do that, anyone know if the server will take commands from stdin?


Can you type commands when you run tremded? Of course you can. Those commands come from stdin :D


So, what you really want is something like this:
Code: [Select]
#!/usr/bin/python

from subprocess import Popen
from subprocess import PIPE
import re

names = ['DancesWithCampers', 'IDontKnowWhoIAm', 'Bew4rOfN00B']
i = 0

p = Popen("tremded.x86", shell=True, bufsize=512, stdin=PIPE, stdout=PIPE, close_fds=True)

up = re.compile("UnamedPlayer")

while True:
    line = p.stdout.readline()
    if not line: break
    if up.search(line):
        p.stdin.write("/say !rename UnamedPlayer %s" % names[i])
        i = i+1
        if i >= len(names): i = 0


You should be able to just add names to the names list.  You might need to change the first line to reflect where python is installed, and this likely requires python2.4 (since I cannot remember what is and is not available in earlier versions).  Finally, you also need to change the path to tremded.x86 (add any command line switches you normally use in the string too).

Once you've done all that, run this program instead of your tremded.x86, and you should find that your UnamedPlayers turn in to DancesWithCampers &c.

This has not been fully tested.  It should work, but I give you no gaurantees it will actually work.  If it breaks your system, you ran it, not me.  This code snippet is public domain.

Jeff -- obviously a bit more than an Associate Linux Programmer
owered by Slackware.  Dare to Slack.

David

  • Spam Killer
  • *
  • Posts: 3543
  • Turrets: +249/-273
Any way to write a script like PHP/Javascript
« Reply #18 on: August 08, 2006, 01:14:19 am »
Quote from: "AssciateLinuxProgr-[SOUP
"]java c#

WTF??????
Any maps not in the MG repo?  Email me or come to irc.freenode.net/#mg.
--
My words are mine and mine alone.  I can't speak for anyone else, and there is no one who can speak for me.  If I ever make a post that gives the opinions or positions of other users or groups, then they will be clearly labeled as such.
I'm disappointed that people's past actions have forced me to state what should be obvious.
I am not a dev.  Nothing I say counts for anything.

kevlarman

  • Posts: 2737
  • Turrets: +291/-295
Any way to write a script like PHP/Javascript
« Reply #19 on: August 08, 2006, 03:53:41 am »
Quote from: "David"
Quote from: "AssciateLinuxProgr-[SOUP
"]java c#

WTF??????
i like how he manages to mix up then and than in the code, as well as the fact that he uses it in combination with braces.
Quote from: Asvarox link=topic=8622.msg169333#msg169333
Ok let's plan it out. Asva, you are nub, go sit on rets, I will build, you two go feed like hell, you go pwn their asses, and everyone else camp in the hallway, roger?
the dretch bites.
-----
|..d| #
|.@.-##
-----

Teiman

  • Posts: 286
  • Turrets: +0/-0
Any way to write a script like PHP/Javascript
« Reply #20 on: August 08, 2006, 09:13:40 am »
Code: [Select]

set un1 "say !rename UnnamedPlayer noob1; bind F7 vstr un2"


Wait!

WTF is that "!rename" thing? a command?
Maybe you can make a new command:

set rename "say !AutoRenameNoob UnnamedPlayer noobfile.txt"

this AutoRenameNoob command can pick a name from the noobfile.txt,  and use it.

Easier to add a scripting engine, and IF parsing, a whole new command to rename noobs to a safe name.

About automatically, maybe the code that render the status can trigger this command over noobs. But I have no idea how Quake3 work, maybe command stuff on the render is a really bad idea or imposible.

kevlarman

  • Posts: 2737
  • Turrets: +291/-295
Any way to write a script like PHP/Javascript
« Reply #21 on: August 08, 2006, 05:34:09 pm »
Quote from: "Teiman"
Code: [Select]

set un1 "say !rename UnnamedPlayer noob1; bind F7 vstr un2"


Wait!

WTF is that "!rename" thing? a command?
Maybe you can make a new command:

set rename "say !AutoRenameNoob UnnamedPlayer noobfile.txt"

this AutoRenameNoob command can pick a name from the noobfile.txt,  and use it.

Easier to add a scripting engine, and IF parsing, a whole new command to rename noobs to a safe name.

About automatically, maybe the code that render the status can trigger this command over noobs. But I have no idea how Quake3 work, maybe command stuff on the render is a really bad idea or imposible.
adding a new command requires patching tjw's source which is possible, but a pain. it is a lot easier to use the !rename command (which tjw's binary already supports) from a script that listens to tremulous' stdout like phaedrus did in python (though his script forgets to do bounds checking, and it would be nice to read from a file)
Quote from: Asvarox link=topic=8622.msg169333#msg169333
Ok let's plan it out. Asva, you are nub, go sit on rets, I will build, you two go feed like hell, you go pwn their asses, and everyone else camp in the hallway, roger?
the dretch bites.
-----
|..d| #
|.@.-##
-----

David

  • Spam Killer
  • *
  • Posts: 3543
  • Turrets: +249/-273
Any way to write a script like PHP/Javascript
« Reply #22 on: August 13, 2006, 08:31:45 pm »
it dosnt work :(

Code: [Select]
stdin is not a tty, tty console mode failed

i was going ot make a client side one to automate admin tasks, and stuff.
Any maps not in the MG repo?  Email me or come to irc.freenode.net/#mg.
--
My words are mine and mine alone.  I can't speak for anyone else, and there is no one who can speak for me.  If I ever make a post that gives the opinions or positions of other users or groups, then they will be clearly labeled as such.
I'm disappointed that people's past actions have forced me to state what should be obvious.
I am not a dev.  Nothing I say counts for anything.

kevlarman

  • Posts: 2737
  • Turrets: +291/-295
Any way to write a script like PHP/Javascript
« Reply #23 on: August 13, 2006, 09:00:29 pm »
Quote from: "David"
it dosnt work :(

Code: [Select]
stdin is not a tty, tty console mode failed

i was going ot make a client side one to automate admin tasks, and stuff.
it works just fine for me in an xterm, haven't tried it from a script because i don't know how to manipulate the stdin/stdout of a child process
Quote from: Asvarox link=topic=8622.msg169333#msg169333
Ok let's plan it out. Asva, you are nub, go sit on rets, I will build, you two go feed like hell, you go pwn their asses, and everyone else camp in the hallway, roger?
the dretch bites.
-----
|..d| #
|.@.-##
-----

David

  • Spam Killer
  • *
  • Posts: 3543
  • Turrets: +249/-273
Any way to write a script like PHP/Javascript
« Reply #24 on: August 13, 2006, 10:45:04 pm »
i meant the code that phaedrus posted wont work.
by redirecting the stdin, it doesnt get a tty.
i can see no reason why thay would have done it like this other than to stop us from using scripts like this.
Any maps not in the MG repo?  Email me or come to irc.freenode.net/#mg.
--
My words are mine and mine alone.  I can't speak for anyone else, and there is no one who can speak for me.  If I ever make a post that gives the opinions or positions of other users or groups, then they will be clearly labeled as such.
I'm disappointed that people's past actions have forced me to state what should be obvious.
I am not a dev.  Nothing I say counts for anything.

kevlarman

  • Posts: 2737
  • Turrets: +291/-295
Any way to write a script like PHP/Javascript
« Reply #25 on: August 14, 2006, 03:42:52 am »
Quote from: "David"
i meant the code that phaedrus posted wont work.
by redirecting the stdin, it doesnt get a tty.
i can see no reason why thay would have done it like this other than to stop us from using scripts like this.
or maybe it's because someone at id decided that since the process wasn't run from an interactive shell, there was no point. you could try running it as tremulous +set ttycon 1.
Quote from: Asvarox link=topic=8622.msg169333#msg169333
Ok let's plan it out. Asva, you are nub, go sit on rets, I will build, you two go feed like hell, you go pwn their asses, and everyone else camp in the hallway, roger?
the dretch bites.
-----
|..d| #
|.@.-##
-----