Jump to content

[Help] Trigger Server Event


BieHDC

Recommended Posts

Hello,

i wanna give the Server 2 elements, but only the 1st is sent sucsessfully.

Outputs: server line 4 > bad argument @ getvehicleaccupant

--clientside 
function collision ( thehitted ) 
    if thehitted and getElementType ( thehitted ) == "vehicle" then 
        if ( source == getPedOccupiedVehicle(getLocalPlayer()) ) then 
            triggerServerEvent ( "whowasit", source, thehitted ) 
        end 
    end 
end 
addEventHandler("onClientVehicleCollision", root, collision) 

--serverside 
function whokilledvic ( thehitter, thehitted ) 
local hitterp = getPlayerName(getVehicleOccupant( thehitter )) 
local hittedp = getPlayerName(getVehicleOccupant( thehitted )) 
setVehicleColor ( thehitter , 0, 0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 255 ) 
outputChatBox( hitterp.. " > hitted > " ..hittedp, root ) 
end 
addEvent ( "whowasit", true ) 
addEventHandler ( "whowasit", root, whokilledvic ) 

Link to comment
  • Moderators
--serverside 
    function whokilledvic ( thehitted ) 
    local thehitter = source 
    local hitterp = getPlayerName(getVehicleOccupant( thehitter )) 
    local hittedp = getPlayerName(getVehicleOccupant( thehitted )) 
    setVehicleColor ( thehitter , 0, 0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 255 ) 
    outputChatBox( hitterp.. " > hitted > " ..hittedp, root ) 
    end 
    addEvent ( "whowasit", true ) 
    addEventHandler ( "whowasit", root, whokilledvic ) 

theElement: The element that is the source of the event. This could be another player, or if this isn't relevant, use the root element.
triggerServerEvent ( string event, element theElement, [arguments...] )
Link to comment
  • Moderators

np.

btw something I did noticed about this event.

The event onClientVehicleCollision can be triggered a lot (just for a single scratch), if this player may have bad connection there is a chance that he will be timed out very quickly. So I recommend you to choose for a minimal force before sending info to the server.

element theHitElement, float force, int bodypart, float collisionX, float collisionY, float collisionZ, float normalX, float normalY, float normalZ, float hitElementForce, int model

Link to comment

i already noticed that and have done the following:

and it works :)

function collision ( thehitted ) 
    if hit == "false" then 
        if thehitted and getElementType ( thehitted ) == "vehicle" then 
            if ( source == getPedOccupiedVehicle(getLocalPlayer()) ) then 
                thehitted2 = thehitted 
                triggerServerEvent ( "whowasit", source, thehitted2 ) 
                hit = "true" 
                setTimer( resethittimer, 5000, 1 ) 
            end 
        end 
    end 
end 
addEventHandler("onClientVehicleCollision", root, collision) 
  
function resethittimer() 
hit = "false" 
end 

Link to comment
  • Moderators

I will recommend you only use timers, when there is no other way.

If you want to go for performance then:

local lastHit = getTickCount()   
local function collision ( thehitted ) 
    local tickTime = getTickCount() 
    if thehitted and tickTime > lastHit and getElementType ( thehitted ) == "vehicle" then 
        if source == getPedOccupiedVehicle(getLocalPlayer()) then 
            thehitted2 = thehitted 
            triggerServerEvent ( "whowasit", source, thehitted2 ) 
            lastHit = tickTime+1000 
        end 
    end 
end 
addEventHandler("onClientVehicleCollision", root, collision) 

Use gametime(getTickCount()) to check if amount of time has been past.

isn't 5 seconds very long? This is for DD right?

Link to comment

thx for the "better" code^ EDIT: it works :)

its a special DD, a revolution ;)

One is Victim and the others have to catch him.

If the victim hits a colsphere he wins and so on...

And yes its long, but what would be the right...if 1 sec then its flooding > think about if 20 players are messing around with one victim :D

and if the script is ready i will post in showcase and maybe you wanna develop with me if you think its a good one^

because i wrote it in noob style, because i am a beginner :P and i would need someone who can help me to unmess the code

Link to comment
  • Moderators

interesting idea,

It is your idea so you should development it in the first place, if there are any problems you can pm me any time.

(my response is sometimes quick and sometimes it can take 1/2 days)

I wish you good luck! :)

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