Jump to content

How to fix default autopistol.pfb


MaybeMe
 Share

Recommended Posts

Hey guys,

 

I was messing around and wanted to give a try at different aspects of the engine.

 

I noticed with the default autopistol prefab that you can fire the pistol before the reloading animation is done. How can I delay it and make it fire later, when the animation is finished?

 

Edit: Also, how do I move the prefab floorplates? I can only rotate them among the axes, not actually drag them once they are placed.

Link to comment
Share on other sites

Ok, I just looked at the script. It is a little more complicated than I thought.

 

I'm working on the FPSGun.lua file.

 

Put this at the top of the file:

Script.reloadstarttime=Time:GetCurrent()-10000

 

Put this around the code inside of the Fire() method:

if Time:GetCurrent()-self.reloadstarttime>5000 then
 --fire code
end

 

Now, the 10000 I put at the top is for ten seconds (I'm basically saying put the reload time back 10 seconds to begin without so there is no lock).

 

Anyway, that part isn't that important. The part you will likely have to change with this new code is the number 5000. I just used this for testing purposes. Basically, after 5 seconds of starting the reload process, you can fire again. You'll probably want to pick a better number. I also didn't test it that much, so there might be other timing issues, but you should be able to move the start reload animation line somewhere else to fix these.

  • Upvote 1
Link to comment
Share on other sites

Ok, I just looked at the script. It is a little more complicated than I thought.

 

I'm working on the FPSGun.lua file.

 

Put this at the top of the file:

Script.reloadstarttime=Time:GetCurrent()-10000

 

Put this around the code inside of the Fire() method:

if Time:GetCurrent()-self.reloadstarttime>5000 then
--fire code
end

 

Now, the 10000 I put at the top is for ten seconds (I'm basically saying put the reload time back 10 seconds to begin without so there is no lock).

 

Anyway, that part isn't that important. The part you will likely have to change with this new code is the number 5000. I just used this for testing purposes. Basically, after 5 seconds of starting the reload process, you can fire again. You'll probably want to pick a better number. I also didn't test it that much, so there might be other timing issues, but you should be able to move the start reload animation line somewhere else to fix these.

Alright!

 

Thanks for the fix. I just wanted to try and get it the way I like it so I could use it for other purposes.

 

Thanks a bunch!

  • Upvote 1
Link to comment
Share on other sites

Alright...

 

This is what I've got. I'm going to try and look up some Lua tutorials to see what I messed up, but it gives me an error:

attempt to call method 'SpawnBullet' (a nil value)

 

function Script:Fire()
if Time:GetCurrent()-self.reloadstarttime>5000 then
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
if self.clipammo==0 then
if self.sound.dryfire then
if self.suspenddryfire~=true then
self.sound.dryfire:Play()
end
end
else
self.currentaction="fire"
if #self.sound.fire>0 then
self.sound.fire[math.random(#self.sound.fire)]:Play()
end
self.clipammo = self.clipammo - 1
self.firetime = Time:GetCurrent()
self.muzzlelight:Point(self.player.camera,1)
self.muzzlelight:Show()
self.muzzleflash:SetAngle(math.random(0,360))
self.animationmanager:SetAnimationSequence("Fire",self.firespeed,300,1,self,self.EndFire)

--Spawn bullet
local n
for n=1,self.pellets do
local d = Transform:Normal(0,0,1,self.player.camera,nil)
d = d + Vec3(math.random(-1,1),math.random(-1,1),math.random(-1,1)) * self.scatter
d = d:Normalize()
local p
if self.muzzle then
p=self.muzzle:GetPosition(true)
self:SpawnBullet(p,d*self.bulletspeed)
else
System:Print("Warning: Muzzle entity not found.")
end
end
end
else
self.cancelreload=true
end
end
end
end

--Creates a bullet
function Script:SpawnBullet(position,velocity)
local bullet = {}
bullet.sprite = tolua.cast(self.tracer:Instance(),"Sprite")
bullet.sprite:SetPosition(position)
bullet.sprite:AlignToVector(velocity)
bullet.sprite:Hide()
bullet.position = position
bullet.origin = Vec3(position.x,position.y,position.z)
bullet.velocity = velocity
table.insert(self.bullets,bullet)
end

function Script:Draw()

local t = Time:GetCurrent()

if self.muzzlelight:Hidden()==false then
if t-self.firetime>50 then
self.muzzlelight:Hide()
end
end

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()
self.emitter[0]:Release()
self.emitter[1]:Release()
self.emitter=nil
ReleaseTableObjects(self.sound)
end

function Script:Cleanup()
self.tracer:Release()
end
end

 

Any help and possible explanation of what I did wrong?

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