Jump to content

getPlayerName


Geramy92

Recommended Posts

function createVehicleForPlayer(thePlayer, command, vehicleModel)
   local playerName = getPlayerName ( thePlayer )
   -- Does he have access to Admin functions?
   if isObjectInACLGroup ( "user." .. playerName, aclGetGroup ( "Admin" ) ) then
	local x,y,z = getElementPosition(thePlayer) 
	x = x + 5 
	local createdVehicle = createVehicle(tonumber(vehicleModel),x,y,z)
	if (createdVehicle == false) then
		outputChatBox("Failed to create vehicle.",thePlayer)
	end
else
outputChatBox("Du bist nicht berechtigt!",thePlayer)
end
end

[01:48:31] ERROR: ...A/mods/deathmatch/resources/reallifemod/Reallife.lua:52: attempt to call

global 'getPlayerName' (a nil value)

what must i do to remove this error????

(the script whit getPlayerName is from wiki)

Link to comment

I bet you want to create a command:

function createVehicleForPlayer(playerSource, command, vehicleModel)
local playerName = getPlayerName ( playerSource )
-- Does he have access to Admin functions?
if isObjectInACLGroup ( "user." .. playerName, aclGetGroup ( "Admin" ) ) then
local x,y,z = getElementPosition(playerSource) 
	y = y - 5 
local createdVehicle = createVehicle(tonumber(vehicleModel),x,y,z)
if (createdVehicle == false) then
outputChatBox("Failed to create vehicle.", playerSource)
else
outputChatBox( getVehicleNameFromModel(vehicleModel).. " has been created for you!", playerSource)
end
else
outputChatBox("Du bist nicht berechtigt!", playerSource)
end
end
addCommandHandler ( "spawnveh", createVehicleForPlayer )

Just use a command /spawnveh 451 , this will spawn Turismo near you, for example.

Edited by Guest
Link to comment
I have a question about this script, when i am not a admin but join in the server with the admin name without login can i use the command spawnveh too?

Or must i do a login check after i ckeck the playername?

It work's for the non-admin player's with admin names, so yes you doesn't have to be admin.

You can use HasObjectPermissionTo instead of using isObjectInACLGroup

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