Jump to content

How to know if the thing is already in use?


Recommended Posts

Hello ,

I would like to know how too know if a thing is already used

for example if i want to buy a name and the name is already used it says "its already in use"

I tried already some things and im willing to LEARN how to get this working

I know i dont have every function yet if im right but im willing to learn since im out of clue

  
function getName()  
name = guiGetText(editbox) -- to get the name inside the box 
if name then 
outputChatBox("Does this works?") -- debugger if that code up works 
  
setElementData(thePlayer,"name") -- not sure about this one too if it gets the name wich is in the box or not 
end 
  

  
-- the gui  
    function guiOpen() 
        window1 = guiCreateWindow(243, 147, 305, 264, "Buy your name!", false) 
        guiWindowSetSizable(window1, false) 
  
        editbox = guiCreateEdit(44, 62, 212, 28, "", false, window1) 
        label = guiCreateLabel(46, 44, 206, 18, "Put here your name :", false, window1) 
        button1 = guiCreateButton(23, 232, 74, 22, "Done", true, window1) 
        guiSetProperty(button1, "NormalTextColour", "FF36FC01") 
        addEventHandler("onClientGUIClick",button1,done) --- event 
        button2 = guiCreateButton(182, 232, 74, 22, "Cancel", true, window1) 
        guiSetProperty(button2, "NormalTextColour", "FFFE0000") 
        addEventHandler("onClientGUIClick",button2,cancel) --- event 
    end 
addCommandHandler("buyname",guiOpen) 
  
  
function cancel() 
guiSetVisible(false) 
end 
addEvent("cancel",true) 
addEventHandler("cancel",getRootElement(),cancel) 
  
function done() 
guiSetVisible(false) 
-- idk what to put here 
end 
addEvent("done",true) 
addEventHandler("done",getRootElement(),done) 
  
  

Greetings ,

Scaryface87

Link to comment

Hello ,

I dont think that will work since it sets a elemtndata to everyone then if im right?(else u cant loop to all players to see if he has the elementdata)

Or do u mean that it loops every player's elementdata?

If so i can use it normal

is it like this? :

  
for i,v in ipairs getElementsByType("players") 
if getElementData(v,"name") then 
outputChatBox("This name is already taken!!") 
else 
outputChatBox("Congratz! this name is yours") 
setElementData(player,"name") 
  

Greetings ,

scaryface87

Link to comment
remove s form 'players'

"player": A player connected to the server

Sorry but dont i have to use "players" since u said" "player" : a player connected to the server "

cuz i want to check if someone got it or not , even if hes ofline so if someone got the name and hes ofline , i cant take it

Link to comment
If you do that, all players will need an account. So, also check or they are logged in @ scaryface87

Exactly They Must have account to store the name and if he logged in his name will change to the old one he saved

and if any one tryed to store a name alredy another player have outputMsg to player

you Should Use tabel or , XML to store them so they wont be lost .

Link to comment

Ok so like this ;

but i dont think it gonna look at everyones account no?

  
      local playerAccount = getPlayerAccount(source) -- get his account not sure if its from everyone's 
      if (playerAccount) then 
if getAccountData(playerAccount,"name") then 
outputChatBox("This name is already taken!!") 
else 
outputChatBox("Congratz! this name is yours") 
setAccountData(playerAccount,"name") 
  

Link to comment

Hm can you maybe help me to learn how to use database? (sql if im right?) let me try it already ;

(sorry if its that bad)

  
function createSQL() 
executeSQLCreateTable ( "names", "account TEXT,name TEXT" ) 
end 
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()),createSQL) 
  
  

  
function test() 
name = executeSQLSelect ( "names", "account", "name = '" .. sourcename .. "'" ) 
-- stuck here 
end 
  
  

Link to comment
function test ( ) 
    local data = executeSQLQuery ( "SELECT account FROM names WHERE name = ?", tostring ( sourcename ) ) 
    if ( data ) then -- If there is data 
        local account = data [ 1 ] [ "account" ] -- Get the account from it 
        -- stuck here 
    end 
end 

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