Posted By: nfs42
[GSTScript] 0.9.2 released - 04/05/11 19:39
do you want to let your users mod your games ?
here is the second release of GSTScript supporting lua 5.1.4
some standard classes are defined like EngineClass, EntityClass, CameraClass
you can register lite-c functions in lua and call lua functions from lite-c.
more...
happy scripting
here is the second release of GSTScript supporting lua 5.1.4
some standard classes are defined like EngineClass, EntityClass, CameraClass
you can register lite-c functions in lua and call lua functions from lite-c.
more...
happy scripting
Click to reveal..
Code:
-- require "GSTDebug" -- initialize global objects engine = EngineClass() camera = CameraClass(engine:camera()) gImage = ImageClass() gSound = SoundClass() gSound:Load("data/sounds/impact.wav") engine:SetVideoMode(2) -- 1=windowed, 2= fullscreen engine:VideoWindow(0,0,0,0,0,"GSTScript TEST V 0.9.2 by GSTools/nfs42") camera:SetPan(0) galpha_step = -10 gInitialized = 0 ---------------------------------------------------------------------------------------- -- function: entity -- purpose: to be called from lite-c entity action every frame -------------------------------------------------------------------- function entity() gModel = EntityClass(engine:my()) if (lastx == 0) then lastx = gModel:GetX() lasty = gModel:GetY() end -- gModel:SetX(gModel:GetX() - 1 * engine:time_step()) -- gModel:SetY(gModel:GetY() - 1 * engine:time_step()) gModel:SetPan(gModel:GetPan() - 15 * engine:time_step()) gModel:SetTilt(gModel:GetTilt() - 15 * engine:time_step()) gModel:SetLightRange(gModel:GetLightRange()+1) -- gModel:SetBlue(0) gModel:SetGreen(255) gModel:SetRed(255) gModel:SetU(gModel:GetU() + 0.1 * engine:time_step()) gModel:SetV(gModel:GetV() + 0.1 * engine:time_step()) if (gModel:GetAlpha() < 0) then galpha_step = 10 end if (gModel:GetAlpha() > 100) then galpha_step = -10 end gModel:SetAlpha(gModel:GetAlpha() + galpha_step * engine:time_step()) TESTENT(gModel:Handle()) end ---------------------------------------------------------------------------------------- -- function: cameramove -- purpose: controls cameramove in lua -------------------------------------------------------------------- function cameramove() if engine:KeyPressedByName("cuu") then --> VK_UP camera:SetTilt(camera:GetTilt() + 2 * engine:time_step()) elseif engine:KeyPressedByName("cud") then --> VK_DOWN camera:SetTilt(camera:GetTilt() - 2 * engine:time_step()) elseif engine:KeyPressed(75) then --> VK_LEFT camera:SetPan(camera:GetPan() + 5 * engine:time_step()) elseif engine:KeyPressed(77) then --> VK_RIGHT camera:SetPan(camera:GetPan() - 5 * engine:time_step()) elseif engine:KeyPressed(33) then --> VK_PRIOR camera:SetPan(camera:GetPan() + 0.1 * engine:time_step()) elseif engine:KeyPressed(34) then --> VK_NEXT camera:SetPan(camera:GetPan() + 0.1 * engine:time_step()) end end ---------------------------------------------------------------------------------------- -- function: cameramove -- purpose: controls cameramove in lua -- if first call from engine > init lua -------------------------------------------------------------------- function GameInit() print("\nGame init") gImage:Load("items.png.pcx#1#1#32#32") -- load an image mouse_map(gImage:Handle()) -- set mouse_map if gModel then -- if gModel exists, set lightrange to a default value gModel:SetLightRange(0) gModel:SetScaleX(1) gModel:SetScaleY(1) gModel:SetScaleZ(1) end gInitialized = 1 -- initialized print("\nGame init done") end ---------------------------------------------------------------------------------------- -- function: MainStep() -- purpose: is called by the engine every frame -------------------------------------------------------------------- function MainStep() if (gInitialized == 0) then GameInit() end cameramove() engine:draw_text("LUA: <h>elp",250,250,255,25,10) local x, y = engine:GetMousePos() local l, m, r = engine:GetMouseButtons() -- engine:SetMousePos(x + 5, y + 5) engine:draw_text("LUA:Mouse: "..x..":"..y,50,100,255,25,10) engine:draw_text("LUA:MButt:"..l..":"..m..":"..r,50,120,255,25,10) local h = EntityClass(engine:ObjectUnderMouse()) if (h:Handle()>0) then engine:draw_text("LUA:I am under the mouse",50,150,255,25,10) if (gObjectUnderMouse) then DrawBoundingBox(gObjectUnderMouse:Handle()) end gObjectUnderMouse = h end local t = Client_GetTicks() local iTimeSinceLastFrame = gLastFrameTime and (t - gLastFrameTime) if engine:KeyPressedByName("h") then engine:draw_text("LUA:INFO: reload script with <r>",250,270,255,25,10) engine:draw_text("LUA:INFO: camera up with <cuu>",250,290,255,25,10) engine:draw_text("LUA:INFO: camera down with <cud>",250,310,255,25,10) engine:draw_text("LUA:INFO: resize entity <s>",250,330,255,25,10) engine:draw_text("LUA:INFO: sound with <F1>",250,350,255,25,10) -- engine:draw_text("LUA:INFO: reload script with <r>",250,370,255,25,10) end if engine:KeyHitByName("F1")>0 then gSound:Play(100,100) end if engine:KeyHitByName("F2")>0 then gSound:Pause() end if engine:KeyHitByName("F3")>0 then gSound:Start() end if engine:KeyHitByName("s")>0 then if gModel then -- if gModel exists, set lightrange to a default value gModel:SetScaleX(1) gModel:SetScaleY(1) gModel:SetScaleZ(1) end end --print("\n75:",engine:KeyHit(75)) --print("\nAA:",engine:KeyHit(30)) gLastFrameTime = Client_GetTicks() end