• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

getPlayerID(cid) and others

Marcelo Druida

Intermediate OT User
Joined
Nov 17, 2014
Messages
429
Solutions
1
Reaction score
134
Location
Brazil
Hello OTLanders

3 simple functions that was very useful to me and hope be useful to someone

name = getPlayerNameById(7) -- returns database player 7 name
function getPlayerNameById(id)
local resultName = db.storeQuery("SELECT `name` FROM `players` WHERE `id` = " .. db.escapeString(id))
if resultName ~= false then
local name = result.getDataString(resultName, "name")
result.free(resultName)
return name
end
return 0
end

id = getPlayerIdByName(Marcelo) -- returns Marcelo's database ID
function getPlayerIdByName(name)
local resultID = db.storeQuery("SELECT `id` FROM `players` WHERE `name` = " .. db.escapeString(name))
if resultID ~= false then
local id = result.getDataString(resultID, "id")
result.free(resultID)
return id
end
return 0
end

and

id = getPlayerID(cid) -- returns player (cid) database ID
function getPlayerID(cid)
return getPlayerIdByName(getPlayerName(cid))
end

huge hug!
 
@Summ
Your responses to people's post lately seem very negative, you know there is not only 1 way to make something happen, we all don't need to conform to the standard that is a tfs function and sometimes reinventing the wheel is called for.

I noticed now that yes.
didnt know the function. :confused::confused::confused:

but i hope that it could be helpful to show newbies how to select a database value..

thanks and sorry!
It is helpful especially to a beginner, unlike a predefined function a user defined function allows the scripter or programmer to understand how it works, what arguments it accepts and what values it returns especially when the documentation for the predefined function is limited or non-existent.
 
@Breed
I am just being objective when it comes to code releases, if uneffective scripts are released at least 90% of the people will just copy them, even though the scripts might be easy to learn from.
Also, you don't want to call a query everytime you need a player id.
 
@Breed
I am just being objective when it comes to code releases, if uneffective scripts are released at least 90% of the people will just copy them, even though the scripts might be easy to learn from.
Also, you don't want to call a query everytime you need a player id.
I use to think that there was a work around to limit calls to the database but the truth of the matter is the server is in constant communication with the database regardless of the functions we are using whether it is direct or indirect, especially if those calls are coming from the user.
 
@Breed
I am just being objective when it comes to code releases, if uneffective scripts are released at least 90% of the people will just copy them, even though the scripts might be easy to learn from.
Also, you don't want to call a query everytime you need a player id.
I use to think that there was a work around to limit calls to the database but the truth of the matter is the server is in constant communication with the database regardless of the functions we are using whether it is direct or indirect, especially if those calls are coming from the user.

True to both of you. I agree that players can release scripts to learn from, however I still believe they should be best optimized. Looking at just some of the stuff in my signature I am appalled by what I released, but when I released it I felt differently, I was quite proud of my work. We evolve, and if you are better than what you are releasing then you should do it better, make it better, so others can learn to be better as well. That being said, as soon as I find the time, everything in my signature is going to be updated to 1.1 and written way better. Then edited on here. Because this is the way it should be! We should EVOLVE as a community, not backtrack. The OT community has evolved majorly since tliff and them, and that's good. However many months before the release of 1.0 the community had seemed like it was dieing off. This is not true! Thanks to @Mark and everyone involved in the TFS project. We don't need to regress because of different developers thinking oh I want this and I want that differently than what you want, but rather help each other to make the needs possible. This is what github is all about, fork the damn thing and start your own project. Getting off subject, as for the calls to the webserver. I agree with it shouldn't be used in the way it is above for something that is not necessary, however breed has a very valid point on the fact that the server maintains a constant connection with the database regardless.

@topic

thanks again to @Marcelo Druida for releasing work for the community :D
 
Back
Top