Jump to content

Monthly Script Challenge Nov 16


Thirsty Panther
 Share

Recommended Posts

Welcome to the first Monthly Script Challenge.

 

Each Month I will set a challenge for gifted Leadwerkers to solve. I will provide a map as a starting point. Once you have perfected your script you re-post your map to this thread. At the end of the month I will go through all the entries and judge the winner. I will then place the winning map on the Workshop so others can learn from them.

 

Rules.

 

Entries must be your own work.

Entries must be submitted before the end of the month ( November).

Any assets you use must be your own or Royalty free.

The map that you submit can be used by others for commercial use.

Have fun.

 

November Challenge

 

 

Leadwerks terrain maps can cover as much as 16 square kms. We need a way for the player to be able to cover this quickly. So your challenge for this month is a Jetpack script.

Jetpacks have been used in games such as Planetside 2, Tribes ascend and Section 8.

 

The map I have provided is very simple. Two platforms and a FPS player prefab. Your Jetpack should be powerful enough for the player to reach the second platform. You should also include fuel into your script and a way for the player to refuel.

 

To help I've included 4 sound effects. Three Jetpack sounds and one refueling sound. Even if you can't complete your script you still get to keep these to use in your own projects.

 

The November Map.

 

How you implement your script is up to you. You can alter the FPS player script or add a separate script.

Remember the winning script should not only solve the problem but should also have comprehensive comments within the script so that new users can learn from your script.

 

Prize

 

Currently I have no prize to give. Your reward will be admiration of your fellow Leadwerkers and being the first winner of the Monthly Script Challenge.

 

If any person or company would like to donate or sponsor the Challenge you can contact me on this forum.

 

If you have any ideas or thoughts on the Challenge please feel free to comment. This is the first time I've run anything like this and I want it to be successful and useful to the community.

 

Looking forward to your submissions.

  • Upvote 13
Link to comment
Share on other sites

  • 3 weeks later...

lwnov16challenge_screen1.png

 

Here you go. Wasn't really sure how to best package it all up. Put what I could off in a separate addons directory though it relies on parts of FPS hud materials and sounds.

 

Uploaded an EXE build package: https://dl.dropboxusercontent.com/u/67692508/leadwerks/leadwerks_nov_16_challenge/lw_nov_16_jetpack_challenge_exe.zip

and the whole project: https://dl.dropboxusercontent.com/u/67692508/leadwerks/leadwerks_nov_16_challenge/lw_nov_16_jetpack_challenge_project.zip

Main script is MDG_JP_FPSPlayer.lua

 

Main desktop has some problems so had to do some final bits on my laptop intel graphics which is often a bit weird. You may get massive particles for the jetpack smoke.

 

Enjoyed the challenge I there is a good chance I'll base my Christmas game on the work done here so thanks for setting up the challenge.

  • Upvote 3
Link to comment
Share on other sites

Jetpack, skiing and shooting with inheritance.

dl.dropboxusercontent.com/s/an1lrw57r2u1yza/ClansArise.7z

 

 

Player script

 


Script.health = 100

Script.maxHealth = 100

Script.mouseSensitivity = 15

Script.camSmoothing = 2

Script.moveSpeed = 2.5

Script.speedMultiplier = 1.5

Script.strafeSpeed = 4

Script.playerHeight = 1.8

Script.eyeheight=0.8

Script.input={}

Script.mouseDifference = Vec2(0,0)

Script.playerMovement = Vec3(0,0,0)

 

Script.energy=100

 

--This function will be called when an entity is loaded in a map. Use this for intitial setup stuff.

function Script:Start()

 

self.camRotation = self.entity:GetRotation(true)

 

--create jetpack sound source

local jetpackSound = Sound:Load("Sound/MSC Nov 16 Sound Effects/Jet Pack Loop 3.wav")

self.jetpackSource = Source:Create()

self.jetpackSource:SetSound(jetpackSound)

self.jetpackSource:SetLoopMode(true)

self.jetpackSource:SetVolume(0)

self.jetpackSource:Play()

 

self.entity:SetPickMode(0) --don't shoot yourself

 

--Set the type for this object to player

self.entity:SetKeyValue("type","player")

 

--Create a camera

self.camera = Camera:Create()

self.camera:SetFOV(80)

self.camera:SetRange(0.05,1000)

self.camera:SetMultisampleMode((System:GetProperty("multisample","1")))

 

--Set the camera's rotation to match the player

self.camera:SetRotation(self.entity:GetRotation(true))

 

--Set the camera position at eye height

self.camera:SetPosition(self.entity:GetPosition(true)+Vec3(0,self.eyeheight,0))

 

--Create listener

self.listener = Listener:Create(self.camera)

 

 

---------------------------------------------------------------------------

--We want the player model visible in the editor, but invisible in the game

--We can achieve this by creating a material, setting the blend mode to make

--it invisible, and applying it to the model.

---------------------------------------------------------------------------

local material = Material:Create()

material:SetBlendMode(5)--Blend.Invisible

