ZombieTG Posted August 2, 2015 Share Posted August 2, 2015 So theres some code here thats supposed to explode on impact... Well on impact I'm getting a crash everytime, could anyone look at the code and tell me what's wrong here? Attached the lua file on this postgrenade.lua Link to comment Share on other sites More sharing options...
whatsmynameagain Posted August 2, 2015 Share Posted August 2, 2015 (edited) 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()endI don't know if the that's the lightning thing you were going for, but it looks great. Edited August 2, 2015 by whatsmynameagain Link to comment Share on other sites More sharing options...
DarkXero Posted August 3, 2015 Share Posted August 3, 2015 @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 More sharing options...
ZombieTG Posted August 4, 2015 Author Share Posted August 4, 2015 Thank you, this wasn't what i had coded. I just needed to fix it, i'm a noob when it comes to code lol. Hopefully i learn more through out, you guys helping me out is making me learn more Link to comment Share on other sites More sharing options...
DarkXero Posted August 4, 2015 Share Posted August 4, 2015 I just needed to fix it Fair enough then. Here:grenade.lua Link to comment Share on other sites More sharing options...
ZombieTG Posted August 4, 2015 Author Share Posted August 4, 2015 Is there anyway i can throw it anywhere i want just like the water balloon? Link to comment Share on other sites More sharing options...
ZombieTG Posted August 5, 2015 Author Share Posted August 5, 2015 (edited) 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)endI 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 August 5, 2015 by ZombieTG Link to comment Share on other sites More sharing options...
DarkXero Posted August 5, 2015 Share Posted August 5, 2015 @ZombieTG, the first grenade.lua file I posted works like an explosive waterballoon. Link to comment Share on other sites More sharing options...
ZombieTG Posted August 5, 2015 Author Share Posted August 5, 2015 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 More sharing options...
DarkXero Posted August 5, 2015 Share Posted August 5, 2015 @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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now