Jump to content

script not working


Lukkaz

Recommended Posts

Not working, doesn't switch modes or anything I tried a million things. Thanks

server-side

  
  
local time = 10 --In seconds, time, when player is frozen 
  
function deaglemodes(localPlayer, number) 
local mode = tonumber(number) 
if mode == 0 then 
--tazer 
setElementData(localPlayer,"deaglemode", 0) 
elseif mode == 1 then 
--leathal 
setElementData(localPlayer,"deaglemode", 1) 
elseif mode ==2 then 
--radar 
setElementData(localPlayer,"deaglemode", 2) 
end 
end 
addEvent("deaglemode", true) 
addEventHandler("deaglemode", getRootElement(), deaglemodes, thePlayer, number) 
function tazerShot(hitX, hitY, hitZ, hitElement) 
    setPedFrozen ( source, true ) 
    setPedAnimation( source, "ped", "FLOOR_hit_f")   
    setTimer(setPedFrozen, time * 1000, 1, source, false) 
    setTimer(setPedAnimation, time * 1000, 1, source) 
end 
  
addEvent("tazerFired", true) 
addEventHandler("tazerFired", getRootElement(), tazerShot, hitX, hitY, hitZ, hitElement)    
  
function killmebyped(target) 
--killed by ped blahhhh 
end 
  
  

client-side

  
cooldown = 0 
cooldownTimer = nil 
localPlayer = getLocalPlayer() 
  
  
--function isPD() 
--  return exports.factions:isPlayerInFaction( localPlayer, 1 )  
--end 
  
function switchMode() 
    if (getPedWeapon(localPlayer)==24) and (getPedTotalAmmo(localPlayer)>0) then -- has ammo 
        local mode = getElementData(localPlayer, "deaglemode") 
        if mode == 0 then -- tazer mode 
            triggerServerEvent("deaglemode", localPlayer, 1) 
            outputChatBox( "You switched your weapon mode to lethal.", 0, 255, 0 ) 
        elseif mode == 1  
    --  and isPD()  
        then -- lethal mode 
            outputChatBox( "You switched your weapon to radar gun.", 0, 255, 0 ) 
            triggerServerEvent("deaglemode", localPlayer, 2) 
        elseif mode == 2 or mode == 1 then -- radar gun mode 
            outputChatBox( "You switched your weapon to taser.", 0, 255, 0 ) 
            triggerServerEvent("deaglemode", localPlayer, 0) 
        end 
    end 
end 
  
function bindKeys(res) 
    bindKey("n", "down", switchMode) 
     
    local mode = getElementData(localPlayer, "deaglemode") 
    if not (mode) then triggerServerEvent("deaglemode", localPlayer, 0) end 
end 
addEventHandler("onClientResourceStart", getResourceRootElement(), bindKeys) 
  
function enableCooldown() 
    cooldown = 1 
    cooldownTimer = setTimer(disableCooldown, 3000, 1) 
    toggleControl("fire", false) 
    setElementData(getLocalPlayer(), "deagle:reload", true) 
end 
  
function disableCooldown() 
    cooldown = 0 
    toggleControl("fire", true) 
    setElementData(getLocalPlayer(), "deagle:reload", false) 
  
    if (cooldownTimer~=nil) then 
        killTimer(cooldownTimer) 
        cooldownTimer = nil 
    end 
end 
addEventHandler("onClientPlayerWeaponSwitch", getRootElement(), disableCooldown) 
  
function weaponFire(weapon, ammo, ammoInClip, hitX, hitY, hitZ, hitElement) 
    if (weapon==24) then -- deagle 
        local mode = getElementData(localPlayer, "deaglemode") 
        if (mode==0) then -- tazer mode 
            enableCooldown() 
            local px, py, pz = getElementPosition(localPlayer) 
            local distance = getDistanceBetweenPoints3D(hitX, hitY, hitZ, px, py, pz) 
             
            if (distance<35) then 
                fxAddSparks(hitX, hitY, hitZ, 1, 1, 1, 1, 10, 0, 0, 0, true, 3, 1) 
            end 
            playSoundFrontEnd(38) 
            triggerServerEvent("tazerFired", localPlayer, hitX, hitY, hitZ, hitElement)  
        end 
    end 
