YourGGeorgie Posted April 24, 2020 Share Posted April 24, 2020 I saw a forum post where a person was making a character which dropped logs with a 50/50 chance when they were hit. Link: https://forums.kleientertainment.com/forums/topic/83766-solved-can-custom-character-spawn-objects/ My character is a grass gekko, and I want them to drop grass sometimes upon being hit. I copied the code to see whether it would work, but when my character gets hit there is an error message, which I've attached. If anyone could make sense of this and help me it'd mean the world, thanks! Link to comment https://forums.kleientertainment.com/forums/topic/117616-character-dropping-items-upon-being-hit/ Share on other sites More sharing options...
Ultroman Posted April 24, 2020 Share Posted April 24, 2020 (edited) If you read the comments after the code-block, they solve the problem in the thread. The error even points out that the function is misspelled (by telling you it doesn't exist, when we know all entities are guaranteed to have a SetPosition() function). Edited April 24, 2020 by Ultroman Link to comment https://forums.kleientertainment.com/forums/topic/117616-character-dropping-items-upon-being-hit/#findComment-1327872 Share on other sites More sharing options...
YourGGeorgie Posted April 25, 2020 Author Share Posted April 25, 2020 Thanks, I fixed the problem but now it says that "variable 'projectile' is not declared" in the error. This is the code for it: inst:ListenForEvent("attacked", function(inst) inst:DoTaskInTime(0, function(inst) if math.random() <= .5 then local wood = SpawnPrefab("log") wood.Transform:SetPosition(inst.Transform:GetWorldPosition()) if wood.Physics ~= nil then local x, y, z = wood.Transform:GetWorldPosition() wood.Physics:Teleport(x, .3, z) local angle = (math.random() * 20 - 10) * DEGREES angle = angle + math.random() * 2 * PI local speed = projectile and 2 + math.random() or 3 + math.random() * 2 wood.Physics:SetVel(math.cos(angle) * speed, 10, math.sin(angle) * speed) end end end) end) If anyone could help again that would be great, thanks Link to comment https://forums.kleientertainment.com/forums/topic/117616-character-dropping-items-upon-being-hit/#findComment-1328045 Share on other sites More sharing options...
Ultroman Posted April 26, 2020 Share Posted April 26, 2020 They're using a "projectile" variable in the "local speed" line, but it's not mentioned anywhere else. Try just changing that line to: local speed = 3 + math.random() * 2 Link to comment https://forums.kleientertainment.com/forums/topic/117616-character-dropping-items-upon-being-hit/#findComment-1328289 Share on other sites More sharing options...
YourGGeorgie Posted April 26, 2020 Author Share Posted April 26, 2020 Hm, there's a different error now which I've attached. I've been playing around with the code a little bit but I can't find a solution Thanks for the continued help Link to comment https://forums.kleientertainment.com/forums/topic/117616-character-dropping-items-upon-being-hit/#findComment-1328431 Share on other sites More sharing options...
Ultroman Posted April 26, 2020 Share Posted April 26, 2020 The error says you're missing and "end" somewhere after line 77. The code you've posted doesn't have any such problems. If this information doesn't help you find the problem, post the whole Lua file, so I can look at it. Link to comment https://forums.kleientertainment.com/forums/topic/117616-character-dropping-items-upon-being-hit/#findComment-1328433 Share on other sites More sharing options...
YourGGeorgie Posted April 26, 2020 Author Share Posted April 26, 2020 Yes! It works perfectly now, tysm! 1 Link to comment https://forums.kleientertainment.com/forums/topic/117616-character-dropping-items-upon-being-hit/#findComment-1328435 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