Sauerworld Forum

### ( Triggers in multiplayer, ~~NEW~~ beta 4! .:FIXED UPDATE:. ) ###

Timon

  • *
  • 7
  • +1/-0
  • Argh, my stick...
Hello damn despaired Sauerbraten community!  ;D
I playing this game since 2008 year and for all that time i've explored damn many nice and tricky things, i have good skills in cubescript and there is not that many things are impossible for me. It's even possible to read chat messages via cubescript, remote other computers/files/clients live, etc..
I will be glad to breath the new life into Sauerbraten implementing new features and i hope u could help me with this shit.
My heart is opened for YOU and YOUR suggestions can change the world(sauer world ofc  ;)), my friend!
I'll make everything for free guys, just ask me, and wait for my accept, <3 u all!

And now, i wanna present you my very-old, but useful tool for cooperative editing modes - multiplayer triggers(Yeah, not SP!!!  :o).




Below u can previev teh code:

Code: [Select]
//triggerconstructor beta 3 by (ESP)Timon//

dumpfile = [
  newgui savefile [
    if (strlen (getalias [file_@@arg1])) [
      [file_@@@arg1] = []
    ] [
      [file_@@@arg1] = [@@@arg2]
      guifield [file_@@@arg1]
      textfocus [file_@@@arg1]
      textsave [@@@arg1]
      notepadfile = [@@@arg1]
      cleargui
    ]
  ]
  showgui savefile
]

dumptriggers = [
  local filebuf shrinkbuf
  looplist a $arg2 [
    shrinkbuf = (concat $shrinkbuf $a)
    looplist b $[trigger_bank_@a] [
      filebuf = (format "%1addtrigger %2 %3^n^n" $filebuf $a $b)
    ]
  ]
  filebuf = (format "shrinktriggers [%1 ]^n^n%2" $shrinkbuf $filebuf)
  dumpfile $arg1 $filebuf
]

editmod = [
  if $editing [
    arg1
  ] [
    if (= $getmode 1) [
      if (isspectator $getclientnum) [
        arg2
      ] [
        edittoggle
        arg1
        edittoggle
      ]
    ] [
      arg2
    ]
  ]
]

getcenter = [
  local coeff
  coeff = (cos $getcampitch)
  concat (
    +f (at $getcampos 0) (*f [-@arg1] (*f $coeff (sin $getcamyaw)))
  ) (
    +f (at $getcampos 1) (*f $arg1 (*f $coeff (cos $getcamyaw)))
  ) (
    +f (at $getcampos 2) (*f $arg1 (sin $getcampitch))
  )
]

listpos = [
  local buf
  editmod [
    cancelsel
    local a b
    a = $entdrop
    b = $entautoviewdist
    entdrop 0
    entautoviewdist 0
    newent particles -357
    buf = [[[@@@getcampos] @@getclientnum] ]
    looplist c $listclients [
      goto $c
      buf = (concatword $buf "[[" (getcenter 32) "] "$c"] ")
    ]
    entautoview
    delent
    entdrop $a
    entautoviewdist $b
  ]
  result $buf
]

getpos = [
  local buf
  editmod [
    cancelsel
    local a b
    a = $entdrop
    b = $entautoviewdist
    entdrop 0
    entautoviewdist 0
    newent particles -357
    goto @arg1
    buf = (getcenter 32)
    entautoview
    delent
    entdrop $a
    entautoviewdist $b
  ]
  result $buf
]

dist = [
  sqrt ((+f (+f (pow (-f (at $arg2 0) (at $arg1 0)) 2) (pow (-f (at $arg2 1) (at $arg1 1)) 2)) (pow (-f (at $arg2 2) (at $arg1 2)) 2)))
]

addtrigger = [
  [trigger_bank_@arg1] = (
    format "%1  [[%2] %3 [%4] [%5]]^n" (getalias [trigger_bank_@arg1]) $arg2 $arg3 $arg4 $arg5
  )
]

shrinktriggers = [
  looplist a $arg1 [
    [trigger_bank_@a] = []
  ]
]

parsetriggers = [
  looplist a $[trigger_bank_@arg1] [
    local entered
    looplist b $ci [
      if (< (dist (at $a 0) (at $b 0)) (at $a 1)) [
        entered = (format "%1[%2] " $entered $b)
      ]
    ]
    if (strlen $entered) [
      do (at $a 2)
    ] [
      do (at $a 3)
    ]
  ]
]

starttriggers = [
  local ci
  editmod [
    ci = (listpos)
    parsetriggers @arg1
  ]
  sleep $arg2 [
    starttriggers @arg1 @arg2
  ]
]

