Jump to content

Defranco

Members
  • Posts

    60
  • Joined

  • Last visited

Posts posted by Defranco

  1. Hey,

     

    I'm wondering if its possible to have the NavMesh generate on imported MDL's set as prop or scene in the editor and set as Poly Mesh physics?

     

    A year ago I used to always have to create invisible texture blocks over the MDL surface for the NavMesh to work on it, is this still the case for 4.0 - I was reading up yesterday that the editor should be able to handle NavMesh on MDL's if the physics is set right.

     

    I wasn't able to get it working. - I tried both "Nav Obstacle" checked and unchecked.

     

    Any insights?

     

    Thanks,

    Erika

  2. Hey everyone,

     

    I've been reading up on multiple tutorials for FPS weapon pick-ups and guns, and I'd like to establish melee weapons instead - now I can get it to work with 3.2, but I can't get it to work for 4.0 using the same steps.

     

    Here are some of the resources I've been using:

     

    Rick's Weapon Pickup - https://www.youtube.com/watch?v=VWBGtJ7NQ4Y

    HippoKittie melee code - http://www.leadwerks.com/werkspace/topic/11251-melee-code-for-you-guys/page__hl__melee

    Genebris Collission based Melee combat topic - http://www.leadwerks.com/werkspace/topic/11519-collision-based-melee-combat/page__hl__melee

    HippoKittie thread on melee weapon (specifically Gladious one) - http://www.leadwerks.com/werkspace/topic/10472-enemy-ai-and-melee-weapons/page__hl__melee

     

    Now the last one is the one I managed to get working a year ago back in 3.2 - but now I can't even get any of them to work with 4.0.

     

    WeaponPickup.lua and stuff (default) doesn't seem to be working at all even with the default pistol gun prefab.

     

    I created a trigger box - attached script - following Ricks older weapon pickup guide - and I get 2 different errors, Exception Error which crashes the editor, and another one - then when it does load up, no weapon shows up in screen.

     

    I've also tried attaching the weapon prefab directly to my player character - it doesn't load up with anything - and if I use the default pistol prefab, it fails to load.

     

    I'm guessing that somewhere in the code (because they're older) - its not needed to be adapted to work with 4.0.

     

    The below are all scripts written by others, that have worked in previous versions that I'm attempting to get working with the new build.

     

     

    Below is the FPSMeleeWeapon.lua

     

    import "Scripts/AnimationManager.lua"
    Script.index=1--int "Weapon slot"
    --Script.autogive=false--bool "Autogive"
    Script.offset=Vec3(0,0,0)--Vec3 "Offset"
    Script.rotation=Vec3(0,0,0)--Vec3 "Rotation"
    Script.maxswayamplitude=0.01
    Script.amplitude=0
    Script.swayspeed=0
    Script.timeunits=0
    Script.smoothedposition=Vec3(0)
    Script.smoothedrotation=Vec3(0)
    Script.verticalbob=0
    Script.jumpoffset=0
    Script.strikedelay=500--int "Strike delay"
    Script.landoffset=0
    Script.firetime=0
    Script.refirerate=100--int "Refire rate"
    Script.bulletrange=1000
    Script.bulletforce=500--float "Force"
    Script.bulletdamage=10--int "Damage"
    Script.automatic=false--bool "Automatic"
    Script.fire1soundfile=""--path "Fire sound 1" "Wav File (*wav):wav|Sound"
    Script.fire2soundfile=""--path "Fire sound 2" "Wav File (*wav):wav|Sound"
    Script.fire3soundfile=""--path "Fire sound 3" "Wav File (*wav):wav|Sound"
    Script.ricochet1soundfile=Sound:Load("Sound/Ricochet/bullet_impact_dirt_01.wav")
    Script.ricochet2soundfile=Sound:Load("Sound/Ricochet/bullet_impact_dirt_02.wav")
    Script.ricochet3soundfile=Sound:Load("Sound/Ricochet/bullet_impact_dirt_03.wav")
    Script.firespeed=0.05--float "Fire speed"
    Script.currentaction=nil
    function Script:Start()
    if self.started then return end
    self.started=true
    
    self.entity:SetPickMode(0,true)
    self.entity:SetPosition(self.offset)
    self.entity:SetAnimationFrame(0,1,"fire")
    
    self.entity:Hide()
    
    self.entity:SetShadowMode(0)
    self.entity:SetOcclusionCullingMode(false)
    
    self.currentaction=nil
    self.muzzle = self.entity:FindChild("blade")
    
    self.sound={}
    self.sound.fire={}
    if self.fire1soundfile~="" then self.sound.fire[1]=Sound:Load(self.fire1soundfile) end
    if self.fire2soundfile~="" then self.sound.fire[2]=Sound:Load(self.fire2soundfile) end
    if self.fire3soundfile~="" then self.sound.fire[3]=Sound:Load(self.fire3soundfile) end
    self.sound.ricochet={}
    self.sound.ricochet[1]=Sound:Load("Sound/Ricochet/bullet_impact_dirt_01.wav")
    self.sound.ricochet[2]=Sound:Load("Sound/Ricochet/bullet_impact_dirt_02.wav")
    self.sound.ricochet[3]=Sound:Load("Sound/Ricochet/bullet_impact_dirt_03.wav")
    
    self.entity:SetPickMode(0)
    
    self.animationmanager = AnimationManager:Create(self.entity)
    self.originalposition = self.entity:GetPosition()
    self.originalrotation = self.entity:GetRotation()
    
    self.emitter={}
    --Debris emitter - This will throw chunks off of walls and make it look like they are breaking
    self.emitter[0]=Emitter:Create()
    self.emitter[0]:SetMaterial("Materials/Effects/default.mat")
    self.emitter[0]:SetEmissionVolume(0.05,0.05,0.05)
    self.emitter[0]:SetColor(0.1,0.1,0.1,1)
    self.emitter[0]:SetVelocity(1.5,1.5,1.5,1)
    self.emitter[0]:SetParticleCount(10)
    self.emitter[0]:SetReleaseQuantity(10)
    self.emitter[0]:SetMaxScale(0.3)
    self.emitter[0]:SetDuration(1000)
    self.emitter[0]:SetAcceleration(0,-12,0)
    self.emitter[0]:Hide()
    
    --Blood emitter - This will provide a visual cue when an enemy is shot
    self.emitter[2]=Emitter:Create()
    self.emitter[2]:SetColor(1,1,1,0.25)
    self.emitter[2]:SetEmissionVolume(0.1,0.1,0.1)
    self.emitter[2]:SetVelocity(0.3,0.3,0.3,1)
    self.emitter[2]:SetParticleCount(3)
    self.emitter[2]:SetReleaseQuantity(3)
    self.emitter[2]:SetMaxScale(4)
    self.emitter[2]:SetDuration(2500)
    self.emitter[2]:AddScaleControlPoint(0,0.5)
    self.emitter[2]:AddScaleControlPoint(1,1)
    self.emitter[2]:SetRotationSpeed(10)
    self.emitter[2]:SetMaterial("Materials/Effects/bloodspatter.mat")
    self.emitter[2]:SetColor(1,1,1,0.25)
    self.emitter[2]:SetParticleCount(3)
    self.emitter[2]:SetReleaseQuantity(3)
    self.emitter[2]:SetDuration(200)
    self.emitter[2]:SetEmissionVolume(0,0,0)
    self.emitter[2]:SetMaxScale(1)
    self.emitter[2]:SetRotationSpeed(10)
    self.emitter[2]:AddScaleControlPoint(0,0)
    self.emitter[2]:AddScaleControlPoint(1,1)
    self.emitter[2]:SetVelocity(0,0,0,0)
    self.emitter[2]:SetVelocity(0,0,0,1)
    self.emitter[2]:Hide()
    
    --[[if self.autogive then
    local player,n
    for n,player in ipairs(players) do
    player:AddWeapon(self,self.index)
    end
    end]]--
    self.entity:Hide()
    end
    function Script:Hide()
    self.entity:Hide()
    end
    function Script:FindScriptedParent(entity,func)
    while entity~=nil do
    if entity.script then
    if type(entity.script[func])=="function" then
    if entity.script.enabled~=false then
     return entity
    else
     return nil
    end
    end
    end
    entity = entity:GetParent()
    end
    return nil
    end
    function Script:BeginJump()
    self.jumpoffset = -180
    end
    function Script:BeginLand()
    self.landoffset = -180
    end
    function Script:EndFire()
    self.currentaction=nil
    end
    function Script:Strike()
    local pickinfo=PickInfo()
    local pos = self.player.camera:GetPosition(true)
    local dir = Transform:Normal(0,0,0.5,self.player.camera,nil)
    
    if self.entity.world:Pick(pos,pos+dir,pickinfo,0,true,Collision.Projectile) then	
    --Find first parent with the Hurt() function
    local enemy = self:FindScriptedParent(pickinfo.entity,"Hurt")
    if enemy~=nil then
    if enemy.script.health>0 then
    enemy.script:Hurt(self.bulletdamage,self.player)
    end
    
    --Blood emitter
    e = self.emitter[2]:Instance()
    e = tolua.cast(e,"Emitter")
    e:Show()
    e:SetLoopMode(false,true)
    e:SetPosition(pickinfo.position+pickinfo.normal*0.1)
    e:SetVelocity(0,0,0)
    
    else
    
    --Add a temporary particle emitter for bullet effects
    local e
    
    e = self.emitter[0]:Instance()
    e = tolua.cast(e,"Emitter")
    e:Show()
    e:SetLoopMode(false,true)
    e:SetPosition(pickinfo.position)
    local v=3
    e:SetVelocity(pickinfo.normal.x*v,pickinfo.normal.y*v,pickinfo.normal.z*v,0)
    
    --Play bullet impact noise
    e:EmitSound(self.sound.ricochet[math.random(#self.sound.ricochet)],30)
    
    if pickinfo.entity~=nil then
    
    --Add impulse to the hit object
    if pickinfo.entity:GetMass()>0 then
     --local force = pickinfo.normal*-1*self.bulletforce
     local dir = Transform:Normal(0,0,1,self.player.camera,nil)
     local force = dir * self.bulletforce * math.max(0,-pickinfo.normal:Dot(dir))
     --force = force * math.max(0,-pickinfo.normal:Dot(d))--multiply by dot product of velocity and collided normal, to weaken glancing blows
     pickinfo.entity:AddPointForce(force,pickinfo.position)
    end
    end
    end
    end
    end
    function Script:Fire()
    if self.player.weaponlowerangle==0 then
    local currenttime=Time:GetCurrent()
    if self.lastfiretime==nil then self.lastfiretime=0 end
    if currenttime-self.lastfiretime>self.refirerate then
    if self.currentaction==nil then
    self.lastfiretime = currenttime
    self.currentaction="strike"
    if #self.sound.fire>0 then
     self.sound.fire[math.random(#self.sound.fire)]:Play()	
    end
    self.firetime = Time:GetCurrent()
    self.animationmanager:SetAnimationSequence("Fire",self.firespeed,300,1,self,self.EndFire)
    end
    end
    end
    end
    function Script:UpdateWorld()
    if self.currentaction=="strike" then
    local t=Time:GetCurrent()
    if t-self.firetime>self.strikedelay then
    self:Strike()
    self.currentaction="fire"
    end
    end
    end
    function Script:Draw()
    
    local t = Time:GetCurrent()
    
    local jumpbob = 0
    
    if self.jumpoffset<0 then
    jumpbob = (Math:Sin(self.jumpoffset))*0.01
    self.jumpoffset = self.jumpoffset + 8*Time:GetSpeed()
    end
    
    if self.landoffset<0 then
    jumpbob = jumpbob + (Math:Sin(self.landoffset))*0.01
    self.landoffset = self.landoffset + 10*Time:GetSpeed()
    end
    
    --Animate the weapon
    local bob = 0;
    local speed = math.max(0.1,self.player.entity:GetVelocity():xz():Length())
    if self.player.entity:GetAirborne() then speed = 0.1 end
    self.swayspeed = Math:Curve(speed,self.swayspeed,20)
    self.swayspeed = math.max(0.5,self.swayspeed)
    self.amplitude = math.max(2,Math:Curve(speed,self.amplitude,20))
    self.timeunits = self.timeunits + self.swayspeed*4*Time:GetSpeed()
    local sway = math.sin(self.timeunits/120.0) * self.amplitude * self.maxswayamplitude
    bob = (1-math.cos(self.timeunits/60.0)) * self.maxswayamplitude * 0.1 * self.amplitude
    local campos = self.player.camera:GetPosition(true)
    
    self.smoothedposition.x = campos.x
    self.smoothedposition.y = Math:Curve(campos.y,self.smoothedposition.y,2)
    self.smoothedposition.z = campos.z
    self.entity:SetRotation(self.rotation)
    self.entity:SetPosition(sway*self.entity.scale.x,bob+jumpbob,0)
    self.entity:Translate(self.offset,false)
    
    self.animationmanager:Update()
    end
    function Script:Release()
    if self.emitter~=nil then
    self.emitter[0]:Release()
    self.emitter[2]:Release()
    self.emitter=nil
    end
    ReleaseTableObjects(self.sound)
    end
    

     

     

    And this is one of the pickup codes; PickupWeapon.lua

     

    Script.vwepfile=""--path "VWep" "Prefab (*pfb):pfb|Prefabs"
    --Script.vwep=nil--entity
    function Script:Start()
    if self.vwepfile~="" then
    local prefab = Prefab:Load(self.vwepfile)
    if prefab~=nil then
    if prefab.script~=nil then
    self.vwep = prefab.script
    else
    prefab:Release()
    end
    end
    end
    end
    function Script:Use(player)
    if self.vwep then
    if type(player.AddWeapon)=="function" then
    if player.weapons~=nil then
    if player.weapons[self.index]==nil then
     player:AddWeapon(self.vwep)
     self.entity:Hide()
    end
    end
    end
    end
    end
    function Script:Collision(entity, position, normal, speed)
    if self.vwep then
    if entity.script~=nil then self:Use(entity.script) end
    end
    end
    

     

    This is PART of my FPSPlayer.lua file

     

    --Load the default weapon, if one is set
    if self.weaponfile~="" then
    local entity = Prefab:Load(self.weaponfile)
    if entity~=nil then
    if entity.script~=nil then
    entity.script.player = self
    self.weapon = entity.script
    self.weapon.entity:SetParent(self.camera)
    self.weapon.entity:SetRotation(0,0,0)
    if self.weapon.offset~=nil then
     self.weapon.entity:SetPosition(self.weapon.offset)
    else
     self.weapon.entity:SetPosition(0,0,0)
    end
    end
    end
    end
    
    

     

    I also have a script called GameRules.lua (I think this came with LEX extension template---)

     

    ---------------------------------------------------
    --[[Weapon Slot Defines: Set Weapon Slots ]]--
    ---------------------------------------------------
    WpnSlot={}
    WpnSlot.Melee = 1
    WpnSlot.Pistol = 2
    WpnSlot.Shotgun = 3
    WpnSlot.Smg= 4
    WpnSlot.M4 = 5
    ------------------------------------
    --[[End of Weapon Slot Defines ]]--
    ------------------------------------
    ---------------------------------------------------
    --[[Collsion Defines: Make new Collision Rules ]]--
    ---------------------------------------------------
    Collision.CharacterBlocker = 9
    Collision.PropBlocker = 10
    Collision.PickInfo = 11
    Collision.PickedUpProp = 12
    Collision.Item = 13
    -- Props can activate triggers.
    Collision:SetResponse(Collision.Prop, Collision.Trigger, Collision.Trigger)
    
    -- CSG Collisions
    Collision:SetResponse(Collision.CharacterBlocker, Collision.Character, Collision.Collide)
    Collision:SetResponse(Collision.PropBlocker, Collision.Prop, Collision.Collide)
    Collision:SetResponse(Collision.PropBlocker, Collision.PickedUpProp, Collision.Collide)
    -- Picked up objects can still collide with triggers, but never characters.
    Collision:SetResponse(Collision.PickedUpProp, Collision.Character, Collision.None)
    Collision:SetResponse(Collision.PickedUpProp, Collision.Scene, Collision.Collide)
    Collision:SetResponse(Collision.PickedUpProp, Collision.Prop, Collision.Collide)
    Collision:SetResponse(Collision.PickedUpProp, Collision.Trigger, Collision.Trigger)
    Collision:SetResponse(Collision.PickedUpProp, Collision.PickedUpProp, Collision.None)
    
    -- Items
    Collision:SetResponse(Collision.Item, Collision.Character, Collision.Trigger)
    Collision:SetResponse(Collision.Item, Collision.Scene, Collision.Collide)
    Collision:SetResponse(Collision.Item, Collision.Prop, Collision.Collide)
    Collision:SetResponse(Collision.Item, Collision.Trigger, Collision.Trigger)
    Collision:SetResponse(Collision.Item, Collision.PickedUpProp, Collision.None)
    
    -- PickInfo
    Collision:SetResponse(Collision.PickInfo, Collision.Scene, Collision.Collide)
    Collision:SetResponse(Collision.PickInfo, Collision.Prop, Collision.Collide)
    Collision:SetResponse(Collision.PickInfo, Collision.PickedUpProp, Collision.Collide)
    Collision:SetResponse(Collision.PickInfo, Collision.Trigger, Collision.None)
    Collision:SetResponse(Collision.PickInfo, Collision.Item, Collision.Collide)
    ---------------------------------
    --[[End of Collsion Defines ]]--
    ---------------------------------
    --[[
    Load models onto memory if you wish to "spawn" them later such as npcs,
    or gibs. It's best to do this at a Start function as loading a model in real time
    causes a slow down.
    --]]
    function PrecacheObject(obj)
    if obj == nil then return end
    local ext = FileSystem:ExtractExt(obj)
    if (ext == "mdl") or (ext == "pfb") then
    if (ext == "mdl") then
    local model = Model:Load(obj)
    model:Hide()
    System:Print("Precached model: " ..obj)
    elseif (ext == "pfb") then
    local prefab = Prefab:Load(obj)
    prefab:Hide()
    System:Print("Precached prefab: " ..obj)
    end
    end
    end
    

  3. Hey all,

     

    I've build Navmesh, and have several different models setup (including crawler) with different AI scripts, (including 1 from the FPS default).

     

    In all scenarios, the AI triggers are sort of working (as the debug print/call screen says its looking for player, player in range, etc etc)

     

    However, all models are running in the same spot without actually moving. Navmesh seems to be looking fine.

     

    I've tried setting physics to Polymesh & Polyhydron - in 1 case the model topples over and falls down...

     

    I have everything enabled, collision type to Character - and mass i've tried everything from 5, 20, 50, 100, etc

     

     

    Will get screen shots, and code samples in a sec...

  4. Hey,

     

    I've been trying to adapt as much scripts as possible to work with the 4.0 version, and I've come across some issues with the Health Bar script,

     

    The color function doesn't work. The bars stay black.

     

    Script.offset = Vec2(0,0) --Vec2 "Offset"
    Script.size = Vec2(160, 25) --Vec2 "Size"
    Script.backgroundColor = Vec4() --color "Background color"
    Script.healthbarColor = Vec4() --color "HealthBar color"
    Script.overlayPath = "" -- path "Overlay" "Tex file (*tex):tex"
    Script.overlay = nil
    Script.player = nil
    Script.backgroundColorFractioned = nil
    Script.healthbarColorFractioned = nil
    
    function Script:Start()
    self.player = self.entity:GetParent()
    if self.overlayPath ~= "" then
    self.overlay = Texture:Load(self.overlayPath)
    end
    
    
    --background
    local c = self.backgroundColor
    self.backgroundColorFractioned = Vec4(c.x/255, c.y/255, c.z/255, c.w/255)
    
    c = self.healthbarColor
    self.healthbarColorFractioned = Vec4(c.x/255, c.y/255, c.z/255, c.w/255)
    end
    
    
    function Script:PostRender(context)
    -- Background
    context:SetColor(self.backgroundColorFractioned)
    context:DrawRect(self.offset.x, context:GetHeight() - self.offset.y, self.size.x, self.size.y)
    
    -- Healthbar
    context:SetColor(self.healthbarColorFractioned)
    local healthFactor = self.player.script.health / self.player.script.maxHealth
    context:DrawRect(self.offset.x,context:GetHeight() - self.offset.y, self.size.x * healthFactor, self.size.y)
    
    
    --Draw overlay
    if self.overlay ~= nil then
    context:SetBlendMode(Blend.Alpha)
    context:SetColor(1,1,1,1)
    context:DrawImage(self.overlay, 0, context:GetHeight() - self.overlay:GetHeight())
    context:SetBlendMode(Blend.Solid)
    end
    end

     

    ROQc23x.png

     

    Htll9SY.jpg

  5. This doesn't work with LE 4.0 - constantly gives errors. Version 40 not supported when trying to test or debug..

     

    Edit: just to clarify - works with default and brand new creation of project. But once you edit anything, or "save" specifically. Gives this error.

     

    Create new project - loads up. Hit test, works. Add a box. Hit save, hit test, doesn't work. Seems like saving over the default map breaks it for LE 4.0

     

     

    Edit 2: Possibly found a solution - delete all the files (not folders) in the project/yourprojectname folder such and doing a project - updates. It replaces the TEX original files with your owns current version. Works now.

  6. Hey everyone,

     

    I'm wondering if anyone knows of a updated tutorial or could assist with integrating the newest version of NeosisGUI with the newest version of Leadwerks.

     

    I played around with NeosisGUI way back around 16 months ago and got it working back then with Leadwerks version from that time, however I've reset my project over and the steps to implement (from the old tutorial) aren't valid anymore with all the updates.

     

    Any assistance would be greatly appreciated.

     

    Erika

  7. I'm not 100% how to reproduce the error.

     

    After playing around with some of the backup saves (thank goodness for autosaves!! <3 <3 )

     

    I believe this to just be a corrupt save.

     

    My start.map was from 8:02 pm last night.

    my backup367.map.bak was from 7:59pm last night. I renamed backup376.map.bak to just backup367.map and loaded it (a 3 minute earlier save) and it doesn't give the error.

     

    There's no difference between the start.map and the several backups from before that as no work additions were done and no changes were done. I think perhaps maybe it failed to fully save and caused a corrupt file.

     

     

  8. Good day,

     

    Program was working fine yesterday, logged on today and it gives this error when opening the start.map . after pressing OK, the program shuts off immediately.

     

    Exception_Access_Violation

    Error: Top-level entity cannot be a bone.

     

    This error is occurring in Leadwerks 3.2 standard edition.

     

    On windows 7, with a Nvidia graphics card 650M model.

     

    When opening the CPP files and debugging, or running the map on Microsoft Visual Studio 2013, it gives no errors there.

     

    The error is on Leadwerks Editor.

  9. I'm playing around and still learning lua;

     

    Am I on the right track in thinking that something along the lines of the below script could be used to toggle open/close an inventory?

     

    A player would press the key " i " in game and it would open/close the inventory.

     

     

     

     

    --Toggle the inventory on and off

    if window:KeyHit(Key.i) then

    self.sound.inventory:Play()

    if self.inventory:Hidden() then

    self.inventory:Show()

    else

    self.inventory:Hide()

    end

    end

     

     

    -- then, in the function script start area... a sound would play when toggleing the inventory on or off.

     

    self.sound.inventory=Sound:Load("Sound/Player/inventory_toggle.wav")

     

     

     

     

    -- then at the top for scripts;

     

    Script.inventoryon = false --bool "Inventory on"

     

     

     

    -- then I would need to define what the inventoryon is? ??? -- this is what im working on now, trying to attach it to my inventory.lua script where it has the dimensions/color, etc.

     

     

    self.inventory =

    if self.inventoryon==false then

    self.inventory:Hide()

    end

     

     

     

    Let me know if I have the right sort of idea... I'm trying, hehe

  10. Good day;

     

    I've been following Rick's weapon pickup tutorial to the letter (or I think I have) as well as the adaptation of the code by Macklebee where he changed it from a gun to a melee weapon called Gladious.

     

    I was able to get the pickup script to work when I was using just the Indie version. And I think that when I upgraded to Standard and compiled things in CPP that it perhaps broke something within the scripts. At the moment I'm not proficient enough with coding to fully understand what could be wrong. If someone could take a peak and perhaps point me in the right direction, would be greatly appreciated.

     

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

    --FPSWeapon.Lua - the script that is attached to the prefab of the weapon.

     

    import "Scripts/AnimationManager.lua"

    Script.offset = Vec3(.5,-.5,.3) --vec3 "Offset"

    --used to set the location of the weapon in relationship to the fpsplayer's camera

     

    function Script:Start()

    --self.entity:SetRotation(45,180,0) --cant set it here unless you change the fpsplayer script

    -- fpsplayer script sets the weapons rotation to (0,0,0) after it has been loaded

    self.fired = 0 --

    self.animationmanager = AnimationManager:Create(self.entity)--sets up animationmanager

    end

     

    function Script:Fire() --using this just so i dont have to mess with the fpsplayer script

    self.animationmanager:SetAnimationSequence("swing",0.05,300,1)

    --Parameters = (sequence, speed, blendtime, mode)

    -- sequence equal to "swing" animation in model

    -- speed controls how fast to play animation

    -- blendtime controls how fast it changes from the previous animation

    -- mode controls whether animation plays once or loops.

    end

     

    function Script:Reload() --using this becaue inherent fpsplayer script calls this function when R is hit

    self.animationmanager:SetAnimationSequence("idle",0.05,300,1)

    end

    function Script:BeginJump() -- called from fpsplayer

    end

    function Script:BeginLand() -- called from fpsplayer

    end

     

    function Script:Draw()

    self.entity:SetRotation(45,180,0) --settting the model's rotation to be able to see it

    --Animate the weapon

    self.animationmanager:Update()

    end

     

    function Script:Release()

     

    end

     

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

    --WeaponPickup.Lua - the script that is attached to the trigger that the player steps on.

     

    Script.entered = false

    Script.exited = false

    Script.hadCollision = false

     

    Script.vModel = "" --path

     

    function Script:UpdatePhysics()

    if self.entered then

    if self.hadCollision == false then

    if self.exited == false then

    self.exited = true

    self.component:CallOutputs("TriggerExit")

    self.entered = false

    end

    end

    end

     

    self.hadCollision = false

    end

     

    function Script:Collision(entity, position, normal, speed)

    self.hadCollision = true

     

    if self.entered == false then

    self.component:CallOutputs("TriggerEnter")

    if entity:GetKeyValue("type") == "player" then

    entity.script.weaponfile = self.vModel

    entity.script:LoadWeapon()

    self.entity:Hide()

    end

     

    self.entered = true

    self.exited = false

    end

    end

     

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

    --FPSPlayer.Lua - the script that is attached to the player. Copied only up until the LoadWeapon

     

    import "Scripts/Functions/ReleaseTableObjects.lua"

     

    Script.Camera = nil --entity

    Script.health = 100 --float "Health"

    Script.maxHealth = 100 --float "Max Health"

    Script.mouseSensitivity = 15 --float "Mouse sensitivity"

    Script.camSmoothing = 2 --float "Cam smoothing"

    Script.moveSpeed = 2.5 --float "Move Speed"

    Script.speedMultiplier = 1.5 --float "Run Multiplier"

    Script.strafeSpeed = 4 --float "Strafe Speed"

    Script.playerHeight = 1.8 --float "Player Height"

    Script.jumpForce = 8 --float "Jump Force"

    Script.flashlighton = false --bool "Flashlight on"

    Script.useDistance = 3

    Script.alive=true

    Script.eyeheight=1.6

    Script.footstepwalkdelay = 500

    Script.footsteprundelay = 300

    Script.weaponfile=""--path "Weapon" "Prefab (*.pfb):pfb|Prefabs"

    Script.input={}

    Script.maxcarryweight=5

    Script.throwforce = 500

    Script.isairborne=false

    Script.bloodindex=1

    Script.teamid=1--choice "Team" "Neutral,Good,Bad"

    Script.hurtoffset=Vec3(0)

    Script.smoothedhurtoffset=Vec3(0)

    Script.mouseDifference = Vec2(0,0)

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

    Script.tempJumpForce = 0

     

    --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)

     

    self.image={}

    self.image.crosshair = Texture:Load("Materials/HUD/crosshair.tex")

    self.image.hand = Texture:Load("Materials/HUD/use.tex")

     

    self.image.blood={}

    self.image.blood[1]=Texture:Load("Materials/HUD/blood1.tex")

    self.image.blood[2]=Texture:Load("Materials/HUD/blood2.tex")

    self.image.blood[3]=Texture:Load("Materials/HUD/blood3.tex")

    self.image.blood[4]=Texture:Load("Materials/HUD/blood4.tex")

     

    --Load shared sounds

    self.sound={}--table to store sound in

    self.sound.flashlight=Sound:Load("Sound/Player/flashlight_02_on.wav")

    self.sound.damage={}

    self.sound.damage[1]=Sound:Load("Sound/Impact/body_punch_03.wav")

    self.sound.damage[2]=Sound:Load("Sound/Impact/body_punch_04.wav")

    self.sound.footsteps={}

    self.sound.footsteps.concrete={}

    self.sound.footsteps.concrete.step={}

    local n

    for n=1,4 do

    self.sound.footsteps.concrete.step[n] = Sound:Load("Sound/Footsteps/Concrete/step"..tostring(n)..".wav")

    end

    self.sound.footsteps.concrete.jump = Sound:Load("Sound/Footsteps/Concrete/jump.wav")

     

    self.bloodoverlay={}

     

    self.entity:SetPickMode(0)

     

    --Set the type for this object to player

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

     

    local mass = self.entity:GetMass()

    if self.entity:GetMass()==0 then Debug:Error("Player mass should be greater than 0.") end

     

    --Create a camera

    --self.camera = Camera:Create()

    self.camera = self.Camera

     

    --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))

     

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

     

    self.flashlight = SpotLight:Create()

    self.flashlight:SetParent(self.camera,false)

    self.flashlight:SetPosition(0.2,-0.1,0)

    self.flashlight:SetRotation(10,-3,0)

    self.flashlight:SetConeAngles(25,15)

    self.flashlight:SetShadowMode(Light.Dynamic+Light.Static)

    if self.flashlighton==false then

    self.flashlight:Hide()

    end

     

    self:LoadWeapon()

     

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

    --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.camera:SetRotation(self.camRotation)

     

    end

     

     

     

    function Script:LoadWeapon()

     

     

    --Load the default weapon, if one is set

    if self.weaponfile~="" then

    local entity = Prefab:Load(self.weaponfile)

    if entity~=nil then

    if entity.script~=nil then

    entity.script.player = self

    self.weapon = entity.script

    self.weapon.entity:SetParent(self.camera)

    self.weapon.entity:SetRotation(0,0,0)

    if self.weapon.offset~=nil then

    self.weapon.entity:SetPosition(self.weapon.offset)

    else

    self.weapon.entity:SetPosition(0,0,0)

    end

    end

    end

    end

     

    end

     

     

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

     

    Other things to note;

     

    vModel option does have the pfb file attached under the script

    Shape: None

    Physics: tried both trigger and prop.

     

     

    When I add a weapon.pfb (either the gun or the gladious) to my Player at start-up (when it has FPSPlayer.lua script attached, the weapon has no function, and no animation, just a pfb on screen visuals load.

  11. --This function will be called once when the program starts

    function App:Start()

     

    --Initialize Steamworks (optional)

    Steamworks:Initialize()

     

    --Set the application title

    self.title="MyGame"

     

    --Create a window

    local windowstyle = Window.Titlebar

    if System:GetProperty("fullscreen")=="1" then windowstyle=windowstyle+Window.Fullscreen end

    self.window=Window:Create(self.title,0,0,System:GetProperty("screenwidth","1024"),System:GetProperty("screenheight","768"),windowstyle)

    self.window:HideMouse()

     

    --Create the graphics context

    self.context=Context:Create(self.window,0)

    if self.context==nil then return false end

     

    --Create a world

    self.world=World:Create()

    self.world:SetLightQuality((System:GetProperty("lightquality","1")))

     

    --Load a map

    local mapfile = System:GetProperty("map","Maps/start.map")

    if Map:Load(mapfile)==false then return false end

     

    return true

    end

     

    --This is our main program loop and will be called continuously until the program ends

    function App:Loop()

     

    --If window has been closed, end the program

    if self.window:Closed() or self.window:KeyDown(Key.Escape) then return false end

     

    --Handle map change

    if changemapname~=nil then

     

    --Clear all entities

    self.world:Clear()

     

    --Load the next map

    Time:Pause()

    if Map:Load("Maps/"..changemapname..".map")==false then return false end

    Time:Resume()

     

    changemapname = nil

    end

     

    --Update the app timing

    Time:Update()

     

    --Update the world

    self.world:Update()

     

    --Render the world

    self.world:Render()

     

    --Render statistics

    self.context:SetBlendMode(Blend.Alpha)

    if DEBUG then

    self.context:SetColor(1,0,0,1)

    self.context:DrawText("Debug Mode",2,2)

    self.context:SetColor(1,1,1,1)

    self.context:DrawStats(2,22)

    self.context:SetBlendMode(Blend.Solid)

    else

    --Toggle statistics on and off

    if (self.window:KeyHit(Key.F11)) then self.showstats = not self.showstats end

    if self.showstats then

    self.context:SetColor(1,1,1,1)

    self.context:DrawText("FPS: "..Math:Round(Time:UPS()),2,2)

    end

    end

     

    --Refresh the screen

    self.context:Sync(false)

     

    --Returning true tells the main program to keep looping

    return true

    end

  12. IMPORTANT EDIT:

     

    I think I got the camera working now. I made a new project, and copied everything over except SOURCE folder. Then in vs2013 - i re-compiled, and ran a fast debug, and did a release.

     

    Now the camera works as intended. Everything is working now except for the inventory script.

     

    Working on replacing : self.screenWidth = App.context:GetWidth() - to something that works. Im learning!

     

     

     

    #include "App.h"

     

    using namespace Leadwerks;

     

    App::App() : window(NULL), context(NULL), world(NULL), camera(NULL) {}

     

    App::~App() { delete world; delete window; }

     

    bool App::Start()

    {

    int stacksize = Interpreter::GetStackSize();

     

    //Get the global error handler function

    int errorfunctionindex = 0;

    #ifdef DEBUG

    Interpreter::GetGlobal("LuaErrorHandler");

    errorfunctionindex = Interpreter::GetStackSize();

    #endif

     

    //Create new table and assign it to the global variable "App"

    Interpreter::NewTable();

    Interpreter::SetGlobal("App");

     

    //Invoke the start script

    if (!Interpreter::ExecuteFile("Scripts/App.lua"))

    {

    System::Print("Error: Failed to execute script \"Scripts/App.lua\".");

    return false;

    }

     

    //Call the App:Start() function

    Interpreter::GetGlobal("App");

    if (Interpreter::IsTable())

    {

    Interpreter::PushString("Start");

    Interpreter::GetTable();

    if (Interpreter::IsFunction())

    {

    Interpreter::PushValue(-2);//Push the app table onto the stack as "self"

    #ifdef DEBUG

    errorfunctionindex = -(Interpreter::GetStackSize()-errorfunctionindex+1);

    #endif

    if (!Interpreter::Invoke(1,1,errorfunctionindex)) return false;

    if (Interpreter::IsBool())

    {

    if (!Interpreter::ToBool()) return false;

    }

    else

    {

    return false;

    }

    }

    }

     

    //Restore the stack size

    Interpreter::SetStackSize(stacksize);

     

    return true;

    }

     

    bool App::Loop()

    {

    //Get the stack size

    int stacksize = Interpreter::GetStackSize();

     

    //Get the global error handler function

    int errorfunctionindex = 0;

    #ifdef DEBUG

    Interpreter::GetGlobal("LuaErrorHandler");

    errorfunctionindex = Interpreter::GetStackSize();

    #endif

     

    //Call the App:Start() function

    Interpreter::GetGlobal("App");

    if (Interpreter::IsTable())

    {

    Interpreter::PushString("Loop");

    Interpreter::GetTable();

    if (Interpreter::IsFunction())

    {

    Interpreter::PushValue(-2);//Push the app table onto the stack as "self"

    #ifdef DEBUG

    errorfunctionindex = -(Interpreter::GetStackSize()-errorfunctionindex+1);

    #endif

    if (!Interpreter::Invoke(1,1,errorfunctionindex))

    {

    System::Print("Error: Script function App:Loop() was not successfully invoked.");

    Interpreter::SetStackSize(stacksize);

    return false;

    }

    if (Interpreter::IsBool())

    {

    if (!Interpreter::ToBool())

    {

    Interpreter::SetStackSize(stacksize);

    return false;

    }

    }

    else

    {

    Interpreter::SetStackSize(stacksize);

    return false;

    }

    }

    else

    {

    System::Print("Error: App:Loop() function not found.");

    Interpreter::SetStackSize(stacksize);

    return false;

    }

    }

    else

    {

    System::Print("Error: App table not found.");

    Interpreter::SetStackSize(stacksize);

    return false;

    }

     

    //Restore the stack size

    Interpreter::SetStackSize(stacksize);

     

    return true;

    }

     

     

    When I run the game with debug - in leadwerks editor, it works fine (except inventory script) - it starts as the FPSplayer controller.

    when I just hit play, the camera starts at 0,-2,3 or something, and it has no-clip/fly.

  13. I can get it compiled,

     

    Then when I go back to Leadwerks editor - most the start-up errors dissapear,

     

    Its stuck on;

     

    Script Error

     

    attempt to index global 'App' (a nil value)

     

    Line 10

     

    -------------- this is referring to line 10 of the inventory.lua script from tutorial 16/17 by Jorn Theunissen

     

    function Script:Start()

    self.screenWidth = App.context:GetWidth()

     

     

    It also gives warning: Lua Sandboxing is Disabled.

     

     

    Now, if I remove the inventory.lua script from my player, the game runs.

     

    However, it's ignoring my FPSplayer controller, its spawning me at 0.0.0 in the middle of the map, with fly mode/walk thru walls. I also cant interact with objects.

  14. I switched it from 32bit to 64bit for debugging;

     

    And it gives

     

    2 errors, 1 warnings.;

     

    Warning "C4267:'argument'conversion from 'size_t' to 'const int', possible loss of data - main.cpp line 33

     

    Which says on line 33 "if (String::Right(settingsfile, 6) == ".debug") settingsfile = String::Left(settingsfile, settingsfile.length() - 6);"

     

     

    Errors are; LNK1104: cannot open file 'lua51.lib'

    And; IntelliSense enumeration value is out of 'int' range.

     

     

    EDIT: for the LNK1104 error, in project properties, linker, input, the discrepancies field has a error - this could be the reason for it.

     

    EDIT2: my file paths show x86, when changing it to 64bit, it wants 64bit file paths. But I have x86 file paths. so I guess I need to use 32bit debug.

  15. Ahh ok, the guide I had open before mentioned 2010.

     

    I installed the VS2013, and it doesn't launch anything. It gives around 85-120 errors, then just closes.

     

    Most errors are PDB errors, which I believe I can ignore, but theres also runtime errors (memory errors), .tex and .mat errors, which is weird as they dont give error in leadwerks editor.

     

    Heres some of the last of the debug;

     

    The thread 0x2204 has exited with code 1 (0x1).

    The thread 0x1fbc has exited with code 1 (0x1).

    The thread 0x2648 has exited with code 1 (0x1).

    The thread 0xc40 has exited with code 1 (0x1).

    The thread 0x2130 has exited with code 1 (0x1).

    The thread 0x1d18 has exited with code 1 (0x1).

    The thread 0xf68 has exited with code 1 (0x1).

    The thread 0xf24 has exited with code 1 (0x1).

    The program '[6912] MyGame2.debug.exe' has exited with code 1 (0x1).

     

     

    Attempt to index global "app" (A Nil Value) (EDIT2: this error is caused by app.cpp something about null, or function.) nil & function are used in LUA, but not in C++, I didn't see any nil or function mentioned in app.cpp but there is 3 (NULL) as some things from the default are not defined.

     

     

    I've tried build/rebuild, and running with and without debug.

     

     

    EDIT; I solved error c4018 by replacing int i with size_t i on line 58 of main.cpp

  16. I upgraded from Indie to Standard yesterday as I am interested in utilizing modules/apps and other benefits of programs like Neosis GUI which only works for C++.

     

    I installed the DLC, and created a new project, using C++ instead of LUA.

     

    My issue is moving my existing project over (my start.map) to the new project.

     

    copy-paste of the map / texture / prefab / models , etc did not simply just work.

     

     

    I had a look at Aggror's first tutorials 1-8 which covers Intro to C++, and models, and shapes, and other stuff using C++.

     

    Do I need to start this first for the new project?

     

    My existing project already works in Indie version by just hitting play. It loads the game fine.

     

     

    Any help with this would be greatly appreciated. Let me know if I need to do a lot of set-up first, or if the existing project I worked on before should be able to just be copied over.

     

     

    Edit; been reading other posts of users who upgraded. My understanding is that theres no default FPS character controller for C++ where as it has it in LUA. So I would need to do the follow along of Aggror's beginning tutorials to prepare the change over?

     

    Edit2: I can get the map to copy, just can't run it. Gives a game.exe error. (I am assuming this is because the C++ isn't setup yet?)

×
×
  • Create New...