Jump to content

Need help with my script


Hussain

Recommended Posts

I have problem with my script it doesn't work.. It doesn't start when I try to run it I don't know why... Here is my code :

function teamName ( Police ) 
    local playerTeam = getPlayerTeam ( source ) 
    if ( playerTeam ) Police then 
    
    function wanted () 
local wantedLvl = getPlayerWantedLevel ( ) 
   if wantedLvl == 0 then 
    
   function showLocalHealth() 
    local playerHealth = getElementHealth ( getLocalPlayer() ) 
    if playerHealth then 
    
    function hpSlap ( sourcePlayer, command, targetPlayerName ) 
    if not hasObjectPermissionTo(sourcePlayer, "command.slap", false) then 
        return false 
    end 
    local targetPlayer = getPlayerFromName ( targetPlayerName ) 
    if targetPlayer then 
        setElementHealth ( targetPlayer, getElementHealth(targetPlayer) - 20 ) 
end 
  
    addCommandHandler ( onPlayerDamage, "wanted", "showhealth", "hpslap", hpSlap ) 

I know there are many mistakes

Because i'm junior scripter

--

I want make script for police team

When the police hit unwanted player

Police get slap for 20 -

For all time he hit the unwanted player

Link to comment
function OnPlayerIsDamaged(attacker, attackerweapon, bodypart, loss) 
  
    -- In this function, "source" is the player damaged. 
    PlayerWantedLevel = getPlayerWantedLevel(source) 
    AttackerTeam      = getPlayerTeam(attacker) 
     
    if(PlayerWantedLevel == 0) then 
        if(AttackerTeam == "Police") then 
            setElementHealth(source, getElementHealth(source) + loss) --Health of player damaged 
            setElementHealth(attacker, getElementHealth(attacker) - 20) --Health of cop (who shot) 
            outputChatBox("Don't shot unwanted players or you will lose health!", attacker, 255, 0, 0) 
        end 
    end 
end 
addEventHandler("onPlayerDamage", getRootElement(), OnPlayerIsDamaged) 

