Jump to content

[Help] Searching for Workaround


BieHDC

Recommended Posts

hello,

i know that we cant "send" Elements to server with triggerServerEvent, so i was looking for a workaround with getPlayerName and getPlayerFromName, but it wont work :/

Here is my code, maybe you find the fail.

This is only a "try-out" example with no sense:

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

--serverside 
function whokilledvic ( thehittername, thehittedname ) 
local hitterp = getPlayerFromName( thehittername ) 
local hittedp = getPlayerFromName( thehittedname ) 
outputChatBox( hitterp.. " > hitted > " ..hittedp , root ) 
end 
addEvent ( "whowasit", true ) 
addEventHandler ( "whowasit", root, whokilledvic ) 

Link to comment
hello,

i know that we cant "send" Elements to server with triggerServerEvent, so i was looking for a workaround with getPlayerName and getPlayerFromName, but it wont work :/

Here is my code, maybe you find the fail.

This is only a "try-out" example with no sense:

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

--serverside 
function whokilledvic ( thehittername, thehittedname ) 
local hitterp = getPlayerFromName( thehittername ) 
local hittedp = getPlayerFromName( thehittedname ) 
outputChatBox( hitterp.. " > hitted > " ..hittedp , root ) 
end 
addEvent ( "whowasit", true ) 
addEventHandler ( "whowasit", root, whokilledvic ) 

this will never work;

if ( source == getPedOccupiedVehicle(getLocalPlayer()) ) then 

The source is the vehicle that hits the collision. If you want to do something like that, then try this;

if ( getPedOccupiedVehicle ( source ) == getLocalPlayer() ) then  

Link to comment

but mine worked because i got the trigger to the server -.-

you said source is vehicle and getPedOccupiedVehicle returns theVehicle!

so my code it right! yours is false because the source is already the vehicle you messed up getVehicleOccupant ( needs the vehicle and returns player) and getPedOccupiedVehicle (needs player and returns Vehicle)

ok?

my problem is only that the two player names are not sucsessfully sent to server > thats the only thing i cant manage

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