Jump to content

Problem with spawning objects near a player


Recommended Posts

Hello,

At first my excuses for my poor English :oops:

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! :D

Thomas

Link to comment
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

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:

ny644i.png

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

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
  
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
  
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

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

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

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...