Jump to content

Script Problem


Recommended Posts

hey guys I'm trying to make a script that checks if the player is in the car and then tells the player that he's in a car, but it doesn't work, what can i do?.

 

I want the script to work through command I don't want events.

 

Code :

function insideCar( source , player )
   		local pos = getElementPosition(getLocalPlayer(player))     
			if  isPlayerInVehicle(pos) then
     outputChatBox("You're in the car"..getPlayerName(source), source)
  else 
        outputChatBox("You're on foot", source)
    end
          end
addCommandHandler("check",insideCar)

thanks.

Link to comment
1 hour ago, ABU.OMAR</> said:

hey guys I'm trying to make a script that checks if the player is in the car and then tells the player that he's in a car, but it doesn't work, what can i do?.

 

I want the script to work through command I don't want events.

 

Code :

function insideCar( source , player )
   		local pos = getElementPosition(getLocalPlayer(player))     
			if  isPlayerInVehicle(pos) then
     outputChatBox("You're in the car"..getPlayerName(source), source)
  else 
        outputChatBox("You're on foot", source)
    end
          end
addCommandHandler("check",insideCar)

thanks.

function insideCar(source)
    local thePlayer = source
    local vehicle = getPedOccupiedVehicle(thePlayer)
    
    if vehicle then
        outputChatBox("You're in a car", thePlayer)
    else 
        outputChatBox("You're on foot", thePlayer)
    end
end
addCommandHandler("check", insideCar)

 

  • Like 1
Link to comment
2 hours ago, ABU.OMAR</> said:

hey guys I'm trying to make a script that checks if the player is in the car and then tells the player that he's in a car, but it doesn't work, what can i do?.

 

I want the script to work through command I don't want events.

 

Code :

function insideCar( source , player )
   		local pos = getElementPosition(getLocalPlayer(player))     
			if  isPlayerInVehicle(pos) then
     outputChatBox("You're in the car"..getPlayerName(source), source)
  else 
        outputChatBox("You're on foot", source)
    end
          end
addCommandHandler("check",insideCar)

thanks.

I think comments aobve me already answered your question, but i suggest you to re-visit LUA and scripting basics, since in your code you have to parameters, the first is source and the second is player, but in this case the source and the play are the same thing.

  • Like 2
Link to comment

omg it's simple more than i thought, thank you guys!.

5 hours ago, coNolel said:

I think comments aobve me already answered your question, but i suggest you to re-visit LUA and scripting basics, since in your code you have to parameters, the first is source and the second is player, but in this case the source and the play are the same thing.

thanks bro for correcting me, i will do that.

Link to comment

guys the codes you write don't work properly , it gives me an argument error,

so I tried another way I used a "local player" parameter and its works fine!
 

i don't know how that happens but it works.

 

and this is the specific code:

 

function insideCar( source )
    local vehicle = getPedOccupiedVehicle(localPlayer)
    if vehicle then
        outputChatBox("You're in a car", source)
    else
        outputChatBox("You're on foot", source)
    end
end
addCommandHandler("check", insideCar)

 

anyway thank you for your efforts guys appreciated.

 

Edited by ABU.OMAR</>
Link to comment
--server side
function insideCar(player) --define player here so we know whom used the commandhandler
    local vehicle = getPedOccupiedVehicle(player) --is he in  a car?
    if vehicle then
        outputChatBox("You're in a car", player) --serverside we need to specifie the player we output to, else we outpoot to root (all players)
    else
        outputChatBox("You're on foot", player)
    end
end
addCommandHandler("check", insideCar)

-------------------------------------------------------------------------------------------------------------
--and for client you use it like that 'localPlayer' is a client only variable
function insideCar()
    local vehicle = getPedOccupiedVehicle(localPlayer)
    if vehicle then
        outputChatBox("You're in a car") --clientside outputChatBox outputs directlly to the client in question
    else
        outputChatBox("You're on foot")
    end
end
addCommandHandler("check", insideCar)

Do you know the difference between client/server scripts?

Link to comment
2 hours ago, Tekken said:
--server side
function insideCar(player) --define player here so we know whom used the commandhandler
    local vehicle = getPedOccupiedVehicle(player) --is he in  a car?
    if vehicle then
        outputChatBox("You're in a car", player) --serverside we need to specifie the player we output to, else we outpoot to root (all players)
    else
        outputChatBox("You're on foot", player)
    end
end
addCommandHandler("check", insideCar)

-------------------------------------------------------------------------------------------------------------
--and for client you use it like that 'localPlayer' is a client only variable
function insideCar()
    local vehicle = getPedOccupiedVehicle(localPlayer)
    if vehicle then
        outputChatBox("You're in a car") --clientside outputChatBox outputs directlly to the client in question
    else
        outputChatBox("You're on foot")
    end
end
addCommandHandler("check", insideCar)

Do you know the difference between client/server scripts?

I understood bro, honestly I don't have an experience in scripting with LUA, so thanks for explaining to me the different between server & client.

so you mean in the client side there's no need to use source or any parameter because it automatically gives the value to the client?

thanks.

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