Jump to content

Auto Admin Paintjobber


DazzaJay

Recommended Posts

Got a small issue with this script, (Had lots of help from Mvol and a few others on it)

but it has a really stupid issue.

Basically, it checks to see if somone with "[PS]" in their name (such as [PS]DazzaJay[AU] or [PS]Riz ) and if they have that in their name, it checks their car, if their car is one of the types in the script, it sets it to a specific paintjob.

Problem is... its not working properly.

Well, it works, and works well. but its not detecting the Clan tag properly.

Like Line 6 clearly has this in it:

if ( string.find(name, "[PS]" )) then

So its clearly searching players names for [PS]

Problem is, if a player has ps in their name (note lowercase AND no brackets) it will also set thier paintjob.

So, it sets the paintjob of [PS]DazzaJay[AU] AND some random with the name "Jumpshit" all cos its not searching for the brackets, even tho it should be.

So, either there is somhing wrong with MTA not searching the brackets also, or theres somthing wrong with the script, (Which shows no errors in debug 3)

If its the script how do i fix.

if its MTA not searching the brackets, then i am guessing id have to add in another line somwhere that checks if the person with [PS] in their name has admin rights. and then set paint. (So basically If [PS] and admin, set paint, but if the player has only one or the other, don't set paint. (As some admins dont wear the tag for Sneaking purposes))

function setadminpaint() 
  local players = getElementsByType ( "player" ) 
  
  for theKey,thePlayer in ipairs(players) do 
    local name = getClientName ( thePlayer ) 
    if ( string.find(name, "[PS]" )) then 
      if ( isPlayerInVehicle ( thePlayer ) ) then 
        local thisPlayersVehicle = getPlayerOccupiedVehicle( thePlayer ) 
        local theVehicle = getVehicleNameFromID(getVehicleID(thisPlayersVehicle)) 
        if ( theVehicle == "Sultan" ) then 
          setVehiclePaintjob ( thisPlayersVehicle, 1 ) 
        end 
        if ( theVehicle == "Elegy" ) then 
          setVehiclePaintjob ( thisPlayersVehicle, 1 ) 
        end 
        if ( theVehicle == "Jester" ) then 
          setVehiclePaintjob ( thisPlayersVehicle, 0 ) 
        end 
        if ( theVehicle == "Blade" ) then 
          setVehiclePaintjob ( thisPlayersVehicle, 2 ) 
        end 
        if ( theVehicle == "Broadway" ) then 
          setVehiclePaintjob ( thisPlayersVehicle, 1 ) 
        end 
        if ( theVehicle == "Remington" ) then 
          setVehiclePaintjob ( thisPlayersVehicle, 2 ) 
        end 
        if ( theVehicle == "Slamvan" ) then 
          setVehiclePaintjob ( thisPlayersVehicle, 0 ) 
        end 
        if ( theVehicle == "Savanna" ) then 
          setVehiclePaintjob ( thisPlayersVehicle, 2 ) 
        end 
        if ( theVehicle == "Stratum" ) then 
          setVehiclePaintjob ( thisPlayersVehicle, 1 ) 
        end 
        if ( theVehicle == "Tornado" ) then 
          setVehiclePaintjob ( thisPlayersVehicle, 2 ) 
        end 
        if ( theVehicle == "Uranus" ) then 
          setVehiclePaintjob ( thisPlayersVehicle, 2 ) 
        end 
        if ( theVehicle == "Flash" ) then 
          setVehiclePaintjob ( thisPlayersVehicle, 2 ) 
        end 
      end 
    end 
  end 
  
end 
  
setTimer ( setadminpaint, 1000, 0 ) 

Link to comment

Probably would make sense to change it when the [PS] player enters a vehicle?

like

addEventHandler ( "onPlayerVehicleEnter", getRootElement(), function ( vehicle ) 
    local name = getClientName ( source ) 
    if ( not string.find ( name, "[PS]" ) ) then 
        return 
    end 
    local theVehicle = getVehicleName ( vehicle ) 
    if ( theVehicle == "Sultan" ) then 
        setVehiclePaintjob ( vehicle, 1 ) 
    elseif ( theVehicle == "Elegy" ) then 
        setVehiclePaintjob ( vehicle, 1 ) 
    elseif ( theVehicle == "Jester" ) then 
        setVehiclePaintjob ( vehicle, 0 ) 
    elseif ( theVehicle == "Blade" ) then 
        setVehiclePaintjob ( vehicle, 2 ) 
    elseif ( theVehicle == "Broadway" ) then 
        setVehiclePaintjob ( vehicle, 1 ) 
    elseif ( theVehicle == "Remington" ) then 
        setVehiclePaintjob ( vehicle, 2 ) 
    elseif ( theVehicle == "Slamvan" ) then 
        setVehiclePaintjob ( vehicle, 0 ) 
    elseif ( theVehicle == "Savanna" ) then 
        setVehiclePaintjob ( vehicle, 2 ) 
    elseif ( theVehicle == "Stratum" ) then 
        setVehiclePaintjob ( vehicle, 1 ) 
    elseif ( theVehicle == "Tornado" ) then 
        setVehiclePaintjob ( vehicle, 2 ) 
    elseif ( theVehicle == "Uranus" ) then 
        setVehiclePaintjob ( vehicle, 2 ) 
    elseif ( theVehicle == "Flash" ) then 
        setVehiclePaintjob ( vehicle, 2 ) 
    end 
end ) 

i'd use vehicle IDs and stick them in a table instead though

Link to comment

Correct me if I am wrong but doesn't the function do exactly what it's supposed to do? What you're basically saying with the brackets is "give me a match with all occurrences that include the pattern ps". I am not familiar with LUA pattern matching but what you want is a match with the pattern "[PS]" and not "ps". If this function works like I think it does you will have to find a way to make the brackets part of the pattern (most languages have something like backslash to escape special characters) and a switch to ignore lowercase.

Edited by Guest
Link to comment

Ace_Gambit is correct. The code is ok, but string.find, seeks for "patterns" therefore [ and ] are used to find characters between the brackets in a string. And if the characters are found it returns the character which was found or a number at which place it was found. Visit the link below.

For example:

string.find( "PS2", "[PS]" ) -- should return P or 1 

http://lua-users.org/wiki/PatternsTutorial

Link to comment

In util_server.lua from the Race mod, there's a function setVehiclePaintjobAndUpgrades() - I'd call your code from there. This ways it's not constantly on a timer setting values for the vehicle. Maybe it'd be nice in the next Race update to throw a Race-defined event (similar to entering the vehicle), so that code such as yours, could trap it and setup further car mods.

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