Jump to content

Need help with fixing code


Recommended Posts

Still have to test it on a client but here...

local function onhit(inst, attacker, target)	SpawnPrefab("collapse_small").Transform:SetPosition(target.Transform:GetWorldPosition())	SpawnPrefab("explode_small").Transform:SetPosition(target.Transform:GetWorldPosition())	TheWorld:PushEvent("screenflash", .5)	for i, v in ipairs(AllPlayers) do		v:ShakeCamera(CAMERASHAKE.SIDE, .5, .05, .1, inst, 40)	end	inst.components.combat:DoAreaAttack(target, 8)	inst:Remove()end

I don't know if the that's the lightning thing you were going for, but it looks great.

Edited by whatsmynameagain
Link to comment
Share on other sites

@ZombieTG, that works? Unexpected.

 

So, what's wrong:

- No returning the inst before loading components so client doesn't get them

- Using GetClock() and DoLightning(), no such things

- Using that ShakeCamera, that one is no more, also GetPlayer() is deprecated

 

You would notice the errors in the basic structure by looking at any simple prefab file.

 

I suggest using the waterballon info from the waterprojectiles file. I did in the attachment.

I also applied the code I gave you for damaging multiple things nearby.

grenade.lua

Link to comment
Share on other sites

local function ReticuleTargetFn()	local player = ThePlayer	local ground = TheWorld.Map	local x, y, z	for r = 6.5, 3.5, -0.25 do		x, y, z = player.entity:LocalToWorldSpace(r, 0, 0)		if ground:IsPassableAtPoint(x, y, z) then			return Vector3(x, y, z)		end	end	return Vector3(x, y, z)end

I thought this was the reticle for it to be thrown anywhere the mouse is pointed... but yet again I'm a noob...

 

If anyone could help me find it that would be cool, I'm still going to look for it anyway until then!

Edited by ZombieTG
Link to comment
Share on other sites

Okay i tried the first grenade.lua file, well it didn't work so i just took some of the code and put it into the second grenade.lua file

 

However throwing it just lands it on the floor without any impact, only throwing it at a target causes it to explode.

 

Is there anything i have to do in the code below to make it explode on impact of the world and not just a target?

local function onhit(inst, attacker, target)		SpawnPrefab("collapse_small").Transform:SetPosition(target.Transform:GetWorldPosition())	SpawnPrefab("explode_small").Transform:SetPosition(target.Transform:GetWorldPosition())	TheWorld:PushEvent("screenflash", 0.5)	for i, v in ipairs(AllPlayers) do		v:ShakeCamera(CAMERASHAKE.FULL, 0.7, 0.02, 0.5, inst, 40)	end	inst.components.combat:DoAreaAttack(target, 8)	inst:Remove()end

- The above code is from the second grenade.lua and both works fine from the ( function onhit ) it's just i prefer this one

 

Would it work if i added  local function onhit(inst, attacker, target, world) by adding the world after target?

 

I have no clue if that would work but i would think it's not working because it thinks the world isn't a target for impact?

 

Thanks for taking your time to help me btw

Link to comment
Share on other sites

@ZombieTG:

My first grenade.lua code works perfectly. I don't know what you did to it.

I packaged it into an attachment.

You get some grenades, you equip them, you right click them and toss them.

They fly, they hit target or ground, they explode and damage enemies around.

 

Is there anything i have to do in the code below to make it explode on impact of the world and not just a target?

 

You can't edit the onhit code to make it account the world as a target. That's because of how you made the grenade work, as a weapon, for a combat between an attacker and a target. Waterballoons have the complexprojectile component, which allows them to be targeted to the cursor position.

 

Would it work if i added local function onhit(inst, attacker, target, world) by adding the world after target?

 

Would it work if I added local function onhit(inst, attacker, target, your_credit_card_number) and then I printed the credit card number? The onhit function is called with the inst, attacker, target arguments, and that's it.

 

I have no clue if that would work but i would think it's not working because it thinks the world isn't a target for impact?

 

Things with the combat component or weapon component don't get actions that see world positions as targets.

Grenade.zip

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...