Sign in to follow this  
Plantjen

Very basic question about outputting to one player

Recommended Posts

I'm starting to learn a little bit of lua, but there's some very basic thingy that i just can't get right.

I have the following code in my server file that i use to lock/unlock cars. This code is from the speedometer(http://community.mtasa.com/index.html?p=resources&s=details&id=5) resource by 50p

function lock_unlockDoor( player )
local playername = getPlayerName ( player )
local veh = getPedOccupiedVehicle( player )
local lock = isVehicleLocked( veh )
if veh and lock == false then
setVehicleLocked( veh, true )
outputChatBox("Car locked",playername,255,255,0,255)
elseif veh and lock == true then
setVehicleLocked( veh, false )
outputChatBox("Car unlocked",playername,255,255,0,255)
end
end

I wanted to change it so that only the player that locks the car gets the message 'Car locked' or 'Car unlocked'. Currently if i lock a car, the message is shown to every player in the server. What have i done wrong? Any help will be very much appreciated :D

Share this post


Link to post

You output message to player NOT his name.

function lock_unlockDoor( player )
local veh = getPedOccupiedVehicle( player )
local lock = isVehicleLocked( veh )
if veh and lock == false then
setVehicleLocked( veh, true )
outputChatBox("Car locked",player,255,255,0,255)
elseif veh and lock == true then
setVehicleLocked( veh, false )
outputChatBox("Car unlocked",player,255,255,0,255)
end
end

Share this post


Link to post

Though it seems very strange to me it does work! Thank you a lot, now i can also make progress on other scripts :)

Share this post


Link to post

after you will learn something about elements - it wont be strange anymore.

btw: wiki clearly says: player element, not player name :)

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.