Sign in to follow this  
Andres99907

My code doesn't work :(

Recommended Posts

Posted (edited)

I'm trying to make a resource that obtain the name of a player like this line:

local who = getPlayerName(playerSource), playerSource(who)

but :( i got this

GetPlayerName  [expected element at argument 1, got nil]

lua:13: attempt to call global 'playerSource' (a nil value)

 

I need help :'c

 

the script is of the type server

Edited by Andres99907

Share this post


Link to post
Posted (edited)

function check ( player, seat, jacked )
if getElementData(source, "policeman") then
if getElementData(source, "owner") == getAccountName(getPlayerAccount(player)) then
else
cancelEvent()
outputChatBox("You need to be a Policeman", player)
end
end
end
addEventHandler ( "onVehicleStartEnter", getRootElement(), check )

function setcop(player, cmd, who)
local who = getPlayerName(playersource), setcop(who)
local co = getPedOccupiedVehicle(who)
setElementData(co, "policeman", true)
setElementData(co, "owner", getPlayerName(who))
outputChatBox("The Policeman:"..getPlayerName(who), player)
end

addEventHandler ( "onVehicleEnter", getRootElement(), setcop )

i made a few changes

Edited by Andres99907

Share this post


Link to post
Posted (edited)
function check ( player, seat, jacked )
if getElementData(source, "policeman") ==  true then
if getElementData(source, "owner") == getAccountName(getPlayerAccount(player)) then
else
cancelEvent()
outputChatBox("You need to be a Policeman", player)
end
end
end
addEventHandler ( "onVehicleStartEnter", getRootElement(), check )

function setcop(player, cmd)
setElementData(getPedOccupiedVehicle(player), "policeman", true)
setElementData(getPedOccupiedVehicle(player), "owner", getAccountName(getPlayerAccount(player)))
outputChatBox("The Policeman:"..getPlayerName(player), player)
end

addEventHandler ( "onVehicleEnter", getRootElement(), setcop )

 

Edited by Sendy
  • Like 1

Share this post


Link to post

Note ; use onVehicleStartEnter insted of onVehicleEnter

Because onVehicleEnter can't be cancelled

Share this post


Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.