Jump to content

TwicH

Members
  • Posts

    20
  • Joined

  • Last visited

Posts posted by TwicH

  1. 26 minutes ago, MadnessReloaded said:

    Found this thing long ago and been using it on my scripts ever since, so props to the original creator:

    
    function getPositionInFront(element,meters) 
       local x, y, z = getElementPosition ( element ) 
       local a,b,r = getVehicleRotation ( element ) 
       x = x - math.sin ( math.rad(r) ) * meters 
       y = y + math.cos ( math.rad(r) ) * meters 
       return x,y,z 
    end 
    

    This gets the position in front of the player.

    I think I have used setElementVelocity before and I'm pretty sure that function won't work if the player is standing over a surface, so you should find a workaround. But try it anyway, I might be wrong.

    works perfect, thank you so much :)

  2. hi scripters of mta, I had an idea to make a platform cj would automatically "slide" on for my parkour server.

    so here is what i did:

    function standingcheck()
    	
    	local slide_platform = getElementModel (getPedContactElement ( localPlayer )) --get the model of the object cj is standing on
    	
    	if slide_platform == 8558 then --if its this object then
    		
    		local x,y,z = getElementRotation ( localPlayer ) 
    		
    		--do some math with z variable here :D
    		
    		setElementVelocity ( localPlayer, 0, 0, 0) --push cj the way hes facing somehow
    	end
    end
    
    addEventHandler ( "onClientPreRender", root, standingcheck ) 

    thank you in advance.

     

  3. Oh wait I read that wrong crap..
        function follow() 
                
                for i,v in pairs(zombie) do 
                    
                    local x,y,z = getElementPosition (getLocalPlayer()) 
                    local zpx,zpy,zpz = getElementPosition (v) 
              
                    local zombie_angle = (360 - math.deg(math.atan2((zpx - x), (zpy - y)))) % 360 
                    local dist = getDistanceBetweenPoints2D(x, y, zpx, zpy) 
                    if (dist > 3) then 
                        setPedCameraRotation (v,-zombie_angle) 
                        setPedControlState(v, "backwards", true) 
                        setPedControlState(v, "fire", false) 
                    elseif (dist < 3) then 
                         setPedAimTarget (v, x,y,z) 
                        setPedCameraRotation (v,-zombie_angle) 
                        setPedControlState(v, "fire", false) 
                        setPedControlState(v, "fire", true) 
                        setPedControlState(v, "fire", false) 
                    end 
                end 
            end 
    

    There are a few bits I'm unsure of, but this should work hopefully.

    now they don't punch at all

  4. Made a mistake..
        function follow() 
                
                for i,v in pairs(zombie) do 
                    
                    local x,y,z = getElementPosition (getLocalPlayer()) 
                    local zpx,zpy,zpz = getElementPosition (v) 
              
                    local zombie_angle = (360 - math.deg(math.atan2((zpx - x), (zpy - y)))) % 360 
                    local dist = getDistanceBetweenPoints2D(x, y, zpx, zpy) 
                    if (dist < 2) then 
                        setPedCameraRotation (v,-zombie_angle) 
                        setPedControlState(v, "backwards", true) 
                        setPedControlState(v, "fire", false) 
                    elseif (dist > 2) then 
                         setPedAimTarget (v, x,y,z) 
                        setPedCameraRotation (v,-zombie_angle) 
                        setPedControlState(v, "fire", false) 
                        setPedControlState(v, "fire", true) 
                    end 
                end 
            end 
    

    Had it so it would fire if the distance was bigger then two instead of smaller then.

    I'm sorry to bother you but it seems like every time you fix a bug there is another one coming up, now they don't even follow me unless I get close to them. would you mind we talk on skype?

  5. function follow() 
            
            for i,v in pairs(zombie) do 
                
                local x,y,z = getElementPosition (getLocalPlayer()) 
                local zpx,zpy,zpz = getElementPosition (v) 
          
                local zombie_angle = (360 - math.deg(math.atan2((zpx - x), (zpy - y)))) % 360 
                local dist = getDistanceBetweenPoints2D(x, y, zpx, zpy) 
                if (dist > 2) then 
                    setPedCameraRotation (v,-zombie_angle) 
                    setPedControlState(v, "backwards", true) 
                    setPedControlState(v, "fire", false) 
                elseif (dist < 2) then 
                     setPedAimTarget (v, x,y,z) 
                    setPedCameraRotation (v,-zombie_angle) 
                    setPedControlState(v, "fire", false) 
                    setPedControlState(v, "fire", true) 
                end 
            end 
        end 
    

    - Changed a few things, some due to potential issues; others just to optimize the code a bit. Any ways

    make sure the timer is set up right and what not.

    now the zombies punch me once but wont punch again until i get far away from them

  6. function follow() 
         
        for i=0,maxzombies do 
             
            local x,y,z = getElementPosition (localPlayer) 
            local zpx,zpy,zpz = getElementPosition (zombie[i]) 
      
            local zombie_angle = (360 - math.deg(math.atan2((zpx - x), (zpy - y)))) % 360 
            local dist = getDistanceBetweenPoints2D(x, y, zpx, zpy) 
            if (dist > 2) then 
                setPedCameraRotation (zombie[i],-zombie_angle) 
                setPedControlState(zombie[i], "backwards", true) 
            elseif (dist < 2) then 
                setPedCameraRotation (zombie[i],-zombie_angle) 
                setPedControlState(zombie[i], "fire", false) 
                setPedControlState(zombie[i], "fire", true) 
            end 
        end 
    end 
    

    I have fixed the problem but now the zombies just punch me once when they get close and never punch me again

  7. local maxzombies = 30 
    local zombiecount = 0 
    zombie =  {} 
      
      
    function spawn() 
        local x,y,z = getElementPosition (localPlayer) 
        zombie[tostring(zombiecount)] = zombiecount 
        local zombie[zombiecount] = createPed (20,x+math.random(-7,7),y+math.random(-7,7),z) 
      
    end 
        
    function follow() 
        zpx,zpy,zpz = getElementPosition (zombie[zombiecount]) 
        local zombie_angle = (360 - math.deg(math.atan2((zpx - x), (zpy - y)))) % 360 
        
        local dist = getDistanceBetweenPoints2D(x, y, zpx, zpy) 
        if (dist > 2) then 
            setPedCameraRotation (zombie[zombiecount],zombie_angle) 
            setPedControlState(zombie[zombiecount], "forwards", true) 
        elseif (dist < 2) then 
            setPedControlState(zombie[zombiecount], "forwards", false) 
            setPedControlState(zombie[zombiecount], "fire", true) 
        end 
    end 
    setTimer (follow, 1000, 0) 
      
      
    function zombie_check() 
        if (zombiecount < maxzombies) then  
            spawn() 
            zombiecount = zombiecount + 1 
        end 
    end 
    setTimer (zombie_check, 100, 0) 
      
    function zombie_died() 
        zombiecount = zombiecount - 1 
    end 
      
    addEventHandler("onClientPedWasted", getRootElement(), zombie_died) 
    

    still not working, 9: unexpected symbol near '['

  8. Hello guys could somebody tell me where I went wrong with the tables?

    I'm basically trying to give each zombie an id so they can follow the player

      
    local maxzombies = 30 
    local zombiecount = 0 
    zombie{} 
      
      
    function spawn() 
        local x,y,z = getElementPosition (localPlayer) 
        zombie[tostring(zombiecount)] = zombiecount 
        local zombie[zombiecount] = createPed (20,x+math.random(-7,7),y+math.random(-7,7),z) 
      
    end 
         
    function follow() 
        zpx,zpy,zpz = getElementPosition (zombie[zombiecount]) 
        local zombie_angle = (360 - math.deg(math.atan2((zpx - x), (zpy - y)))) % 360 
         
        local dist = getDistanceBetweenPoints2D(x, y, zpx, zpy) 
        if (dist > 2) then 
            setPedCameraRotation (zombie[zombiecount],zombie_angle) 
            setPedControlState(zombie[zombiecount], "forwards", true) 
        elseif (dist < 2) then 
            setPedControlState(zombie[zombiecount], "forwards", false) 
            setPedControlState(zombie[zombiecount], "fire", true) 
        end 
    end 
    setTimer (follow, 1000, 0) 
      
      
    function zombie_check() 
        if (zombiecount < maxzombies) then   
            spawn() 
            zombiecount = zombiecount + 1 
        end 
    end 
    setTimer (zombie_check, 100, 0) 
      
    function zombie_died() 
        zombiecount = zombiecount - 1 
    end 
      
    addEventHandler("onClientPedWasted", getRootElement(), zombie_died) 
      
    

  9. Hello guys, I'm just starting to learn to script and I've been stuck on this issue for a while now

      
    local x,y,z = getElementPosition (localPlayer) 
    local zombie = createPed (20,x+math.random(-4,4),y+math.random(-4,4),z) 
      
    function follow() 
        x,y,z = getElementPosition (localPlayer) 
        zpx,zpy,zpz = getElementPosition (zombie) 
         
         
        local a = zpx - x 
        local b = y - zpy 
        local c = a*a + b*b 
         
        local sinlaw = 90/math.sin(b) 
        local zangel = math.sin(a)*sinlaw 
         
      
        setPedCameraRotation (zombie,zangel) 
         
         
        setPedControlState(zombie, "forwards", true) 
    end 
      
    setTimer ( follow, 500, 0) 
      
    

    the code made sense the first time that I wrote it and since then I've just messed with a few variables without really thinking hoping that it would bring me an easy solution. also please don't ask me why I did the math the way I did, I'm very bad at it and that's what I came up with.

  10. I tried this but player dosent work

    some friend told me to use this code:

    function MarkerHit ( hitPlayer, matchingDimension ) 
     if hitPlayer == localPlayer then 
         setPedAnimation( hitPlayer, "ped", "WOMAN_walknorm") 
        end 
    end 
    addEventHandler ( "onClientMarkerHit", getRootElement(), MarkerHit ) 
    

    it works but i dont know why..

  11. hey guys im trying to get into scripting and i have some problem with a simple script i put together

    function MarkerHit ( hitPlayer, matchingDimension ) 
          setPedAnimation( player, "ped", "WOMAN_walknorm") 
    end 
    addEventHandler ( "onClientMarkerHit", getRootElement(), MarkerHit ) 
    

    here is the code can you explain to me whats wrong?

×
×
  • Create New...