Coder Social home page Coder Social logo

cod4x_lua_plugin's Introduction

Call of Duty 4 X Lua Plugin

This plugin adds support for CoD4X plugins written in Lua. It is suited towards modders, who require faster functions to be used within gsc scripts and do not want to deal with writting a C plugin. Functions written in Lua are up to 10 times faster than in gsc.

Usage

All usable function are listed here. All functions have same usage parameters as stock plugin function with exception of:

Plugin_AddCommand( (string)<function name>, (int)<power> )
Plugin_ScrAddFunction( (string)<function name> )
vec = Plugin_Scr_GetVector( (int)<param number> )
  • function name is both name of function in gsc and in lua.
  • power is the power needed to run the command, 0 is rcon only, 1 is for everyone.
  • param number is the index of parameter passed within gsc, starting at 0.

Extra notes about vectors in Lua:

  • Vector is a table with size of 3
  • Index must always start at 1 ( vec[1], vec[2], vec[3] )
  • You can simply define the vector as vec = { 192.27, 946.5, 2895.99 }

Lua scripts must be placed in server homepath and loaded with "lua_loadscript <script path>" command

Example

server.cfg:

loadplugin lua
lua_loadscript "lua_scripts/test.lua" // script is located in fs_homepath/lua_scripts

test.lua:

Plugin_ScrAddFunction( "mysqrt" )

function mysqrt ()
    local n = Plugin_Scr_GetFloat( 0 ) --get number (float) from gsc
    local x0 = n
    local x1 = 0
    local delta
    while ( 1 )
    do
        x1 = x0 - (x0*x0 - n)/(2*x0)
        delta = (x1-x0)/x0;
        if ( delta < 0.000001 and delta > -0.000001 ) then
            break
        end
        x0 = x1
    end
    Plugin_Scr_AddFloat( x1 ) --add result (float) to gsc
end

gsc:

main()
{
    num = 123;
    print( "Square root of " + num + " is " + mysqrt( num ) + "\n" );
}

Compiling

Enter directory and run make. Needs to be placed in plugins directory in CoD4X server source code. On Windows you need to compile the server first.

cod4x_lua_plugin's People

Contributors

3agl3 avatar leiizko avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.