Jump to content

Reward for killing


zzx

Recommended Posts

Posted

I made a script, if anyone killed another player with his hunter, he will get 200$

but only with hunter.

local reward = 200 
  
function kill ( ammo, killer, killerweapon, bodypart ) 
    local vehicle = getPedOccupiedVehicle ( killer ) 
    if isPedInVehicle ( killer ) and getElementModel ( vehicle ) == 425 then 
    givePlayerMoney ( source, reward ) 
            outputChatBox ("#ff8800[REWARD] #ffffffYou have killed "..getPlayerName..( source )" ..and rewarded $".. tostring ( reward ), root, 0, 255, 0, true ) 
        end 
    end 
addEventHandler ( "onPlayerWasted", getRootElement(), kill ) 

help please

Posted
local reward = 200 
  
function kill ( ammo, killer, killerweapon, bodypart ) 
    local vehicle = getPedOccupiedVehicle ( killer ) 
    local veh = getVehicleID(vehicle) 
    if isPedInVehicle ( killer ) and veh == 425 then 
    givePlayerMoney ( killer, reward ) 
            outputChatBox ("#ff8800[REWARD] #ffffffYou have killed "..getPlayerName..( source )" ..and rewarded $".. tostring ( reward ), killer, 0, 255, 0, true ) 
        end 
    end 
addEventHandler ( "onPlayerWasted", getRootElement(), kill ) 

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

Posted

You're welcome.

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

Posted
local reward = 200 
  
function kill ( ammo, killer, killerweapon, bodypart ) 
    local vehicle = getPedOccupiedVehicle ( killer ) 
    local veh = getVehicleID(vehicle) 
    if isPedInVehicle ( killer ) and veh == 425 then 
    givePlayerMoney ( killer, reward ) 
            outputChatBox ("#ff8800[REWARD] #ffffffYou have killed "..getPlayerName..( source )" ..and rewarded $".. tostring ( reward ), killer, 0, 255, 0, true ) 
        end 
    end 
addEventHandler ( "onPlayerWasted", getRootElement(), kill ) 

This won't work, first, getVehicleID is a deprecated function, second, you're defining the vehicle without checking whether the killer is a player.

This should work i guess:

local reward = 200 
  
function kill ( ammo, killer, killerweapon, bodypart ) 
    if ( getElementType ( killer ) == "vehicle" ) then 
        if ( getElementModel ( killer ) == 425 ) then 
            local controller = getVehicleController ( killer ) 
            givePlayerMoney ( controller, reward ) 
            outputChatBox ("#ff8800[REWARD] #ffffffYou have killed " .. getPlayerName ( source ) .. " and rewarded $" .. reward, controller, 255, 255, 255, true ) 
        end 
    end 
end 
addEventHandler ( "onPlayerWasted", getRootElement(), kill ) 

F4MZM4.gif

Posted
local reward = 200 
  
function kill ( ammo, killer, killerweapon, bodypart ) 
    local vehicle = getPedOccupiedVehicle ( killer ) 
    local veh = getVehicleID(vehicle) 
    if isPedInVehicle ( killer ) and veh == 425 then 
    givePlayerMoney ( killer, reward ) 
            outputChatBox ("#ff8800[REWARD] #ffffffYou have killed "..getPlayerName..( source )" ..and rewarded $".. tostring ( reward ), killer, 0, 255, 0, true ) 
        end 
    end 
addEventHandler ( "onPlayerWasted", getRootElement(), kill ) 

This won't work, first, getVehicleID is a deprecated function, second, you're defining the vehicle without checking whether the killer is a player.

This should work i guess:

local reward = 200 
  
function kill ( ammo, killer, killerweapon, bodypart ) 
    if ( getElementType ( killer ) == "vehicle" ) then 
        if ( getElementModel ( killer ) == 425 ) then 
            local controller = getVehicleController ( killer ) 
            givePlayerMoney ( controller, reward ) 
            outputChatBox ("#ff8800[REWARD] #ffffffYou have killed " .. getPlayerName ( source ) .. " and rewarded $" .. reward, controller, 255, 255, 255, true ) 
        end 
    end 
end 
addEventHandler ( "onPlayerWasted", getRootElement(), kill ) 

My bad, this one should work yeah.

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

  • Moderators
Posted

Note: Check if there is a controller, it can be none.

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

  • Moderators
Posted
Yeah, i thought of that, but the hunter can never be without a controller when it kills someone, that's impossible :P

You sure about that? :idea:

local vehicles = getElementsByType("vehicle") 
for i=1, #vehicles do 
    local vehicle = vehicles[i] 
    setElementVelocity ( vehicle,0,0, 30 ) 
end 
  
setTimer(function() 
    local vehicles = getElementsByType("vehicle") 
    for i=1, #vehicles do 
        local vehicle = vehicles[i] 
        setElementVelocity ( vehicle,0,0, -30 ) 
    end      
end,1000,1) 

If you have low hp and you get rammed by a falling hunter? :P

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted

My code had many mistakes, I'm glad that Tete fixed it.

You're welcome anyway.

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

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