end 
addEventHandler("onClientPlayerWeaponFire", localPlayer, weaponFire) 
  
function weaponAim(target) 
    if (target) then 
        if (getElementType(target)=="vehicle") then 
            if (getPedWeapon(localPlayer)==24) then 
                local mode = getElementData(localPlayer, "deaglemode") 
                 
                if (mode==2) then 
                    actualspeed = exports.global:getVehicleVelocity(target) 
                    outputChatBox(getVehicleName(target) .. " clocked in at " .. actualspeed .. " km/h.", 255, 194, 14) 
                end 
            end 
        end 
    end 
end 
addEventHandler("onClientPlayerTarget", getRootElement(), weaponAim) 
  
-- code for the target/tazed person 
function cancelTazerDamage(attacker, weapon, bodypart, loss) 
    if (weapon==24) then -- deagle 
        local mode = getElementData(attacker, "deaglemode") 
        if (mode==0 or mode==2) then -- tazer mode / radar gun mode 
            cancelEvent() 
        end 
    end 
end 
addEventHandler("onClientPlayerDamage", localPlayer, cancelTazerDamage) 
  
function showTazerEffect(x, y, z) 
    fxAddSparks(x, y, z, 1, 1, 1, 1, 100, 0, 0, 0, true, 3, 2) 
    playSoundFrontEnd(38) 
end 
addEvent("showTazerEffect", true ) 
addEventHandler("showTazerEffect", getRootElement(), showTazerEffect) 
  
local underfire = false 
local fireelement = nil 
local localPlayer = getLocalPlayer() 
local originalRot = 0 
local shotsfired = 0 
  
function onTargetPDPed(element) 
    if (isElement(element)) then 
        if (getElementType(element)=="ped") and (getElementModel(element)==282 or getElementModel(element)==280 or getElementModel(element)==285) and not (underfire) and (getControlState("aim_weapon")) then 
            underfire = true 
            fireelement = element 
            originalRot = getPedRotation(element) 
            addEventHandler("onClientRender", getRootElement(), makeCopFireOnPlayer) 
            addEventHandler("onClientPlayerWasted", getLocalPlayer(), onDeath) 
        end 
    end 
end 
addEventHandler("onClientPlayerTarget", getLocalPlayer(), onTargetPDPed) 
  
function makeCopFireOnPlayer() 
    if (underfire) and (fireelement) then 
        local rot = getPedRotation(localPlayer) 
        local x, y, z = getPedBonePosition(localPlayer, 7) 
         
        setPedRotation(fireelement, rot - 180) 
         
        setPedControlState(fireelement, "aim_weapon", true) 
        setPedAimTarget(fireelement, x, y, z) 
        setPedControlState(fireelement, "fire", true) 
        shotsfired = shotsfired + 1 
         
    --  if (shotsfired>40) then 
    --      triggerServerEvent("killmebyped", getLocalPlayer(), fireelement) 
    --  end 
    end 
end 
  
function onDeath() 
    if (fireelement) and (underfire) then 
        setPedControlState(fireelement, "aim_weapon", false) 
        setPedControlState(fireelement, "fire", false) 
        setPedRotation(fireelement, originalRot) 
         
        fireelement = nil 
        underfire = false 
        removeEventHandler("onClientRender", getRootElement(), makeCopFireOnPlayer) 
        removeEventHandler("onClientPlayerWasted", getLocalPlayer(), onDeath) 
    end 
end 
  

Link to comment

This had lot of errors that you could have fixed,

--client side

cooldown = 0 
cooldownTimer = nil 
localPlayer = getLocalPlayer() 
  
  
--function isPD() 
--  return exports.factions:isPlayerInFaction( localPlayer, 1 ) 
--end 
  
