Jump to content

[HELP] Cant get script to work onClientVehicleDamage


THASMOG

Recommended Posts

Line 14, 16, 17, 18, 19: getLocalPlayer is a function, use one of these instead:

getLocalPlayer() -- Function to get local player  
localPlayer  -- Predefined variable of local player 

The source element of onClientVehicleDamage is the vehicle that has been damaged so you don't need line 13 unless if you want to compare it with the source element. Use /debugscript 3 and check the server console for more information about these issues.

Link to comment

Thanks it works kinda. But it's not perfect. Now both players get text."Your car received damage! Do not log out in 10 seconds or you will die!"

I'd like to only have ped in car.

EDIT: Actually it's better that way. I just changed text to "You are in combat! Don't log out or you will die!

if i change player's damage from source to local player does it work same way then ?.

Sorry i can't test right now only 2 plaeyers in my server.

Link to comment
  • Moderators

Only the client version can get this information. Also this event can be cancelled.

"onClientVehicleDamage"

local lastDamageTime = 0 
function VehicleGetDamageDayZ ( attacker, weapon, loss, x, y, z, tyre ) 
    local vehicle = getPedOccupiedVehicle( localPlayer ) 
    local timeNow = getTickCount() 
    if timeNow > lastDamageTime and source == vehicle and not getElementData ( localPlayer, "tempodosexo" ) then 
        if weapon and weapon > 1 and attacker and getElementType(attacker) == "player" then 
            lastDamageTime = timeNow+300 -- can only be executed every 300 ms. 
            setTimer (deslogger, 10000, 1, localPlayer) 
            setTimer ( setElementData, 10000, 1, localPlayer, "tempodosexo", false ) 
            setElementData ( localPlayer, "tempodosexo", true ) 
            outputChatBox ( "Your car received damage! Do not log out in 10 seconds or you will die!", localPlayer, 255, 5, 0 ) 
        end 
    end 
end 

You used getLocalPlayer instead of getLocalPlayer() or localPlayer.

Link to comment
  • Moderators

outputChatBox ( "Your car received damage! Do not log out in 10 seconds or you will die!", [color=#FF0000]localPlayer[/color], 255, 5, 0 ) 

outputChatBox ( "Your car received damage! Do not log out in 10 seconds or you will die!", 255, 5, 0 ) 

You don't have to send it to anybody at clientside, since you are the client.

Link to comment
  • Moderators
Still nothing, I tryed to remove if weapon and weapon stuff still wont work.

Debug your code with outputDebugString, if nobody can see why it doesn't work, you should make it visible.

@.:HyPeX:.

also in my experience, redefine localPlayer = getLocalPlayer() just in case.

You will make more trouble then fixing it, by redefine predefined variables.

and if you aren't sure they do work well, you can compare them with the function that returns that value.

if localPlayer == getLocalPlayer() then 

and you will be fine.

@THASMOG

I hope you can do that next time by yourself, instead of saying that you can't find your problem.

  
local lastDamageTime = 0 
function VehicleGetDamageDayZ ( attacker, weapon, loss, x, y, z, tyre ) 
    outputDebugString("addEventHandler works") 
    local vehicle = getPedOccupiedVehicle( localPlayer ) 
    local timeNow = getTickCount() 
    if timeNow > lastDamageTime and source == vehicle and not getElementData ( localPlayer, "tempodosexo" ) then 
        outputDebugString("tickCount system works, vehicle check works, elementdata check works") 
        outputDebugString("weapon: " .. tostring(weapon) .. ", attacker: "  .. tostring(attacker).. ", element type " .. tostring(attacker and getElementType(attacker))) 
         
        if weapon and weapon > 1 and attacker and getElementType(attacker) == "player" then 
            outputDebugString("weapon check works,attacker exist, element type is a player.") 
            lastDamageTime = timeNow+300 -- can only be executed every 300 ms. 
            setTimer (deslogger, 10000, 1, localPlayer) 
            setTimer ( setElementData, 10000, 1, localPlayer, "tempodosexo", false ) 
            setElementData ( localPlayer, "tempodosexo", true ) 
            outputChatBox ( "Your car received damage! Do not log out in 10 seconds or you will die!", localPlayer, 255, 5, 0 ) 
        end 
    end 
end 
  
addEventHandler ( "onClientVehicleDamage", root, VehicleGetDamageDayZ ) 
 outputDebugString("code loaded!") 
  

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