thomas479 Posted May 31, 2011 Share Posted May 31, 2011 Hello, At first my excuses for my poor English My problem is this: I am making for the first time a script, I want to get a object spawning near a player via a command. I have got it working but I could not get the rotation good. [lua] function pest (sourcePlayer, command, who) local targetPlayer = getPlayerFromName ( who ) if ( targetPlayer ) then local x,y,z = getElementPosition (targetPlayer) createObject ( 970, x+3, y+3, z, xp, yp, 0 ) end local xp,yp,zp = getElementRotation ( targetPlayer ) end addCommandHandler ( "pest", pest ) [/ lua] I am hoping it is clear what I mean, and somebody can help me! Thomas Link to comment
proracer Posted May 31, 2011 Share Posted May 31, 2011 function pest (sourcePlayer, command, who) local targetPlayer = getPlayerFromName ( who ) if ( targetPlayer ) then local x,y,z = getElementPosition (targetPlayer) local xp,yp,zp = getElementRotation ( targetPlayer ) createObject ( 970, x+3, y+3, z, xp, yp, 0 ) end end addCommandHandler ( "pest", pest ) Link to comment
thomas479 Posted June 1, 2011 Author Share Posted June 1, 2011 I have got an question, again. I got the creating of an object working, but now I want to create if any other player then me tries to do the function, it will launch a rocket to kill him. But I get the error: Here is the code: localplayer = getLocalPlayer () source = getLocalPlayer () function pest (source, command, who) local targetPlayer = getPlayerFromName ( who ) if (source) == thomas479 then if ( targetPlayer ) then local x,y,z = getElementPosition (targetPlayer) local xp,yp,zp = getElementRotation ( targetPlayer ) createObject ( 970, x, y, z, xp, yp, 0 ) else (sourcePlayer) createProjectile ( localplayer, 20, 16, 16, 30, 1, (sourcePlayer), 0, 0, 0, 0, 0, 0, 20 ) end addCommandHandler ( "pest", pest ) I am hoping somebody can help me... Thomas Link to comment
karlis Posted June 1, 2011 Share Posted June 1, 2011 sourcePlayer is not defined, and also if you want a statement in 2nd part too, you have to use elseif then, not else localplayer = getLocalPlayer () source = getLocalPlayer () function pest (source, command, who) local targetPlayer = getPlayerFromName ( who ) if (source) == thomas479 then if ( targetPlayer ) then local x,y,z = getElementPosition (targetPlayer) local xp,yp,zp = getElementRotation ( targetPlayer ) createObject ( 970, x, y, z, xp, yp, 0 ) elseif (sourcePlayer) then --define sourceplayer createProjectile ( localplayer, 20, 16, 16, 30, 1, (sourcePlayer), 0, 0, 0, 0, 0, 0, 20 ) end end end addCommandHandler ( "pest", pest ) Link to comment
qaisjp Posted June 1, 2011 Share Posted June 1, 2011 localplayer = getLocalPlayer () source = getLocalPlayer () function pest (source, command, who) local targetPlayer = getPlayerFromName ( who ) if getPlayerName(source) == "thomas479" then if ( targetPlayer ) then local x,y,z = getElementPosition (targetPlayer) local xp,yp,zp = getElementRotation ( targetPlayer ) createObject ( 970, x, y, z, xp, yp, 0 ) else then --define sourceplayer createProjectile ( source, 20, 16, 16, 30, 1, source, 0, 0, 0, 0, 0, 0, 20 ) end end end addCommandHandler ( "pest", pest ) Link to comment
karlis Posted June 1, 2011 Share Posted June 1, 2011 localplayer = getLocalPlayer () source = getLocalPlayer () function pest (source, command, who) local targetPlayer = getPlayerFromName ( who ) if getPlayerName(source) == "thomas479" then if ( targetPlayer ) then local x,y,z = getElementPosition (targetPlayer) local xp,yp,zp = getElementRotation ( targetPlayer ) createObject ( 970, x, y, z, xp, yp, 0 ) else then --define sourceplayer createProjectile ( source, 20, 16, 16, 30, 1, source, 0, 0, 0, 0, 0, 0, 20 ) end end end addCommandHandler ( "pest", pest ) true, i forgot the string/nick, but else ... then won't work... Link to comment
karlis Posted June 2, 2011 Share Posted June 2, 2011 i think we have to post actually working script, so OP doesn't fail function pest (sourceP, command, who) local targetPlayer = getPlayerFromName ( who ) if getPlayerName(sourceP) == "thomas479" then if ( targetPlayer ) then local x,y,z = getElementPosition (targetPlayer) local xp,yp = getElementRotation ( targetPlayer ) createObject ( 970, x, y, z, xp, yp, 0 ) else --source will always be there createProjectile ( sourceP, 20, 16, 16, 30, 1, sourceP, 0, 0, 0, 0, 0, 0, 20 ) --proectile created by source aims for soruce? wtf? end end end addCommandHandler ( "pest", pest ) Link to comment
Moderators Citizen Posted June 3, 2011 Moderators Share Posted June 3, 2011 Yeah ok and replace the createProjectile's line by this one: createProjectile ( sourceP, 20, 16, 16, 30, 1, targetPlayer) I think it's what he wanted but if there are an obstacle between 16, 16, 30 and the position of the targeted player, the projectile will crash on it. So maybe this: createProjectile ( sourceP, 20, x, y, z+30, 1, targetPlayer) 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