DiosSasuke Posted April 23, 2018 Share Posted April 23, 2018 Hi, can someone tell me what I did wrong with this script? I'm new to this? In the console I see server.lua: 2: Bad argument @ `getElementPosition` [Expected element at argument 1, got nil] and I also see server.lua: 3: Bad argument @ `createexplosion` [Expected vector3 at argument 1, got boolean] here I leave the lua function explosionOnSpawn ( ) local pX, pY, pZ = getElementPosition(source) createExplosion ( pX, pY, pZ, 6, source ) end addEventHandler ( "onPlayerSpawn", getRootElement(), explosionOnSpawn ) addCommandHandler ( "explosion", explosionOnSpawn ) Link to comment
MIKI785 Posted April 23, 2018 Share Posted April 23, 2018 How is the explosionOnSpawn called? Is it through the event or command handler? Because if you're using the command then source is nil, hence getElementPosition returns false. To make it work in both cases you have to check if source ~= nil or if the first parameter ~= number (as onPlayerSpawn's first parameter is a number). Something like this should work: function explosionOnSpawn (player) if not source then --Source is nil, so we know that it was the command that executed it. source = player --make source be the 'player' end local pX, pY, pZ = getElementPosition(source) createExplosion ( pX, pY, pZ, 6, source ) end addEventHandler ( "onPlayerSpawn", getRootElement(), explosionOnSpawn ) addCommandHandler ( "explosion", explosionOnSpawn ) Link to comment
DiosSasuke Posted April 23, 2018 Author Share Posted April 23, 2018 Thanks, but how do I do it so that it does not take away my life? and also how do I create an object? but not that the object disappears Link to comment
KaMi Posted April 24, 2018 Share Posted April 24, 2018 (edited) 8 hours ago, DiosSasuke said: Thanks, but how do I do it so that it does not take away my life? and also how do I create an object? but not that the object disappears Hello, if you do not want your life to go down I recommend you do a "triggerClientEvent". ( this function is shared but we must pass it because the arguments we need are on the client side ). This is an example: server: --your code function explosionOnSpawn (player) if not source then --Source is nil, so we know that it was the command that executed it. source = player --make source be the 'player' end --The trigger triggerClientEvent(source,"onThePlayerSpawn",source) end addEventHandler ( "onPlayerSpawn", getRootElement(), explosionOnSpawn ) addCommandHandler ( "explosion", explosionOnSpawn ) client: addEvent("onThePlayerSpawn", true) addEventHandler("onThePlayerSpawn", root, function() local x,y,z = getElementPosition (localPlayer) createExplosion ( x, y, z, 6, false, -1.0, false ) end ) Edited April 24, 2018 by <~KaMiKaZe~> 1 Link to comment
DiosSasuke Posted April 24, 2018 Author Share Posted April 24, 2018 thanks can I add you on facebook so you can help me in other things? Link to comment
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