atrX

Owner
  • Content count

    448
  • Joined

  • Last visited

  • Days Won

    385

Posts posted by atrX


  1. Loading/Precaching FX

    Fx have to be precached before you're able to use them, precaching is done using the following function:

    Please login or register to see this code.

     

    Playing an Effect

    playFx

    When to use? General playing of an effect.

    Please login or register to see this code.

     

    playFxOnTag

    When to use? Playing an effect on tags of an entity, moving effects, deleting effects, ...

    Please login or register to see this code.

     

    playLoopedFx

    When to use? Playing a one-shot effect in a loop.

    Please login or register to see this code.

  2. Server Dvars

    Server dvars (or host dvars) are a kind of variable accessible through console (though, cheat protected). You can both modify and request the value of a server dvar through script.

     

    Saved Dvars

    Saved dvars are saved in the save game and are reset to default on level change. Saved dvar functions only work on dvars that have the 'SAVED' parameter set.

     

    Client Dvars

    Client dvars are, as the name suggest, client side dvars. Using GSC, these can only be adjusted, not retrieved. There is however a few workarounds which I might cover in later tutorials. Client dvars are always accessible through CSC (clientscript), which, again, might be covered later on in another tutorial.

     

    Functions

    getDvar( <dvar> );

    Usage: Get the value of a dvar as a string. This can only fetch server/host dvars, not client dvars. Client dvars can be fetched through clientscript using getDvar().

     

    Arguments:

    <dvar>: The dvar name as a string.

     

    Example:

    Please login or register to see this code.

     

    setDvar<dvar>, <value> );

    Usage: Set the value of a dvar. If the 'development' dvar is set then any dvar can be set, otherwise only external dvars (dvars that are not set through code) can be set. This will only work for server dvars.

     

    Arguments:

    <dvar>: The dvar name as a string.
    <value>: The new dvar value.
     

    Example:

    Please login or register to see this code.

     

    getDvarInt<dvar> );

    Usage: Gets the value of a dvar as an integer.

     

    Arguments:

    <dvar>: The dvar name as a string.

     

    Example:

    Please login or register to see this code.

     

    getDvarFloat<dvar> );

    Usage: Gets the value of a dvar as a float.

     

    Arguments:

    <dvar>: The dvar name as a string.

     

    Example:

    Please login or register to see this code.

     

    setSavedDvar<dvar>, <value> );

    Usage: Sets the value of a dvar. Saved dvars are saved in the save game and are reset to default on level change. Only works on dvars that have the 'SAVED' parameter set.

     

    Arguments:

    <dvar>: The dvar name as a string.

    <value>: The new dvar value.

     

    Example:

    Please login or register to see this code.

     

    setClientDvar<dvar>, <value> );

    Usage: Sets the value of a client dvar.

     

    Arguments:

    <dvar>: The dvar name as a string.

    <value>: The new dvar value.

     

    Example:

    Please login or register to see this code.

     

    setClientDvars<dvar>, <value>, <dvar>, <value>, ... );

    Usage: Sets the value of a list of client dvars.

     

    Arguments:

    <dvar>: The dvar name as a string.

    <value>: The new dvar value.

    Note: You can have as many of these as you'd like.

     

    Example:

    Please login or register to see this code.
    1 person likes this

  3. Types of triggers

    There's a couple different types of triggers:

    • trigger_use: Activates when a player presses the "use" button on it.
    • trigger_use_touch: Activates when a player presses the "use" button when touching it.
    • trigger_radius: Activates when a player (and/or AI, depending on how it's set up) is in its radius.
    • trigger_multiple: Activates when a player (and/or AI, depending on how it's set up) is touching it.
    • trigger_damage: Activates when it gets damaged.
    • trigger_hurt: Activates when a player (and/or AI, depending on how it's set up) is touching it, will deal trigger_hurt.dmg amount of damage to the entity touching it.
    • trigger_lookat: Activates when a player is looking at it.

    There's some more trigger types which you most likely will never use and I will therefore not mention them.

     

    Basic trigger setup

    Please login or register to see this code.

     

    Trigger more than once

    This can be done with a simple loop:

    Please login or register to see this code.

     

    Enabling/disabling triggers

    These functions differ for solo and multiplayer, they're also included in different utility scripts.

     

    Solo:

    Includes required:

    Please login or register to see this code.

    Implementation:

    Please login or register to see this code.

     

    Multiplayer:

    Includes required:

    Please login or register to see this code.

    Implementation:

    Please login or register to see this code.

     

    Spawning triggers in manually

    Please login or register to see this code.

  4. Data Types

    Unlike most programming languages, CoDScript does not require you to specify a data type for a variable, it is however helpful to know what each data type used by CoDScript is:

    • String: Sequence of characters
    • Integer (int): Whole number (ex: -2, -1, 0, 1, 2, ...)
    • Floating point number (float): Rational number (ex: 3.14, 1.337, ...)
    • Boolean (bool): True or false
    • Array: Collection of variables, new elements can be inserted at any given time
    • Vector3: Can be compared to an array with a size of 3, in GSC it acts basically identically to an array except that you shouldn't insert new values, only edit the 3 existing ones
    1 person likes this

  5. What is "self"?

    The "self" you keep seeing in scripts refers to the entity the function is called on, let's have a look at an example:

    Please login or register to see this code.

     

    And how is this utilised for "level"?

    I've gotten a question about what calling a function on "level" does, well, it does the exact same as it does with any other entity you call a function on:

    Please login or register to see this code.

     

    What is the difference between "self" and "player"?

    There's actually an extremely big difference between them, "self" is used to refer to the entity a function is called on. "Player", however, is a variable defined in your script:

    Please login or register to see this code.

  6. Notify, waittill and endon, what exactly does it do?
    Waittill is a function used to make the script wait for a notification (sent by notify), waittill can be called on entities and the level. Notify sends a notification to either an entity or the level. Endon will end a function as soon as it recieves a notification specified in the endon function.
     
    How to use notify, waittill and endon?

    Let's take a look at this example:

    Please login or register to see this code.

  7. Arguments

    Arguments are variables initialised by passing data to a function like this:

    Please login or register to see this code.

    You can also pass variables as an argument:

    Please login or register to see this code.

    You can have as many arguments as you want, just bear in mind to give them a decent name, so not like this:

    Please login or register to see this code.

    Naming arguments is incredibly important in maintaining structure in your scripts as these are the names you'll be using throughout your scripts!

    1 person likes this

  8. What is a variable scope?

    The scope of a variable is essentially the part of your code in which this variable is accessible. If a variable is used outside of its scope an error will be thrown by the game: "Uninitialized variable VARNAME". Let's have a look at this basic example:

    Please login or register to see this code.

     

    Global or level variables

    A global (also known as level) variable can be accessed in any function and in any gsc file from the moment it is initialised:

    Please login or register to see this code.

     

    Entity variables

    You can also declare a variable for an entity, the scope for an entity variable is essentially the same as a level variable, except that it is only accessible by that specific entity it is assigned to:

    Please login or register to see this code.

     

    Scope of the for loop's declaration/initialisation

    As seen in the tutorial about for loops, you can declare and initialize a variable in the first part of it. The scope of a variable initialized in a for loop's initialization ends from the moment the for loop ends:

    Please login or register to see this code.

  9. Break

    Break is used to exit the current statement, you'll see this often used in loops and switch statements. Here's an example:

    Please login or register to see this code.

    As soon as stopLoop is set to true the loop will stop and the function will start executing the code after the loop.

     

    Continue

    Continue is used to exit the current instance of a loop, let's have a look at an example:

    Please login or register to see this code.

    If doContinue is true, the current instance of this infinite loop will end and it'll start a new one from the top.

     

    Return

    Return is used to exit the current function and optionally return a value.

    Please login or register to see this code.

  10. What is a Switch Statement?

    A switch statement selects a switch section to execute from a list of candidates (cases). Here's a simple example of a switch statement with 3 switch sections:

    Please login or register to see this code.

    In this example, 1 will be printed on the screen. Note that there is no break in the default switch section, it is not required to add a break to the default switch statement. But why is it required to have a break in the other switch sections then? Because the default switch section will ALWAYS be executed UNLESS you break the switch statement, and we don't want "Default" popping up on our screen if var is equal to 1.

     

    Multiple conditions per candidate

    Let's have a look at an example first:

    Please login or register to see this code.

    There's a couple things about this switch statement that are different compared to our first example. One of these differences is that there are multiple conditions per candidate, it's pretty straight forward how this works, I don't think any further explanation is needed.

     

    But you said breaking a switch statement was required?

    Yes, I did, but breaking a switch statement is only required if you have a default case, in the above example there is none, meaning we don't have to worry about that being executed.


  11. What is an if-else selection?

    The if-else statement identifies which statement to run based on a boolean expression. In the following example, var will be set to 1 as condition is set to true:

    Please login or register to see this code.

     

    If ladders

    You can string tons of if statements together to make an if ladder:

    Please login or register to see this code.

  12. What is a while loop?

    A while loop will execute code as long as a condition is met.

     

    How to use a while loop?

    Please login or register to see this code.

     

    Why use a while loop? I got for loops already!

    There's a simple reason: your source code looks cleaner. Let's take a look:

    Please login or register to see this code.

    Honestly, which one looks more appealing to the eye? The while loop, right. Now, obviously for loops have their usage too, but if you simply need to do a conditional loop, go with a while loop.

     

    What is a for loop?

    A for loop will execute code as long as a condition is met. Unlike while loops, however, for loops can also declare and initialize a variable and/or execute a line of code (loop expression) inside the actual logic statement. Let's take a look:

    Please login or register to see this code.

     

    How to use a for loop?

    As I said before, a for loop consists of 3 parts: declaration/initialization, condition and a loop expression. These 3 parts are all optional, you will often see things like:

    Please login or register to see this code. Please login or register to see this code.

    These are just some examples, there's way more uses for a for loop than shown here.

    In general for loops are used like in the first example, meaning initialization is used to initialize a variable to check for in the condition and incremented/decremented/... in the loop expression. But there's quite a few exceptions as seen in the above examples.

     

    Why use a for loop?
    For loops are love, for loops are life. They honestly help make your code much more organized, let's compare a regular for loop to what it would look like when done with a while loop:

    Please login or register to see this code. Please login or register to see this code.

    The for loop is a lot more organised, as you can see.

     

    How to make an infinite loop?
    Both for and while loops can be easily made infinite:

    Please login or register to see this code. Please login or register to see this code.

     

    Error: Potential infinite loop, what now?

    Obviously you can't physically have code running infinitely without waiting between every loop execution, if the engine would allow you to do this the game would most likely crash. Heck, it even freezes for a couple seconds now when you try to run an infinite loop without waiting between every loop execution. So, how can you solve this? The answer lies in the wait() function:

    Please login or register to see this code.

    Alternatively, because this is a for loop, you could do something like this:

    Please login or register to see this code.

  13. What is an array?

    Arrays are used to store multiple values in a single variable, every value is accessible by its index. Arrays in CoDScript are 0 indexed, meaning the array indexes start from 0.

     

    Declaring an array

    An array in CoDScript is declared as follows:

    Please login or register to see this code.

     

    Storing data in an array

    You can manually store data in an array:

    Please login or register to see this code.

    CoDScript also has many different functions that will return an array, here's a few examples:

    Please login or register to see this code.

     

    Retrieving data from an array

    Retrieving data from an array is simple and works with array's indexes:

    Please login or register to see this code.

     

    Multidimensional arrays

    Multidimensional arrays are basically embedded arrays. What this means is that you are able to store arrays within other arrays.

    Here's a short example of an embedded array:

    Please login or register to see this code.

  14. What are Relational Operators?

    Relational operators compare one value to another. The comparison operators available in CoDScript are:

    • == (Tests if the two operands are equal.)
    • != (Tests if the two operands are not equal.)
    • < (Tests if operand 1 is smaller than operand 2.)
    • > (Tests if operand 1 is larger than operand 2.)
    • <= (Tests if operand 1 is smaller than or equal to operand 2.)
    • >= (Tests if operand 1 is larger than or equal to operand 2.)

    All relational operators result in a boolean value (true or false).

     

    Examples of how to use Relational Operators

    Please login or register to see this code.

     

    What are Logical Operators?

    Logical operators are used to check for multiple conditions (or sometimes if a condition is not true). A logic statement only returns true or false, so to have multiple conditions we use logical operators. Here's a list of the logical operators for CoDScript, what they mean and an example of how to use them:

    Please login or register to see this code.
    1 person likes this

  15. What is threading?

    When calling a function regularly, your code will wait until the called function has finished or returned a value. If you want to run asynchronous functions you'll need to use threading which does not require your code to wait for the threaded function to finish or return a value.

     

    When to use threading?

    This all depends on the purpose of your script. In general, you want to avoid threading as much as possible as it requires extra resources to thread a function as opposed to regularly calling it. The only time you should ever thread a function is if you want to run this function asynchronously from your current code. A great example of this is calling functions on entities in an array. You'll usually want to thread these (there are exceptions, of course) as otherwise your're going to be waiting for one function to finish before going onto the next one.

     

    How to use threading?

    Threading is as simple as putting "thread" in front of your function call:

    Please login or register to see this code.
    1 person likes this

  16. What is a "Syntax"?

    Syntax is the name for the basic structure of a scripting language. If, when testing your scripts, you get an error saying "Syntax Error: ..." Then you've made a mistake in the syntax of your script. More on debugging these errors later on.

     

    What does this "Syntax" look like then?

    CoDScript (which I will often refer to as GSC) is based on the programming language C and therefore follows the same syntax structure. Here's a list of the syntax used for includes, functions, logic statements, variable declaration and comments.

     

    Includes

    An include basically allows you to call functions in your script without having to add their path like is done in this example:

    Please login or register to see this code.

    If you see yourself using the same function from the same file a lot it's probably a good idea to include the functions from said file in your script:

    Please login or register to see this code.

    As you can see, you don't have to add the path to the file that contains the function every time.

     

    Functions

    A function is started by the function name (helloWorld in the example below), followed by parenthesis. Around the function "helloWorld()" curly brackets are placed.

    Please login or register to see this code.

     

    Function Calls

    You can call a function by typing out the function name, followed by parenthesis and a semicolon.

    Please login or register to see this code.

     

    Logic Statements

    A logic statement can be many different things: if(), else if(), else, while(), for(), ... Luckily, all of them follow the same basic structure:

    Please login or register to see this code.

    More on the many different logical statements in further tutorials.

     

    Variable Declaration

    You can declare variables like this:

    Please login or register to see this code.

     

    Comments

    You've seen me use these things a few times now:

    Please login or register to see this code.

    These are comments, they're basically small notes you leave to yourself or others in your script. These do not get parsed ingame and do not have any impact on your code. Their sole purpose is clarifying what a piece of code does.

    There's two types of comments:

    Please login or register to see this code.

     

    Syntax Errors

    If, by accident, you made a mistake in your syntax (forgetting to write a semicolon for example), the game will throw a syntax error. You can track where the problem is by typing "developer 1" in the console and relaunching your map/mod. The game will tell you the line number of the error when you open up the full console (shift + console key).


  17. On 6/15/2018 at 8:55 PM, xoxor4d0xzz said:

    Nice that the tutorial is back! B|

    Dunno if you still have all the data of codscript, but I really liked your scripting tutorial you made back then. Did help me quite alot tbh :$

    It was kinda meh, dunno if I still have it somewhere. I'll check.

     

    On 6/15/2018 at 8:55 PM, xoxor4d0xzz said:

    Also, is setGravity a thing with your serverversion?

    Please login or register to see this link.

     

    Edit: I found the old database with all the tutorials, let's see if they're worth reposting.

    1 person likes this

  18. Hi there!

    Figured I should probably rewrite this guide so people can make maps if they want.

     

    Prerequisites

    • Latest Local Play/Developer Build: Please login or register to see this link.  (once extracted, ignore the last line of the README.txt, as CoDScript is no longer up, simply run "Local Server.bat" and connect to the server using "Play Surf.bat")
    • Alternatively, set up a local server using the source code: Please login or register to see this link.  (Advised if you want to use newer developer features as the Developer Build is rarely updated, certainly not a requirement however)

     

    Mapping

    Making a surf map is relatively easy and requires no scripting if you keep it basic. Setting your map up to work with the mod relies heavily on the use of KVPs (key-value pairs) in Radiant. I'll go over all the necessary components first and then list any other things you can make use of.

    Spawns

    Surf makes use of regular mp_dm_spawn entities. You can place as many as you'd like, but you'll need at least 1.

    ok89Q12.png

     

    You can also provide a spectator point using an mp_global_intermission entity.

    zRrDxf6.png

     

    Start Zone

    The start zone is required to know when to start the timer (it starts as soon as you leave this area). The start zone should be a trigger_multiple with the following KVP:

    Please login or register to see this code.

    ZtVNn1v.png

    You should only ever have ONE start zone!

     

    End Zone

    The end zone is required to know when to stop the timer (it stops as soon as you enter this area), and thus finish the map. The end zone should be a trigger_multiple with the following KVP:

    Please login or register to see this code.

    c2GQOa2.png

    You should only ever have ONE end zone!

     

    Teleporters

    Teleporters are used to teleport players around the map (e.g. when they finish a stage or when they fail a section of the map and need to be respawned somewhere). Teleporters consist of two components: triggers (the area you enter) and script_origins (where you'll be teleported to).

    Generally your triggers will be of the type trigger_multiple, but any other type will also work. It depends on what you need. Every teleporter trigger should have the following KVP:

    Please login or register to see this code.

    Yx5rFJd.png

    As you can see, the teleporter in this screenshot has another KVP:

    Please login or register to see this code.

    The target is the targetname of whatever script_origins are linked to this teleporter (thus, the places you'll be teleported to). You don't have to enter these manually, these will be automatically generated when we start adding script_origins and link them to the triggers.

    Next we'll add a place for this trigger to teleport us to. To do this, we spawn a script_origin.

    GsrO2yF.png

    Now, to link this script origin to the trigger we made earlier, all you have to do is first select the trigger, then select the script_origin and then press W on the keyboard. This will automatically give the script_origin a generated targetname and give the trigger a target pointing to the script_origin.

    You can link as many script_origins to as many triggers as you'd like, there is no limit on either. Beware that an entity can only have one targetname and one target, meaning that you can only link multiple script_origins and triggers together if they actually belong to the same group that will teleport to the same places.

     

    Boosters (Incremental)

    Incremental boosters will add predefined amounts to the player's velocity in a certain direction, speeding him up (or slowing him down in the case of negative values). To make a booster, make a trigger_multiple and give it the following KVPs:

    Please login or register to see this code.

    The target values, x, y and z, should be replaced with the desired speeds in the desired directions (you'll have to play around with these to find a value you like).

     

    Boosters (Scaling)

    Scaling boosters are made in the exact same way as incremental boosters (except for the targetname used). However, unlike incremental boosters, they multiply the player's velocity with the amounts defined.

    Please login or register to see this code.

    Using this, you can make a trigger that, for example, simply doubles a player's horizontal speed using:

    Please login or register to see this code.

     

    No-Hop Zones

    A no-hop zone is an area in which bunny hopping is limited to speeds <= 320 (going above 320 will put your speed back to 280). These can be useful in case you want people to start your map (or stages) from a standstill. To create a no-hop zone you simply make a trigger_multiple covering the area you want and give it the following KVP:

    Please login or register to see this code.

     

    Scripting

    Making a basic surf map requires practically no scripting. All you really need is this basic template:

    Please login or register to see this code.

    You can add much more if you'd like, but make sure your maps runs without a hitch and always test using developer 1! Maps with bad quality scripts will not be added to the official server as they can cause server hitches resulting in lag (which would be detrimental to the user experience as movement is entirely server-sided and thus suffers badly from lag spikes).

    Functions exposed by the mod for use in your maps can be found here: Please login or register to see this link.

     

    I will update this topic if any new features are ever added that you can take advantage of as a mapper.

    Regards, atrX.

    2 people like this

  19. Yes, it's happening, after all this time I'm making a third rendition of this crap series of maps... I've been streaming the mapping process and will continue to do so. All the livestreams are available at: 

     

    1 person likes this

  20. Hi there!

    I've just pushed out an update to Deathrun adding some new stuff like geo trails, old Raid skins and a bunch of new maps. Also in this new update is a bunch of changes and fixes for problems you've all reported. For more information, check the changelog:

     

    Aside from the update I wanted to also put out a quick roadmap for the near future. In order, my current priority is:

    • Slay V3 :ph34r:
    • Raid Promod
    • Raid Fun/High Jump
    • Raid Surf update (new customisation including some of the stuff that was added to Deathrun and possibly some other new stuff)
    • Leaderboard frontend overhaul and integration with Deathrun (currently Please login or register to see this link. )

     

    Hope to see you all on the server! :) PS: Yes, I was indeed too lazy to redo the spectator input overlay for this update, maybe in the next one. :dave:

     

    Regards, atrX.

    5 people like this

  21. Changelog

    New:

    • Added 7 new FX trails (thanks @Mist)
    • Added 4 new geometry trails (thanks @xoxor4d0xzz)
    • Community Announcement and Admin Message through B3 (admins only, across all servers)
    • !join commands (only able to add these on Deathrun and Surf, unfortunately)
    • Added 5 more maps to the rotation (mp_deathrun_hop, mp_deathrun_wood, mp_deathrun_ponies, mp_dr_merry_xmas, mp_dr_fallrun)

    Changes:

    • Reverted weapon skins to the old Raid ones (the really shiny gold ones)
    • Ghosts now have ammo (and can also under no circumstances damage the activator)
    • VIP Deagle now has a purple muzzleflash
    • Removed clip blocking the activator from getting close to the end door on mp_deathrun_liferun
    • Added back Beatthat's Deagle to mp_dr_destiny

    Fixes:

    • Killcam will now also trigger for the activator when players are in ghost run
    • Fixed endmap triggers on some maps
    • Fixed traps not giving XP on some maps
    • Fixed mp_dr_bounce endrooms
    • Fixed mp_dr_blue to force fullbright regardless of your preferences
    • Fixed mp_deathrun_factory's endgame music overlapping with the endround songs
    • Fixed mp_deathrun_factory's sniper room never getting enabled if players in in ghost run
    • Fixed mp_dr_destiny's final fight not getting enabled if players are in ghost run
    • Server now has enough time to display the winning map of a mapvote properly
    • Added mp_deathrun_factory to the exception list for anti spawn camp to prevent people from dying when jumping into spawn from the activator room
    • Fixed spectator button overlay overlapping with ghost run text
    • Added back the german shepard model and animations (mp_deathrun_cherry endroom fix)

     

    If you find any more bugs or issues, please report them here: Please login or register to see this link.

    6 people like this