Try it. I don't know if it will works, but you can try. In the line 9, I can't use cancelEvent() (because the event "onPlayerDamaged" don't accept), so I tried improvise.

Oh, and remember friend: for this script works, the cop must be on the team "Police" (lua is case-sensitive, so is "Police" and not "police"). To create a team, use the function:

createTeam() 

Link to comment

How can i add this code

fuction copyright 
outputChatBox ( "#FF0000Harm Script Made By : #00FF00Hussein", getRootElement(), 255, 255, 255, true ) 
addEventHandler ( "onResourceStart" ) 

to this

function OnPlayerIsDamaged(attacker, attackerweapon, bodypart, loss) 
  
    -- In this function, "source" is the player damaged. 
    PlayerWantedLevel = getPlayerWantedLevel(source) 
    AttackerTeam      = getPlayerTeam(attacker) 
    
    if(PlayerWantedLevel == 0) then 
        if(AttackerTeam == "Police") then 
            setElementHealth(source, getElementHealth(source) + loss) --Health of player damaged 
            setElementHealth(attacker, getElementHealth(attacker) - 20) --Health of cop (who shot) 
            outputChatBox("Don't shot unwanted players or you will lose health!", attacker, 255, 0, 0) 
        end 
    end 
end 
addEventHandler("onPlayerDamage", getRootElement(), OnPlayerIsDamaged) 

I want when i start the script he make outputChatBox This

outputChatBox ( "#FF0000Harm Script Made By : #00FF00Hussein", getRootElement(), 255, 255, 255, true ) 
  

That what i want

then i will test the script :D

Link to comment

i swear it's not Hard to add it :lol:

function OnPlayerIsDamaged(attacker, attackerweapon, bodypart, loss) 
    PlayerWantedLevel = getPlayerWantedLevel(source) 
    AttackerTeam      = getPlayerTeam(attacker) 
    if(PlayerWantedLevel == 0) then 
        if(AttackerTeam == "Police") then 
            setElementHealth(source, getElementHealth(source) + loss) 
            setElementHealth(attacker, getElementHealth(attacker) - 20) 
            outputChatBox("Don't shot unwanted players or you will lose health!", attacker, 255, 0, 0) 
        end 
    end 
end 
addEventHandler("onPlayerDamage", getRootElement(), OnPlayerIsDamaged) 
  
addEventHandler('onResourceStart', root, 
function() 
outputChatBox ( "#FF0000Harm Script Made By : #00FF00Hussein", getRootElement(), 255, 255, 255, true ) 
end) 

Link to comment
i swear it's not Hard to add it :lol:
function OnPlayerIsDamaged(attacker, attackerweapon, bodypart, loss) 
    PlayerWantedLevel = getPlayerWantedLevel(source) 
    AttackerTeam      = getPlayerTeam(attacker) 
    if(PlayerWantedLevel == 0) then 
        if(AttackerTeam == "Police") then 
            setElementHealth(source, getElementHealth(source) + loss) 
            setElementHealth(attacker, getElementHealth(attacker) - 20) 
            outputChatBox("Don't shot unwanted players or you will lose health!", attacker, 255, 0, 0) 
        end 
    end 
end 
addEventHandler("onPlayerDamage", getRootElement(), OnPlayerIsDamaged) 
  
addEventHandler('onResourceStart', root, 
function() 
outputChatBox ( "#FF0000Harm Script Made By : #00FF00Hussein", getRootElement(), 255, 255, 255, true ) 
end) 

Thanks but when i run any script it ouputChatBox my name :?

Link to comment
Guest Guest4401

you must use resourceRoot instead of root.

Important: If you attach this event to the root element it will called when any resource starts, not just the resource your script is running inside. As such, most of the time you will want to check that the resource passed to this event matches your resource (compare with the value returned by getThisResource) before doing anything. Alternatively you can attach the event to getResourceRootElement(getThisResource()).
Link to comment
you must use resourceRoot instead of root.
Important: If you attach this event to the root element it will called when any resource starts, not just the resource your script is running inside. As such, most of the time you will want to check that the resource passed to this event matches your resource (compare with the value returned by getThisResource) before doing anything. Alternatively you can attach the event to getResourceRootElement(getThisResource()).

Like this ?

function OnPlayerIsDamaged(attacker, attackerweapon, bodypart, loss) 
    PlayerWantedLevel = getPlayerWantedLevel(source) 
    AttackerTeam      = getPlayerTeam(attacker) 
    if(PlayerWantedLevel == 0) then 
        if(AttackerTeam == "Police") then 
            setElementHealth(source, getElementHealth(source) + loss) 
            setElementHealth(attacker, getElementHealth(attacker) - 20) 
            outputChatBox("Don't shot unwanted players or you will lose health!", attacker, 255, 0, 0) 
        end 
    end 
end 
addEventHandler("onPlayerDamage", getRootElement(), OnPlayerIsDamaged) 
  
addEventHandler (getResourceRootElement(getThisResource(Harm_Hussein), root, 
function() 
outputChatBox ( "#FF0000Harm Script Made By : #00FF00Hussein", getRootElement(), 255, 255, 255, true ) 
end) 

Link to comment
Guest Guest4401
addEventHandler ("onResourceStart", resourceRoot, 
function() 
outputChatBox ( "#FF0000Harm Script Made By : #00FF00Hussein", getRootElement(), 255, 255, 255, true ) 
end) 

Link to comment
function OnPlayerIsDamaged(attacker,_,_,loss) 
local PlayerWantedLevel = getPlayerWantedLevel(source) 
local AttackerTeam = getPlayerTeam(attacker) 
     if PlayerWantedLevel == 0 then 
          if AttackerTeam == getTeamFromName("Police") then 
          setElementHealth(source, getElementHealth(source) + loss) 
          setElementHealth(attacker, getElementHealth(attacker) - 20) 
          outputChatBox("Don't shot unwanted players or you will lose health!", attacker, 255, 0, 0) 
          end 
     end 
end 
addEventHandler("onPlayerDamage", root, OnPlayerIsDamaged) 
  
addEventHandler("onResourceStart", resourceRoot, 
function() 
outputChatBox("#FF0000Harm Script Made By : #00FF00Hussein", root, 255, 255, 255, true) 
end) 

Link to comment
function OnPlayerIsDamaged(attacker,_,_,loss) 
local PlayerWantedLevel = getPlayerWantedLevel(source) 
local AttackerTeam = getPlayerTeam(attacker) 
     if PlayerWantedLevel == 0 then 
          if AttackerTeam == getTeamFromName("Police") then 
          setElementHealth(source, getElementHealth(source) + loss) 
          setElementHealth(attacker, getElementHealth(attacker) - 20) 
          outputChatBox("Don't shot unwanted players or you will lose health!", attacker, 255, 0, 0) 
          end 
     end 
end 
addEventHandler("onPlayerDamage", root, OnPlayerIsDamaged) 
  
addEventHandler("onResourceStart", resourceRoot, 
function() 
outputChatBox("#FF0000Harm Script Made By : #00FF00Hussein", root, 255, 255, 255, true) 
end) 

Thanks very much !

I will test it later .

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