function switchMode() 
    if (getPedWeapon(localPlayer)==24) and (getPedTotalAmmo(localPlayer)>0) then -- has ammo 
        local mode = getElementData(localPlayer, "deaglemode") 
        if mode == 0 then -- tazer mode 
            triggerServerEvent("deaglemode", localPlayer, localPlayer, 1) 
            outputChatBox( "You switched your weapon mode to lethal.", 0, 255, 0 ) 
        elseif mode == 1 
    --  and isPD() 
        then -- lethal mode 
            outputChatBox( "You switched your weapon to radar gun.", 0, 255, 0 ) 
            triggerServerEvent("deaglemode", localPlayer, localPlayer, 2) 
        elseif mode == 2 or mode == 1 then -- radar gun mode 
            outputChatBox( "You switched your weapon to taser.", 0, 255, 0 ) 
            triggerServerEvent("deaglemode", localPlayer, localPlayer, 0) 
        end 
    end 
end 
  
function bindKeys(res) 
    bindKey("n", "down", switchMode) 
    local mode = getElementData(localPlayer, "deaglemode") 
    if not (mode) then triggerServerEvent("deaglemode", localPlayer, localPlayer, 0) end 
end 
addEventHandler("onClientResourceStart", getResourceRootElement(), bindKeys) 
  
function enableCooldown() 
    cooldown = 1 
    cooldownTimer = setTimer(disableCooldown, 3000, 1) 
    toggleControl("fire", false) 
    setElementData(getLocalPlayer(), "deagle:reload", true) 
end 
  
function disableCooldown() 
    cooldown = 0 
    toggleControl("fire", true) 
    setElementData(getLocalPlayer(), "deagle:reload", false) 
  
    if (cooldownTimer~=nil) then 
        killTimer(cooldownTimer) 
        cooldownTimer = nil 
    end 
end 
addEventHandler("onClientPlayerWeaponSwitch", getRootElement(), disableCooldown) 
  
function weaponFire(weapon, ammo, ammoInClip, hitX, hitY, hitZ, hitElement) 
    if (weapon==24) then -- deagle 
        local mode = getElementData(localPlayer, "deaglemode") 
        if (mode==0) then -- tazer mode 
            enableCooldown() 
            local px, py, pz = getElementPosition(localPlayer) 
            local distance = getDistanceBetweenPoints3D(hitX, hitY, hitZ, px, py, pz) 
            
            if (distance<35) then 
                fxAddSparks(hitX, hitY, hitZ, 1, 1, 1, 1, 10, 0, 0, 0, true, 3, 1) 
            end 
            playSoundFrontEnd(38) 
            triggerServerEvent("tazerFired", localPlayer, hitX, hitY, hitZ, hitElement) 
        end 
    end 
end 
addEventHandler("onClientPlayerWeaponFire", localPlayer, weaponFire) 
  
function weaponAim(target) 
    if (target) then 
        if (getElementType(target)=="vehicle") then 
            if (getPedWeapon(localPlayer)==24) then 
                local mode = getElementData(localPlayer, "deaglemode") 
                
                if (mode==2) then 
                    actualspeed = exports.global:getVehicleVelocity(target) 
                    outputChatBox(getVehicleName(target) .. " clocked in at " .. actualspeed .. " km/h.", 255, 194, 14) 
                end 
            end 
        end 
    end 
end 
addEventHandler("onClientPlayerTarget", getRootElement(), weaponAim) 
  
-- code for the target/tazed person 
function cancelTazerDamage(attacker, weapon, bodypart, loss) 
    if (weapon==24) then -- deagle 
        local mode = getElementData(attacker, "deaglemode") 
        if (mode==0 or mode==2) then -- tazer mode / radar gun mode 
            cancelEvent() 
        end 
    end 
end 
addEventHandler("onClientPlayerDamage", localPlayer, cancelTazerDamage) 
  
function showTazerEffect(x, y, z) 
    fxAddSparks(x, y, z, 1, 1, 1, 1, 100, 0, 0, 0, true, 3, 2) 
    playSoundFrontEnd(38) 
end 
addEvent("showTazerEffect", true ) 
addEventHandler("showTazerEffect", getRootElement(), showTazerEffect) 
  
local underfire = false 
local fireelement = nil 
local localPlayer = getLocalPlayer() 
local originalRot = 0 
local shotsfired = 0 
  