//Script done by (ESP)Timon//



Below manual how to use it:

First at all u should download my attachment(triggers.txt), and place it into main game folder.
then, start the game, go into coop edit, then press T or ~ and write next:
Code: [Select]
/exec triggers.txt
After u did the first step, u can construct triggers immediately (alles Gute für Sie :) )!
To do this, there's a command called "addtrigger", its structure is the next: addtrigger (trigger bank name) [X Y Z] (radius of a trigger) [do if true] [do if false]
Trigger bank name - any name u like, i'd prefer to declarate their names like: bank1, bank2... etc. (trigger bank constains all triggers inside u declarated via "addtrigger" as array, or list)
[X Y Z] - position of trigger, depends on world coordinates, u can set it manually or use current camera position (setting this argument to $getcampos, without brackets ofc, it's a cubescript call  ;) ).
Radius of a trigger - radius to activate, the same as in envmap, sound and light ents (player height is 16 by default) :D.
[do if true] - place ur script into square brackets, that should be executen if any player joins into a trigger.
[do if false] - same as upper, but vice-versa.

For example we can fly to needed map spot and then write this:
Code: [Select]
/addtrigger bank1 $getcampos 16 [entfind particles; delent; echo $entered]This stuff will push new trigger into bank called "bank1" with coordinates that equals current camera position with radius 16. if any player gonna join into this trigger it will delete all particles and print to YOU info about players that inside of this trigger(info struct [[X Y Z] CN] [...]) ("entered" is a declarated variable used in "parsetriggers" function).

This triggers will not work until you start them  ;D.
To do this, use "starttriggers" command, its structure is the next: starttriggers (trigger bank name) (delay to repeat triggers)
Trigger bank name - name of bank where your triggers are placed (in our case it's "bank1").
Delay to repeat triggers - delay needed to update all triggers in the current bank, set it 99 by default.

For example, to start triggers, type next:
Code: [Select]
/starttriggers bank1 99
To stop maintain all triggers, just write
Code: [Select]
/clearsleep

To clean up bank1 from all triggers, write
Code: [Select]
/shrinktriggers bank1 (you also can clean few banks in a row, example /shrinktriggers [bank1 bank2 ... bankN])

to dump trigger bank into a file, write
Code: [Select]
/dumptriggers mytriggers.cfg [bank1 bank2 ... bankN]( mytriggers.cfg - file name where to save)




Below additional capabilities:
U can also stack triggers, because if u're adding too many triggers in one bank, they checking in one loop too slow, make tree-like structure to serve them.  ;)

Code: [Select]
addtrigger bank1 [512 512 512] 256 [parsetriggers bank2] //if this trigger become active, it's will automatically check triggers in bank2, but not else.
addtrigger bank2 [550 550 512] 16 [echo test]
addtrigger bank2 [450 450 512] 16 [echo hello]
starttriggers bank1 99
Warning: don't forget to shrink trigger banks, if u wanna remake them!


Below features and misc:
Using this useful shit u can make things like a:
  • deathruns;
  • places that killing others;
  • rpgs;
  • buttons;
  • change ents;
  • MUH MOAR!!! (use ur imagination xD  ;D)

This script also constains functions that getting other player positions and position lists, u can find them useful. (do velocity check to make falldamage for other players xD)
Also, "getcenter" function can become a nice tool to check distances :)
You can use "dumpfile" to send files(configs) via maptitle or etc to other clients in editmode. (if u know how to send scripts via maptitle ofc XD)

Be happy and use dat free :)  8)



Below u can see changelog:
  • Beta 2:
    • New filedump structure("dumptriggers" command)
    • Addtrigger function uses new format, compatible with current filedump
  • Beta 3:
    • Optimised editmod command
    • "starttriggers" launch "parsetriggers" function in editmod now(reduces overflow)
    • Local "entered" inside of "parsetriggers" also contains positions now
  • Beta 4:
    • dumptriggers function is fixed
    • TODO: made dumpfile func save comments "//"


P.S. Sry for bad english xD... Report all bugs if u find them and ur suggestions too.
To send this script other players ingame, use:
Code: [Select]
/textfocus textbuf; textload triggers.txt; maptitle $textshow
And request them to write:
Code: [Select]
/do $maptitle
Don't forget, most of this stuffs working only in coop edit mode.
« Last Edit: April 26, 2016, 04:46:54 PM by Timon »
Go out my love, u smell.

Salatiel

  • ***
  • 114
  • +25/-1
    • Projects by Salatiel
