Jump to content

Hard problem : About the following system


jingzhi

Recommended Posts

Posted

Client-side

  
addEvent("onPlayerArrested",true) 
function cuffed(arrester,source)     
local x,y,z = getElementPosition(arrester) 
            local fx,fy,fz = getElementPosition(arrestedcriminal) 
            local distance = getDistanceBetweenPoints2D(fx,fy,x,y) 
                if distance < 2 then 
                setControlState("forwards", false) 
                setControlState("sprint", false ) 
                setTimer (cuffed, 500, 0, arrester, arrestedcriminal ) 
                return 
                else 
                setControlState("forwards", true) 
                setControlState("sprint", true ) 
                setTimer ( cuffed, 500, 0, arrester, arrestedcriminal ) 
                local X,Y = 0,0 
                local X = math.abs( x - fx ) 
                local Y = math.abs( y - fy ) 
                local angle = math.deg(math.atan2(X/Y)) 
                    if ( x > fx ) and ( y > fy ) then 
                        angle = 90 - angle 
                    elseif ( x > fx ) and ( y < fy ) then 
                        angle = 270 + angle 
                    elseif ( x < fx ) and ( y > fy ) then 
                        angle = 90 + angle 
                    elseif ( x < fx ) and ( y < fy ) then 
                        angle = 270 - angle 
                        setElementRotation( arrestedcriminal, angle ) 
                    end 
                    end 
                    end 
addEventHandler("onPlayerArrested",getRootElement(),cuffed) 

Server-side

  
function arrest(arrester,nightstick) 
    if getPlayerTeam(arrester) == getTeamFromName("Police") or getTeamFromName("Speed Enforcement") then 
        if nightstick == 3 then 
            outputChatBox("weapon value correct")         
            if getPlayerWantedLevel(source) > 0 then       
            arrestedcriminal = source     
            if triggerClientEvent(source,"onPlayerArrested",source,source) == true then 
            outputChatBox("clientside event triggered")   
                end         
            end 
        end 
    end 
end 
            
addEventHandler("onPlayerDamage",getRootElement(),arrest) 

Hey so I wrote this script for after a player being arrested he is forced to follow the police, but it doesn't work. No error is showed, i tried to use outputchatbox to see i found out the server side seems good, please help me :|

Posted
  
  
addEvent("onPlayerArrested",true) 
function cuffed(arrester) 
arrestedcriminal = source 
local x,y,z = getElementPosition(arrester) 
            local fx,fy,fz = getElementPosition(arrestedcriminal) 
            local distance = getDistanceBetweenPoints2D(fx,fy,x,y) 
                if distance < 2 then 
                setControlState("forwards", false) 
                setControlState("sprint", false ) 
                setTimer (cuffed, 500, 0, arrester, arrestedcriminal ) 
                return 
                else 
                setControlState("forwards", true) 
                setControlState("sprint", true ) 
                setTimer ( cuffed, 500, 0, arrester, arrestedcriminal ) 
                local X,Y = 0,0 
                local X = math.abs( x - fx ) 
                local Y = math.abs( y - fy ) 
                local angle = math.deg(math.atan2(X/Y)) 
                    if ( x > fx ) and ( y > fy ) then 
                        angle = 90 - angle 
                    elseif ( x > fx ) and ( y < fy ) then 
                        angle = 270 + angle 
                    elseif ( x < fx ) and ( y > fy ) then 
                        angle = 90 + angle 
                    elseif ( x < fx ) and ( y < fy ) then 
                        angle = 270 - angle 
                        setElementRotation( arrestedcriminal, angle ) 
                    end 
                    end 
                    end 
addEventHandler("onPlayerArrested",getRootElement(),cuffed) 
  

  
triggerClientEvent(source,"onPlayerArrested",source,arrester) 
  

Currently developing for International Gaming Community - Join us!

Posted

Try this :

function followPolice(thecop, theprisoner) 
    if (isPedInVehicle(theprisoner)) then return end 
        local copx, copy, copz = getElementPosition (thecop) 
        local prisonerx, prisonery, prisonerz = getElementPosition (theprisoner) 
        copangle = (360 - math.deg (math.atan2 ((copx - prisonerx), (copy - prisonery)))) % 360 
        setPedRotation(theprisoner, copangle) 
        setCameraTarget(theprisoner, theprisoner) 
        local dist = getDistanceBetweenPoints2D (copx, copy, prisonerx, prisonery) 
  
      --Your code here  
     end   
  

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

