mremin Posted December 7, 2010 Share Posted December 7, 2010 function stats(psource,cname,tplayer) if not getPlayerFromName(tplayer) then tplayer = psource else tplayer = getPlayerFromName(tplayer) end achUnlockedNumber(tplayer) local serial = getPlayerSerial(tplayer) local RaceAttempts = executeSQLSelect ( "RaceAttempts", "RaceAttempts","serial = '" .. serial .. "'") local DDAttempts = executeSQLSelect ("DDDM","DDAttempts","serial = '" .. serial .. "'") local DDWins =executeSQLSelect ( "DDDM", "DDWins","serial = '" .. serial .. "'") local Wins1 = executeSQLSelect ( "RaceWins", "RaceWins","serial = '" .. serial .. "'") local Money = executeSQLSelect ( "MoneyB", "Money","serial = '" .. serial .. "'") local MoneyB = executeSQLSelect ( "MoneyB", "B","serial = '" .. serial .. "'") if tonumber(RaceAttempts[1]['RaceAttempts']) == 0 then ratio = 0 else ratio = (tonumber(Wins1[1]['RaceWins'])/tonumber(RaceAttempts[1]['RaceAttempts']))*100 end if tonumber(DDAttempts[1]['DDAttempts']) == 0 then rratio = 0 else rratio = (tonumber(DDWins[1]['DDWins'])/tonumber(DDAttempts[1]['DDAttempts']))*100 end outputChatBox(getPlayerName(tplayer).."'s Stats: Attempted: "..RaceAttempts[1]['RaceAttempts'].." races, "..DDAttempts[1]['DDAttempts'] .." DDs. Won: "..Wins1[1]['RaceWins'].." races("..ratio.."%), "..DDWins[1]['DDWins'].." DDs("..rratio.."%). Cash: $"..Money[1]['Money'].. " Unlocked "..getElementData(tplayer,"data.Achnum").."/9 Achievements("..MoneyB[1]['B'].."B)",root,173,218,068) end addCommandHandler("stats",stats) addCommandHandler("st",stats) Need to write the whole name /stats [TAG]NaMe . how can i make /stats name.. Link to comment
Discord Moderators Zango Posted December 7, 2010 Discord Moderators Share Posted December 7, 2010 I might get you wrong, but you want the script to recognise a player by a part of his name? If the tags you are talking about are made using setPlayerNametagText there shouldn't be a problem. Else, you can try and retrieve player list and see if a player matches the given string tplayer. for k, v in ipairs (getElementsByType ('player')) do if string.find (getPlayerName (v), tplayer, 0, true) then tplayer = v else return end end There's just a problem if someone has parts of identical names ie. player1 is named Drift and player2 is named Drift_King one of those will be chosen. You can probably write around this Link to comment
Aibo Posted December 7, 2010 Share Posted December 7, 2010 while i was typing answer already was posted. though i'd like to add that it wont find «Drift» in «driftking», cause it is case-sensitive. you can convert strings to lower/upper case, for example. and also it will «return» on the first iteration (because of «else return» means return without any conditions), so it will check only first player in list function getPlayerFromNamePart(name) local player = getPlayerFromName(name) -- check if it is already a full player name if player then return player end for i, player in ipairs(getElementsByType("player")) do -- loop thru all players if string.find(getPlayerName(player):lower(), name:lower(), 1, true) then -- search for name part in player name return player -- return player element if a match found end end return false end Link to comment
Discord Moderators Zango Posted December 7, 2010 Discord Moderators Share Posted December 7, 2010 my bad, shouldn't write it this fast as a suggestion, if two or more results are found you could take the one with the least amount of characters from the searched, for example Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now