Re: Triggers in multiplayer, beta 1!
« Reply #1 on: February 21, 2016, 05:29:59 PM »
Nice script man, good job! :)

Edit (2019):
for those who are wondering how it works, it will goto all players "instantly" and check your cam pos. If there is a custom "trigger" at your current position, it will run an action that you set. No magic, just a very clever trick (and it took me almost 4 years to understand).

I hope to see you back someday, Timon!
« Last Edit: October 03, 2019, 05:43:59 PM by Salatiel »
@Salatiel#5274

star

  • *****
  • 310
  • +19/-5
Re: Triggers in multiplayer, beta 2! .:Updated:.
« Reply #2 on: February 23, 2016, 01:04:49 AM »
I don't get it. Could you maybe also explain what it is for and what it does, instead of just explaining how to use it?

Timon

  • *
  • 7
  • +1/-0
  • Argh, my stick...
Re: Triggers in multiplayer, beta 2! .:Updated:.
« Reply #3 on: February 23, 2016, 09:10:58 AM »
I don't get it. Could you maybe also explain what it is for and what it does, instead of just explaining how to use it?

Actually it's a buttons. When you or other players press them, while only you running this script - it executes some scripts u declarated inside. Example, trolling quaddamage ent(ent that dissapearing when people come closer to it):
Code: [Select]
entautoviewdist 0
entfind quaddamage 24 //finding quaddamage with attr1 == 24
entautoview //going inside of quaddamage
addtrigger bank1 $getcampos 64 [entfind quaddamage 24; entset box 24] [entfind box 24; entset quaddamage 24] //$getcampos - current coordinate that equal to coordinates of quaddamage ent.
starttrigger bank1 188

U also can make deathruns via this, i.e. when people press buttons - they activate traps for other players.
« Last Edit: February 23, 2016, 09:49:21 AM by Timon »
Go out my love, u smell.

star

  • *****
  • 310
  • +19/-5
Re: Triggers in multiplayer, beta 3! .:NEW Update:.
« Reply #4 on: February 23, 2016, 02:28:14 PM »
although this might be a cool piece of code, i can't see ANY use of this whatsoever. Does this work only in coopedit, or do plan to make singleplayer maps with this?

Timon

  • *
  • 7
  • +1/-0
  • Argh, my stick...
Re: Triggers in multiplayer, beta 3! .:NEW Update:.
« Reply #5 on: February 23, 2016, 03:42:59 PM »
although this might be a cool piece of code, i can't see ANY use of this whatsoever. Does this work only in coopedit, or do plan to make singleplayer maps with this?

If u wanna build QUEST map, DEATHRUN map, DOKO or PACMAN, just fun and simply things(without sending stipid configs to other people via skype and such things) - this tools can help you. As i said, they are working only in coop edit modes.
Wanna place it to other gamemodes? Please! Modify servercode and include them there, those tools are flexible for such manipulations.

I'll finish new map soon using those tools, so u will see what they're really able to do.
Go out my love, u smell.

va|DeathStar

  • *
  • 29
  • +1/-3
    • TechMaster
Re: ### ( Triggers in multiplayer, ~~NEW~~ beta 4! .:FIXED UPDATE:. ) ###
« Reply #6 on: October 08, 2016, 12:34:42 PM »
Awesome! Good job with this script, we gotta write some cool modes with custom autosendmap and autocalclight!

Timon

  • *
  • 7
  • +1/-0
  • Argh, my stick...
Re: ### ( Triggers in multiplayer, ~~NEW~~ beta 4! .:FIXED UPDATE:. ) ###
« Reply #7 on: October 09, 2016, 03:45:50 PM »
For example, my old piratewars map, it was based on script similar to this one:
Cannons is a triggered buttons and cannonballs is just hundereds of marked boxes ents in air. Destructions is static too. Every cannon can randomly fire in 3 different positions. I also had deathrun map with buttons and entity traps.
Go out my love, u smell.

Suicizer

  • ***
  • 141
  • +6/-5
Re: ### ( Triggers in multiplayer, ~~NEW~~ beta 4! .:FIXED UPDATE:. ) ###
« Reply #8 on: November 22, 2016, 08:16:55 AM »
For those who don't understand this;

It's a script that makes you able to do various of events in edit-mode.

This won't work in other modes as you can't place entities while trying to rifle down your teammate in effic team.
You would need to modify the source-code for that.

The title of this topic is therefore misleiding.
« Last Edit: November 22, 2016, 08:21:11 AM by Suicizer »