Jump to content

[SOLVED] Error In My Weapon Pickup Script Somewhere (not working standard edition)


Defranco
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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.

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