Jump to content

making the ped fly with the direction of the hit


Al3grab

Recommended Posts

hi ,

i made something like Mega Punch cheat 'IAVENJQ' in normal mode .. so i want the ped that i hit fly away with the direction of the hit.

i just made this to make him fly away ..

  
for k=0,20 do 
--source : the ped , attacker : the player that attacked him  
    x,y,z = getElementPosition(source) 
    setElementPosition(source,x,y+0.1,z+0.1) 
end 
  

but he wont fly with the hit direction xD , i know that could be done with maths that i am not good at :?

any help :|

Link to comment
function hit (killer, killerweapon, bodypart) 
if (killer) and (killer ~=source) then 
local x,y,z = getElementPosition(source) 
setElementPosition(source,x,y+0.1,z+0.1) 
outputChatBox('You Got Hit an Moved to BlaBlaBla',source,255,255,0) 
end 
addEventHandler ( "onClientPlayerDamage", getLocalPlayer(), hit) 

Link to comment
function hit (killer, killerweapon, bodypart) 
if (killer) and (killer ~=source) then 
local x,y,z = getElementPosition(source) 
setElementPosition(source,x,y+0.1,z+0.1) 
outputChatBox('You Got Hit an Moved to BlaBlaBla',source,255,255,0) 
end 
addEventHandler ( "onClientPlayerDamage", getLocalPlayer(), hit) 

-_-" , did you read the post ? :|

Link to comment
  • Moderators

"direction of the hit"

You must get the attacker(not killer) position to.

This is what he means!!!

Sample: (this is with gun)

attacker = left

player = center

fly direction = left > direction of the hit

Al3grab is asking a big script with math stuff. I hope you understand what he means now, because I hate this kind of math.

Link to comment
"direction of the hit"

You must get the attacker(not killer) position to.

This is what he means!!!

Sample: (this is with gun)

attacker = left

player = center

fly direction = left > direction of the hit

Al3grab is asking a big script with math stuff. I hope you understand what he means now, because I hate this kind of math.

thanks for explaining that for him :D

You can make use of setPedGravity when player punches then set a timer to change back the gravity to normal.

nice idea , i tried that but it wasn't that good :arrow: , so i made this .. it works but need for improving .

  
x,y,z = getElementPosition(source) -- get the ped pos    
setElementPosition(source,x,y,z+4) -- fly him up 
power = 100 -- number of loops .. 
    for k=0,power do 
    x,y,z = getElementPosition(source)-- get the ped pos 
    rot = getPedRotation(attacker)-- get the attacker rotation 
        if rot > 45 and rot < 140 then -- Hit From Right 
            setElementPosition(source,x-0.1,y,z) 
        elseif rot > 200 and rot < 300 then -- Hit From Left 
            setElementPosition(source,x+0.1,y,z) 
        elseif rot > 90 and rot < 270 then -- Hit From Front 
            setElementPosition(source,x,y-0.1,z) 
        else -- Hit From Back .. betrayer  
            setElementPosition(source,x,y+0.1,z) 
        end 
    end 
  

does anyone have something better ? :roll:

thanks all .

Link to comment
local power = 1 
local powerUp = 0.5 
  
addEventHandler("onClientPedDamage", getRootElement(), 
function(attacker) 
    -- attacker == getLocalPlayer() because setElementVelocity is synced with server 
    if(attacker and attacked ~= source and attacker == getLocalPlayer())then 
        local aPosX, aPosY, aPosZ = getElementPosition(attacker) 
        local sPosX, sPosY, sPosZ = getElementPosition(source) 
        local angle = math.atan2(aPosX - sPosX, aPosY - sPosY) - math.rad(90) 
        local velX, velY, velZ = getElementVelocity(source) 
        setElementVelocity(source, velX + power*-math.cos(angle), velY + power*math.sin(angle), velZ + powerUp) 
    end 
end) 
  
-- use this to test power 
addCommandHandler("fuu", 
function() 
    local posX, posY, posZ = getElementPosition(getLocalPlayer()) 
    local ped = createPed(16, posX, posY + 10, posZ) 
end) 

Link to comment
local power = 1 
local powerUp = 0.5 
  
addEventHandler("onClientPedDamage", getRootElement(), 
function(attacker) 
    -- attacker == getLocalPlayer() because setElementVelocity is synced with server 
    if(attacker and attacked ~= source and attacker == getLocalPlayer())then 
        local aPosX, aPosY, aPosZ = getElementPosition(attacker) 
        local sPosX, sPosY, sPosZ = getElementPosition(source) 
        local angle = math.atan2(aPosX - sPosX, aPosY - sPosY) - math.rad(90) 
        local velX, velY, velZ = getElementVelocity(source) 
        setElementVelocity(source, velX + power*-math.cos(angle), velY + power*math.sin(angle), velZ + powerUp) 
    end 
end) 
  
-- use this to test power 
addCommandHandler("fuu", 
function() 
    local posX, posY, posZ = getElementPosition(getLocalPlayer()) 
    local ped = createPed(16, posX, posY + 10, posZ) 
end) 

WOW ! , that works .. Thank you very much :D

Link to comment
local power = 1 
local powerUp = 0.5 
  
addEventHandler("onClientPedDamage", getRootElement(), 
function(attacker) 
    -- attacker == getLocalPlayer() because setElementVelocity is synced with server 
    if(attacker and attacked ~= source and attacker == getLocalPlayer())then 
        local aPosX, aPosY, aPosZ = getElementPosition(attacker) 
        local sPosX, sPosY, sPosZ = getElementPosition(source) 
        local angle = math.atan2(aPosX - sPosX, aPosY - sPosY) - math.rad(90) 
        local velX, velY, velZ = getElementVelocity(source) 
        setElementVelocity(source, velX + power*-math.cos(angle), velY + power*math.sin(angle), velZ + powerUp) 
    end 
end) 
  
-- use this to test power 
addCommandHandler("fuu", 
function() 
    local posX, posY, posZ = getElementPosition(getLocalPlayer()) 
    local ped = createPed(16, posX, posY + 10, posZ) 
end) 

WOW ! , that works .. Thank you very much :D

did it work when punching other players too (non-script created peds) ? i didn't test that.

Link to comment
local power = 1 
local powerUp = 0.5 
  
addEventHandler("onClientPedDamage", getRootElement(), 
function(attacker) 
    -- attacker == getLocalPlayer() because setElementVelocity is synced with server 
    if(attacker and attacked ~= source and attacker == getLocalPlayer())then 
        local aPosX, aPosY, aPosZ = getElementPosition(attacker) 
        local sPosX, sPosY, sPosZ = getElementPosition(source) 
        local angle = math.atan2(aPosX - sPosX, aPosY - sPosY) - math.rad(90) 
        local velX, velY, velZ = getElementVelocity(source) 
        setElementVelocity(source, velX + power*-math.cos(angle), velY + power*math.sin(angle), velZ + powerUp) 
    end 
end) 
  
-- use this to test power 
addCommandHandler("fuu", 
function() 
    local posX, posY, posZ = getElementPosition(getLocalPlayer()) 
    local ped = createPed(16, posX, posY + 10, posZ) 
end) 

WOW ! , that works .. Thank you very much :D

did it work when punching other players too (non-script created peds) ? i didn't test that.

i didn't test that , i will test it later .. and if it didn't work i can solve it :D , thanks again

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