Defranco Posted September 7, 2014 Share Posted September 7, 2014 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. Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted September 7, 2014 Share Posted September 7, 2014 What is the error you are getting? Quote Link to comment Share on other sites More sharing options...
Defranco Posted September 7, 2014 Author Share Posted September 7, 2014 I'm not actually getting an error; When I walk onto the item, or csg that is set as trigger, and that has both the weaponpickup.lua script, and weapon.pfb atached, it does nothing. It doesn't add the weapon to the player (but does in indie version) I tried it in debug mode, and wasn't receiving any error Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted September 7, 2014 Share Posted September 7, 2014 When you walk up to the weapon, is it removed from the scene? Quote Link to comment Share on other sites More sharing options...
Defranco Posted September 7, 2014 Author Share Posted September 7, 2014 No, no hand icon. Only when I remove the script, and set it to prop with a weight does it show a hand icon. Then I can pick it up like a regular prop object. Once I add the script, it doesn't allow that anymore - doesn't matter if its a prop or trigger in physics, not getting a hand. The weapon is not removed from the scene. Quote Link to comment Share on other sites More sharing options...
Defranco Posted September 7, 2014 Author Share Posted September 7, 2014 Ok, I got a single csg to work with it. I drew a simple square box, set it to trigger, added the script and .pfb. It worked. But its not working when I use an .mdl or .pfb that has "limbs" or attachments to the scene. Basically, I want to walk into a sword, and have it pickup a sword. I dont want to run into a box, to pick up a sword. Quote Link to comment Share on other sites More sharing options...
Defranco Posted September 8, 2014 Author Share Posted September 8, 2014 Ok, wow. oooooooppss! I set the parent of the item that I wanted to run into with Box option, and trigger together. Then I checked "show physics" and it finally turned on. Now, when I walk into the object (mdl, or pfb, it picks it up and removed the item from the game and puts it on the player) So thats solved. Now I need to get it to fire/animate, hehe. Quote Link to comment Share on other sites More sharing options...
Defranco Posted September 8, 2014 Author Share Posted September 8, 2014 So I guess the issue was the object I was walking into had no physics. So how could it interact with the player? Thanks Aggror, as soon as you asked me about it removing from the scene, that's where I looked into. Quote Link to comment Share on other sites More sharing options...
Rick Posted September 8, 2014 Share Posted September 8, 2014 I remember in my tutorial that I put csg around the gun model for the collision and painted it with the invisible material. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.