Posted
  
  
addEvent("onPlayerArrested",true) 
function cuffed(arrester) 
arrestedcriminal = source 
local x,y,z = getElementPosition(arrester) 
            local fx,fy,fz = getElementPosition(arrestedcriminal) 
            local distance = getDistanceBetweenPoints2D(fx,fy,x,y) 
                if distance < 2 then 
                setControlState("forwards", false) 
                setControlState("sprint", false ) 
                setTimer (cuffed, 500, 0, arrester, arrestedcriminal ) 
                return 
                else 
                setControlState("forwards", true) 
                setControlState("sprint", true ) 
                setTimer ( cuffed, 500, 0, arrester, arrestedcriminal ) 
                local X,Y = 0,0 
                local X = math.abs( x - fx ) 
                local Y = math.abs( y - fy ) 
                local angle = math.deg(math.atan2(X/Y)) 
                    if ( x > fx ) and ( y > fy ) then 
                        angle = 90 - angle 
                    elseif ( x > fx ) and ( y < fy ) then 
                        angle = 270 + angle 
                    elseif ( x < fx ) and ( y > fy ) then 
                        angle = 90 + angle 
                    elseif ( x < fx ) and ( y < fy ) then 
                        angle = 270 - angle 
                        setElementRotation( arrestedcriminal, angle ) 
                    end 
                    end 
                    end 
addEventHandler("onPlayerArrested",getRootElement(),cuffed) 
  

  
triggerClientEvent(source,"onPlayerArrested",source,arrester) 
  

TY for answering but still not working :|

Posted
Try this :
function followPolice(thecop, theprisoner) 
    if (isPedInVehicle(theprisoner)) then return end 
        local copx, copy, copz = getElementPosition (thecop) 
        local prisonerx, prisonery, prisonerz = getElementPosition (theprisoner) 
        copangle = (360 - math.deg (math.atan2 ((copx - prisonerx), (copy - prisonery)))) % 360 
        setPedRotation(theprisoner, copangle) 
        setCameraTarget(theprisoner, theprisoner) 
        local dist = getDistanceBetweenPoints2D (copx, copy, prisonerx, prisonery) 
  
      --Your code here  
     end   
  

  
addEvent("onPlayerArrested",true) 
function cuffed(arrester,source)    
    if (isPedInVehicle(source)) then return end 
    local copx, copy, copz = getElementPosition (arrester) 
    local prisonerx, prisonery, prisonerz = getElementPosition (source) 
        copangle = (360 - math.deg (math.atan2 ((copx - prisonerx), (copy - prisonery)))) % 360 
        setPedRotation(theprisoner, copangle) 
        setCameraTarget(theprisoner, theprisoner) 
        local dist = getDistanceBetweenPoints2D (copx, copy, prisonerx, prisonery) 
        if dist < 2 then 
        setControlState("forwards", false) 
        setControlState("sprint", false ) 
        setTimer (cuffed, 500, 0, arrester, arrestedcriminal ) 
        else 
        setControlState("forwards", true) 
        setControlState("sprint", true ) 
        setTimer ( cuffed, 500, 0, arrester, arrestedcriminal ) 
    end 
end 
addEventHandler("onPlayerArrested",getRootElement(),cuffed) 

I did it like this, but its still not working :| , by the way what is %360 ?

  • Moderators
Posted

function cuffed(arrester,source)  
function cuffed(arrester)  

Never define a source variable as a parameter.

  
11 % 10 = 1 
21 % 10 = 1 
55 % 10 = 5 
53673465 % 10 = 5 
  
390 % 360 = 30 
721 % 360 = 1 
  
Rest value = % 

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

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted
function cuffed(arrester,source)  
function cuffed(arrester)  

Never define a source variable as a parameter.

  
11 % 10 = 1 
21 % 10 = 1 
55 % 10 = 5 
53673465 % 10 = 5 
  
390 % 360 = 30 
721 % 360 = 1 
  
Rest value = % 

Hey but in this case "source" is not really the source but is a parameter i passed down by "triggerClientEvent()", and also will what will 30 % 360 give me and -30 % 360 give me? :) thanks for help

Posted

30 % 360 = 30.

You still didn't understand: % = get the rest of the division. It's actually called 'modulo'.

30 % 360 = 30 because 360 > 30, that means the rest is the actual divided number.

For your understanding:

721 % 360 = 1. Why ? 721 / 360 = 2, rest = 1 => 721 = 360 * 2 + 1.

These are all basic mathematical operators. You should have had a basic understanding about it before even touching Lua.

Contact me if you are looking for a Web Developer.

3rd of October 2014 - Founder of RomaniaZ

  • Moderators
Posted
Hey but in this case "source" is not really the source but is a parameter i passed down by "triggerClientEvent()",

It is automatic defined, so don't have to write it down as parameter, or you will overwrite the source variable which will becomes useless.

  
triggerClientEvent( 
source, -- = sending to 
"onPlayerArrested", -- event 
source, -- = source 
  
arrester, -- = first parameter 
whatEver, -- = second parameter 
whatEver2 -- = third parameter 
----------------------------------------------------------------------------------------------------------- 
triggerClientEvent(source,"onPlayerArrested",source,arrester,whatEver,whatEver2) 

>

addEvent("onPlayerArrested",true) 
function cuffed(arrester,whatEver,whatEver2)  
    local mySource = source 
end 
addEventHandler("onPlayerArrested",getRootElement(),cuffed) 

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

 

  Useful functions  3x 

  Tutorials  4x 

 

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