self.entity:SetMaterial(material)

material:Release()

self.entity:SetShadowMode(0)

 

local window = Window:GetCurrent()

local context = Context:GetCurrent()

window:SetMousePosition(Math:Round(context:GetWidth()/2), Math:Round(context:GetHeight()/2))

 

self.disk = self.entity:FindChild("spinfusor"):FindChild("disk")

self.weapon = Pivot:Create() --detach weapon to move it separately

self.weapon:SetPosition(self.camera:GetPosition(true),true)

self.weapon:SetRotation(self.camera:GetRotation(true),true)

self.entity:FindChild("spinfusor"):SetParent(self.weapon)

 

self.jetpackParticles = self.entity:FindChild("particles")

tolua.cast(self.jetpackParticles,"Emitter")

self.jetpackParticles:Pause()

 

self.camera:SetRotation(self.camRotation)

 

self.mainFont=Font:Load("Fonts/arial.ttf",50)

end

 

 

function Script:UpdateWorld()

local window = Window:GetCurrent()

local context=Context:GetCurrent()

 

if window:KeyHit(Key.P) then --enable/disable debug view

if self.debugCameraMode then

self.camera:SetDebugPhysicsMode(false)

else

self.camera:SetDebugPhysicsMode(true)

end

self.debugCameraMode=not self.debugCameraMode

end

 

--Mouse look

self.currentMousePos = window:GetMousePosition()

window:SetMousePosition(Math:Round(context:GetWidth()/2), Math:Round(context:GetHeight()/2))

self.currentMousePos.x = Math:Round(self.currentMousePos.x)

self.currentMousePos.y = Math:Round(self.currentMousePos.y)

 

if self.mousezpos==nil then self.mousezpos=0 end

self.mouseDifference.x = Math:Curve(self.currentMousePos.x - Math:Round(context:GetWidth()/2),self.mouseDifference.x,3)

self.mouseDifference.y = Math:Curve(self.currentMousePos.y - Math:Round(context:GetHeight()/2),self.mouseDifference.y,3)

self.camRotation.x = Math:Clamp(self.camRotation.x + self.mouseDifference.y / self.mouseSensitivity,-90,90)

self.camRotation.y = self.camRotation.y + (self.mouseDifference.x / self.mouseSensitivity)

 

--Set the camera angle

self.camera:SetRotation(self.camRotation)

 

--position weapon at camera with slight delay

self.weapon:SetPosition(self.camera:GetPosition(true), true)

local a = Vec3(0,0,0)

a.x = Math:CurveAngle(self.camera:GetRotation(true).x, self.weapon:GetRotation(true).x, 2)

a.y = Math:CurveAngle(self.camera:GetRotation(true).y, self.weapon:GetRotation(true).y, 2)

a.z = Math:CurveAngle(self.camera:GetRotation(true).z, self.weapon:GetRotation(true).z, 2)

self.weapon:SetRotation(a, true)

 

 

if window:MouseHit(1) then

self:Fire()

end

 

if window:KeyHit(Key.R) then

System:GCSuspend()

World:GetCurrent():Clear()

Map:Load("Maps/MSC Nov16.map")

System:GCResume()

end

 

self.disk:SetRotation(self.disk:GetRotation(false)+Vec3(0,15,0),false) --rotate disk inside spinfusor

 

end

 

 

 

function Script:UpdatePhysics()

 

local window = Window:GetCurrent()

 

--Player Movement

local movex=0

local movez=0

self.input[0]=0

self.input[1]=0

if window:KeyDown(Key.W) then self.input[1]=self.input[1]+1 end

if window:KeyDown(Key.S) then self.input[1]=self.input[1]-1 end

if window:KeyDown(Key.D) then self.input[0]=self.input[0]+1 end

if window:KeyDown(Key.A) then self.input[0]=self.input[0]-1 end

 

local playerMovement = Vec3(0)

playerMovement.x = self.input[0] * self.moveSpeed

playerMovement.z = self.input[1] * self.moveSpeed

 

--This prevents "speed hack" strafing due to lazy programming

if self.input[0]~=0 and self.input[1]~=0 then

playerMovement = playerMovement * 0.70710678

end

 

local velocity=playerMovement*3 --speed that we want to get (if walking)

local currentSpeed = self.entity:GetVelocity(false)

currentSpeed.y=0 --we don't want to affect the gravity so we don't include it in calculations

local extraSpeed = velocity-currentSpeed --speed that we lack

velocity=velocity+extraSpeed*200 --adding lacking speed

 

local pickinfo=PickInfo() --check if airborne

local p1=self.entity:GetPosition(true)

local onTheGround = World:GetCurrent():Pick(p1,p1-Vec3(0,1,0),pickinfo)

 

if not window:KeyDown(Key.Space) and onTheGround then --apply walking force only if walking on the ground

self.entity:AddForce(velocity,false)

end

 

if window:KeyDown(Key.Space) then self.entity:SetFriction(0,0) --skiing

