Jump to content

Set player part nick


pejczi

Recommended Posts

Hey,

I want to set player's nick prefics as SPEC- using one command - but debugger returns :

"ERROR : spectators/spectator.lua:2: attempt to call global 'getPlayerFromNamePart' (a nil value)"

The code is :

function setTag ( source, command, thePlayer ) 
    local spec = getPlayerFromNamePart ( thePlayer ) 
    if ( spec ) then 
        if getElementType ( spec ) == "player" then 
            local oldName = getPlayerName ( spec ) 
            local newName = "SPEC-" .. oldName 
            setPlayerName ( spec, newName ) 
            outputChatBox ( "Player has been moved to SPEC team ", source ) 
        end 
    else 
        outputChatBox ( "Unable to move player to SPEC team " , source ) 
    end 
end 
addCommandHandler ( "spec" , setTag ) 

Yours Faithfully,

Pejczi.

Edited by Guest
Link to comment
There's no function called "getPlayerFromNamePart".

Do you want to add a prefix to a specific player? For example from Player1 to SPEC-Player1?

Yes, i'd like to. And it exists :

https://wiki.multitheftauto.com/wiki/Ge ... omNamePart

Ok, I've recognized that this function isn't predefined. Now it outputs "Player has been moved to SPEC team", but it doesn't add prefix.

function getPlayerFromNamePart(name) 
    if name then  
        for i, player in ipairs(getElementsByType("player")) do 
            if string.find(getPlayerName(player):lower(), tostring(name):lower(), 1, true) then 
                return player  
            end 
        end 
    end 
    return false 
end 
  
function setTag ( source, command, thePlayer ) 
    local spec = getPlayerFromNamePart ( thePlayer ) 
    if ( spec ) then 
        if getElementType ( spec ) == "player" then 
            local oldName = getPlayerName ( spec ) 
            local newName = "SPEC-" .. oldName 
            setPlayerName ( spec, newName ) 
            outputChatBox ( "Player has been moved to SPEC team ", source ) 
        end 
    else 
        outputChatBox ( "Unable to move player to SPEC team " , source ) 
    end 
end 
addCommandHandler ( "spec" , setTag ) 

Link to comment

Ok, i spotted the problem ; maximal character length of nick is 21 .

function deleteTag ( source, command, thePlayer ) 
    local spec = getPlayerFromNamePart ( thePlayer ) 
    if ( spec ) then 
        if getElementType ( spec ) == "player" then 
        local oldName = getPlayerName ( spec ) 
    setPlayerName ( spec , string.gsub ( oldName , "[s]" , "" ) ) 
        setPlayerTeam ( spec, nil ) 
        outputChatBox ( "Player has been removed from SPEC team" , source ) 
        end 
    else 
        outputChatBox ("Unable to remove player from SPEC team" , source ) 
        end 
end 
addCommandHandler ( "nospec" , deleteTag ) 

Why it removes just S, instead of ?

Link to comment

Not sure if it'll work but try this:

function deleteTag ( source, command, thePlayer ) 
    local spec = getPlayerFromNamePart ( thePlayer ) 
    if ( spec ) then 
        if getElementType ( spec ) == "player" then 
        local oldName = getPlayerName ( spec ) 
    setPlayerName ( spec , string.gsub ( oldName , "%[s%]" , "" ) ) 
        setPlayerTeam ( spec, nil ) 
        outputChatBox ( "Player has been removed from SPEC team" , source ) 
        end 
    else 
        outputChatBox ("Unable to remove player from SPEC team" , source ) 
        end 
end 
addCommandHandler ( "nospec" , deleteTag ) 

Link to comment

Ok, last trouble got elminated, now i've got other - the vehicle of spectator doesn't get blown.

function killTeam () 
        local theTeam = getTeamFromName ( "SPECTATORS" ) 
        if ( theTeam ) then 
        local players = getPlayersInTeam ( theTeam ) 
        for key, player in ipairs ( players ) do 
            local theVehicle = getPedOccupiedVehicle ( player ) 
            if ( theVehicle ) then 
                blowVehicle ( theVehicle ) 
                end 
            end 
        end 
    end 

I know, that the argument of blowVehicle is invalid, but i have no idea which do I have to put in.

Link to comment
Ok, last trouble got elminated, now i've got other - the vehicle of spectator doesn't get blown.
function killTeam () 
        local theTeam = getTeamFromName ( "SPECTATORS" ) 
        if ( theTeam ) then 
        local players = getPlayersInTeam ( theTeam ) 
        for key, player in ipairs ( players ) do 
            local theVehicle = getPedOccupiedVehicle ( player ) 
            if ( theVehicle ) then 
                blowVehicle ( source ) 
                end 
            end 
        end 
    end 

I know, that the argument of blowVehicle is invalid, but i have no idea which do I have to put in.

try using

destroyElement 

Link to comment
Ok, last trouble got elminated, now i've got other - the vehicle of spectator doesn't get blown.
function killTeam () 
        local theTeam = getTeamFromName ( "SPECTATORS" ) 
        if ( theTeam ) then 
        local players = getPlayersInTeam ( theTeam ) 
        for key, player in ipairs ( players ) do 
            local theVehicle = getPedOccupiedVehicle ( player ) 
            if ( theVehicle ) then 
                blowVehicle ( source ) 
                end 
            end 
        end 
    end 

I know, that the argument of blowVehicle is invalid, but i have no idea which do I have to put in.

try using

destroyElement 

But it's for race gamemode ; if the vehicle will get destroyed, then whole gamemode is getting bugged.

Link to comment

Jesus, I forgot to put eventhandler - when I put just "onRaceStateChanging", it has blown my car before counting - when i put if

if (state == "Running") , then it doesn't blow me.

////No help needed, i found out a problem. I had to put addEvent ;)

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