Wiki

Clone wiki

Game Guru Toolkit / Home

Welcome

Welcome to Avram's Game Guru Toolkit wiki. Avram's Game Guru Toolkit is a LUA OOP framework (set of LUA OOP classes) for easier development of FPS games with Game Guru.

Game Guru LUA

Why?

Instead of writing spaghetti code and cluttering your global game namespace with custom variables and functions this project tries to encapsulate player and entities in Game Guru so you can easily interact with entities within the game. Don't expect too much though, as LUA support in Game Guru is still poor at this stage. There are only few things you can do, but with this framework you're going to do them easier than ever!

The way it is now, to accomplish anything with LUA in Game Guru you need to write complicated code like this:

#!lua
function pickupitem_main(e)
    -- Get Player Distance
    PlayerDX = g_Entity[e]['x'] - g_PlayerPosX
    PlayerDY = g_Entity[e]['y'] - g_PlayerPosY
    PlayerDZ = g_Entity[e]['z'] - g_PlayerPosZ
    PlayerDist = math.sqrt(math.abs(PlayerDX*PlayerDX)+math.abs(PlayerDY*PlayerDY)+math.abs(PlayerDZ*PlayerDZ))

    -- Showing Text
    if PlayerDist < 80 then
    Prompt("Press E to pickup Item")
    end

    -- Player pickup some item through pressing "E"
    if PlayerDist < 80 and g_KeyPressE == 1 then
    PlaySound0(e)
    Collected(e)
    Destroy(e)
    end

    --End of function
end

And all this just for ability to show text when player is near the entity and to pick it up by pressing "E" key? How about something like this:

#!lua
function pickupitem_main(e)
    -- Encapsulate this entity
    local this = aEntity:new(e)

    -- Showing text when player is near
    if this:distance(aPlayer) < 80 then
    Prompt("Press E to pickup Item");
    end

    -- Player pickup some item through pressing "E"
    if this:distance(aPlayer) < 80 and g_KeyPressE == 1 then
    PlaySound0(e)
    Collected(e)
    Destroy(e)
    end

    --End of function
end

Now, this might not look so awesome, but the real power of this framework can be seen when you try to interact with more than one entity within the function. In regular Game Guru LUA entity functions you get only one parameter, e, which is current entity index in g_Entity table. And the current entity is the entity your LUA script is assigned to. Your script have no idea about other entities in the game level.

The Magic!

What if you have a plant on the table and you want that plant to show how far you are from the nearest teapot entity when you are near the plant? Well, with this framework it is possible. However, there is one catch - at this stage (beta 1.005), LUA in Game Guru does not get entity names that are set in entity properties in Game Guru itself (the panel you see when you right click and choose "Properties" on an existing entity in your Game Guru level)! So we need to set entity names for each entity we want to interact with by it's name in their own script. It's a little bit of overwork, but that's the way it has to be now.

teapot.lua

#!lua
function teapot_main(e)
    -- Encapsulate teapot entity and give it a name
    local this = aEntity:new(e, "teapot")
end

This will assign your teapot name "teapot". Pretty simple, huh? I hope in future Game Guru will populate g_Entity[e] tables with entity names as well so there will not be need for above code in each entity script.

Now here's the magic:

plant.lua

#!lua
function plant_main(e)
    -- Encapsulate plant entity and give it a name
    local this = aEntity:new(e, "plant")

    -- Get the nearest teapot entity by it's name
    local teapot = aPlayer:nearest("teapot")

    -- If the player is near the plant (and the teapot exists), show the distance to the teapot
    if this:distance(aPlayer) < 80 and teapot ~= nil then
    Prompt("Distance between player and the teapot is: " .. teapot:distance(aPlayer))
    end
end

This is pretty much useless example but it shows how easy is to interact with multiple entities from within one LUA script.

For detailed explanation head to the Class Reference manual. Or you may want to install the framework right away? You can also check examples page, when they are done :S

Updated