function onTargetPDPed(element) 
    if (isElement(element)) then 
        if (getElementType(element)=="ped") and (getElementModel(element)==282 or getElementModel(element)==280 or getElementModel(element)==285) and not (underfire) and (getControlState("aim_weapon")) then 
            underfire = true 
            fireelement = element 
            originalRot = getPedRotation(element) 
            addEventHandler("onClientRender", getRootElement(), makeCopFireOnPlayer) 
            addEventHandler("onClientPlayerWasted", getLocalPlayer(), onDeath) 
        end 
    end 
end 
addEventHandler("onClientPlayerTarget", getLocalPlayer(), onTargetPDPed) 
  
function makeCopFireOnPlayer() 
    if (underfire) and (fireelement) then 
        local rot = getPedRotation(localPlayer) 
        local x, y, z = getPedBonePosition(localPlayer, 7) 
        
        setPedRotation(fireelement, rot - 180) 
        
        setPedControlState(fireelement, "aim_weapon", true) 
        setPedAimTarget(fireelement, x, y, z) 
        setPedControlState(fireelement, "fire", true) 
        shotsfired = shotsfired + 1 
        
    --  if (shotsfired>40) then 
    --      triggerServerEvent("killmebyped", getLocalPlayer(), fireelement) 
    --  end 
    end 
end 
  
function onDeath() 
    if (fireelement) and (underfire) then 
        setPedControlState(fireelement, "aim_weapon", false) 
        setPedControlState(fireelement, "fire", false) 
        setPedRotation(fireelement, originalRot) 
        
        fireelement = nil 
        underfire = false 
        removeEventHandler("onClientRender", getRootElement(), makeCopFireOnPlayer) 
        removeEventHandler("onClientPlayerWasted", getLocalPlayer(), onDeath) 
    end 
end 

--server side

local time = 10 --In seconds, time, when player is frozen 
  
function deaglemodes(localPlayer, number) 
local mode = tonumber(number) 
if mode == 0 then 
--tazer 
setElementData(localPlayer,"deaglemode", 0) 
elseif mode == 1 then 
--leathal 
setElementData(localPlayer,"deaglemode", 1) 
elseif mode ==2 then 
--radar 
setElementData(localPlayer,"deaglemode", 2) 
end 
end 
addEvent("deaglemode", true) 
addEventHandler("deaglemode", getRootElement(), deaglemodes) 
  
function tazerShot(hitX, hitY, hitZ, hitElement) 
    setPedFrozen ( source, true ) 
    setPedAnimation( source, "ped", "FLOOR_hit_f")  
    setTimer(setPedFrozen, time * 1000, 1, source, false) 
    setTimer(setPedAnimation, time * 1000, 1, source) 
end 
  
addEvent("tazerFired", true) 
addEventHandler("tazerFired", getRootElement(), tazerShot, hitX, hitY, hitZ, hitElement)   
  
function killmebyped(target) 
--killed by ped blahhhh 
end 

P.S: Next time ask it better, because that's not the way to ask for help.

Link to comment

thanks guys, but now the speed isn't registering and just tell me "bad ped pointer" in the debug.....

the function to tell the speed

  
function weaponAim(target) 
    if (target) then 
        if (getElementType(target)=="vehicle") then 
            if (getPedWeapon(localPlayer)==24) then 
                local mode = getElementData(localPlayer, "deaglemode") 
                
                if (mode==2) then 
                    actualspeed = exports.global:getVehicleVelocity(target) 
                    outputChatBox(getVehicleName(target) .. " clocked in at " .. actualspeed .. " km/h.", 255, 194, 14) 
                end 
            end 
        end 
    end 
end 
  

the global function

  
function getVehicleVelocity(target) 
local driver = target 
    if isPedInVehicle(driver) then 
        local vx, vy, vz = getElementVelocity(getPedOccupiedVehicle(driver)) 
        return math.sqrt(vx^2 + vy^2 + vz^2) * 161 
    end 
    return 0 
  
end 
  

Ideas? I'm stumped

Link to comment

if it's a vehicle:

  
if (getElementType(target)=="vehicle") then 
  actualspeed = exports.global:getVehicleVelocity(target) 
  

the why are you trying to:

  
 function getVehicleVelocity(target) 
 local driver = target 
     if isPedInVehicle(driver) then 
  

?

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