else self.entity:SetFriction(1,1) end

 

local jetPackActive = false

if window:MouseDown(2) and self.energy>1 then --jetpack

local jetpackForce=playerMovement*200

jetpackForce.y=700

self.entity:AddForce(jetpackForce, false)

jetPackActive=true --for sound and particles

self.energy=self.energy-1

end

self.energy=self.energy+0.4

if self.energy > 100 then self.energy = 100 end

if self.energy < 0 then self.energy = 0 end

--end of movement code

 

--Position camera at correct height and playerPosition

local playerPos = self.entity:GetPosition()

local newCameraPos = self.camera:GetPosition()

--local playerTempHeight = ((self:IsCrouched() == 1) and crouchHeight or playerHeight)

newCameraPos = Vec3(playerPos.x, newCameraPos.y ,playerPos.z)

 

if newCameraPos.y<playerPos.y + self.eyeheight then

newCameraPos.y = Math:Curve(playerPos.y + self.eyeheight, newCameraPos.y, self.camSmoothing)

else

newCameraPos.y = playerPos.y + self.eyeheight

end

 

self.camera:SetPosition(newCameraPos)

 

self.entity:PhysicsSetRotation(0,self.camera:GetRotation(true).y,0) --keeping player straight

 

--jetpack particles and sound

if jetPackActive then

self.jetpackParticles:Play()

self.jetpackSource:SetVolume(self.jetpackSource:GetVolume()+0.2)

else

self.jetpackParticles:Pause()

self.jetpackSource:SetVolume(self.jetpackSource:GetVolume()-0.2)

end

if self.jetpackSource:GetVolume()>1 then self.jetpackSource:SetVolume(1) end

if self.jetpackSource:GetVolume()<0 then self.jetpackSource:SetVolume(0) end

end

 

 

 

function Script:Fire()

local disk = Prefab:Load("Prefabs/Disk.pfb")

disk:SetPosition(self.camera:GetPosition(true),true)

disk:SetRotation(self.camera:GetRotation(true),true)

disk.script.inheritance=self.entity:GetVelocity()/80

end

 

function Script:PostRender(context)

context:SetFont(self.mainFont)

context:SetBlendMode(Blend.Alpha)

context:SetColor(1,1,1,1)

 

context:DrawRect(context:GetWidth()/2-2,context:GetHeight()/2-2,4,4) --crosshair

local barLength = self.energy*2 --energy bar

context:DrawRect(context:GetWidth()/2-barLength/2,context:GetHeight()-10,barLength,6)

if Window:GetCurrent():KeyDown(Key.Space) then --skiing speed

local speed = Math:Round(self.entity:GetVelocity():Length())..""

context:DrawText(speed,context:GetWidth()/2-self.mainFont:GetTextWidth(speed)/2, context:GetHeight()-15-self.mainFont:GetHeight())

end

end

 

  • Upvote 4
Link to comment
Share on other sites

Here is my submission!

This is my first time using dropbox and all that, so tell me if something goes horribly wrong.smile.png

Here is the script and assets, you should put it under the Models folder of a project. It should have a little refuel station model I made.

https://www.dropbox.com/sh/itobxiovteuhhaz/AACstVsTrfUQ9Gqrs8utPLMUa?dl=0

Here is a neat map that I made.

https://www.dropbox.com/s/2zhr18sof337j5d/MSC%20Nov16.map?dl=0

The map and script use textures and models from the first link, so it will not work if copied incorrectly. If something does go wrong, just look at the Player.lua from the first link, and get rid of the textures and stuff. If it does work, then yay.

Thanks for the awesome script challenge!

  • Upvote 4
Link to comment
Share on other sites

November challenge is now CLOSED.

 

Thanks to the Leadwerkers who have submitted entries. I'll go thru the entries over the weekend and will announce the winner next week.

 

I have decided to postpone the December Script Challenge. The Winter Games Tournament is about to start and I'm sure everyone will be to busy making outstanding games.

 

Still looking for a sponsor to provide prize/prizes for the Script Challenge. If anyone can help out please contact me thru these forums.

Link to comment
Share on other sites

After much thought and play testing the winner is.....

 

GarlicWaffle.

 

Congratulations on being the inaugural winner of the Monthly Script Challenge.

 

It was a tough job deciding between the three entrants. All produce great maps with good Jetpack scripts. In fact the maps are more like mini games than maps.

 

I liked Genebris sandbox style map where you can just go flying across the map trying out different things. Great fun.

 

Mdgunns map or more accurately levels where also fun. I even managed to finish the 2nd level without landing on the platforms. Try it out for yourself.

 

I decide on GarlicWaffle in the end because his script contained very detailed comments which should help new users work out what is happening in the script. GarlicWaffle also wins the prize for the most useful second post on the Leadwerks forums ever. Great work.

 

The Monthly Script Challenge is taking a small break as the Winter Games Challenge is on. Maybe we will see some games making use of the Jetpack scripts.

  • Upvote 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...