Jump to content

IIYAMA

Moderators
  • Posts

    6,097
  • Joined

  • Last visited

  • Days Won

    218

Everything posted by IIYAMA

  1. IIYAMA

    Basic's SQL

    Aha. I am planning to update it slowly, using a table which contains the same data as the database. So I don't have to call the database to receive data from the players. Just only storage and only loading data when they join. Just wondering, why do I have to index the result 1 time more before I can access the main data? function loadData (player) local account = getPlayerAccount (player) if not isGuestAccount(account) then local accountName = getAccountName(account) if accountName then local query = dbQuery(connection, "SELECT * FROM `accounts` WHERE `username` = ?", accountName) if query and rows ~= 0 then local result, rows = dbPoll(query, -1) if result then for index,data in pairs(result[1]) do outputDebugString(tostring(index) .. " " .. tostring(data)) end end end end end end addCommandHandler("loadData",loadData) This part solved: and this doesn't seems to work: (no errors/warnings) and returns true -- the total string looks like this: -- "UPDATE `accounts` SET `location` = ?, `status` = ?, `weaponSkills` = ?, `serial` = ? WHERE `username` = ?" dbExec(connection, "UPDATE `accounts` SET " .. dbString .. " WHERE `username` = ?", unpack(dbArguments))
  2. It depends if you use custom table Keys. When you use them in combination with the pairs loop. (not ipairs) It is possible and manage able.
  3. It doesn't show up, because I created an error/warning or you didn't use the piss command. Yet your previous code is kinda strange and has a lot of features you don't need. (like having the possibility to create multiply bars, which you aren't using in your code.) The reason why you can't update it, is because your data can't be edited easily. When you use the piss command multiply times, it will fill up the table with the same data. The data will never be delete, it will only increase. And at the end the players with not very good pc's will have very low fps. Pls stick with the latest code I posted and debug is correctly.
  4. IIYAMA

    Basic's SQL

    Aha, great! Another question, now I get the data based on the column username. "UPDATE `accounts` SET `serial`= ?, `playerName` = ? WHERE `username` = ?" But can I also use the playerName or serial to find the account right? "UPDATE `accounts` SET `serial`= ?, `username` = ? WHERE `playerName` = ?" Or am I limited to the key I first used to insert? Which is in this case the key username. dbExec(connect, "INSERT INTO `accounts` SET `username` = ?", accountName)
  5. IIYAMA

    Basic's SQL

    Will predefined columns give more performance? (while edit that column the next time) The ones you can create with "CREATE TABLE IF NOT EXISTS".
  6. IIYAMA

    Basic's SQL

    aha I understand that part now. (I am a fast learner) Another question: dbExec( connection, "INSERT INTO table_name VALUES (?,?,?)", "aaa", "bbb", 10 ) --(From wiki) Will I be able to add more than 3 values later?
  7. IIYAMA

    Basic's SQL

    "UPDATE `accounts` SET `serial`= ?, `playerName` = ? WHERE `username` = ?" The "WHERE" must be the last thing in the string?
  8. IIYAMA

    Basic's SQL

    Is this how I can make accounts like with accountdata? Or I do get problems with special characters in the players their names? local connect = dbConnect ( "sqlite", "file.db" ) local possibleData = { "serial TEXT", "playerName TEXT" } addCommandHandler("test", function (player) local account getPlayerAccount(player) if not isGuestAccount (account) then local accountName = getAccountName(account) local serial = getPlayerSerial(player) local playerName = getPlayerName(player) dbExec ( connect, "CREATE TABLE IF NOT EXISTS `" .. accountName .. "` ( " .. table.concat(possibleData,", ") .. ")" ) dbExec ( connect, "INSERT INTO `" .. accountName .. "` SET `serial`=?, `playerName`=?", serial, playerName ) end end)
  9. IIYAMA

    Basic's SQL

    Can you continuous my addCommandHandler example, so I know how I can use the account name as key for the sql table?
  10. IIYAMA

    Basic's SQL

    This is my first try to create a SQL database. local possibleData = { "serial TEXT", "playerName TEXT" } -- This is for creating the .db file? local resultOfExecuteSQLQuery = executeSQLQuery("CREATE TABLE IF NOT EXİSTS player ( " .. table.concat(possibleData,", ") .. ")") outputDebugString(tostring(resultOfExecuteSQLQuery)) addCommandHandler("test", function (player) local account getPlayerAccount(player) if not isGuestAccount (account) then local accountName = getAccountName(account) local serial = getPlayerSerial(player) local playerName = getPlayerName(player) -- todo -- end end) Yet I do not understand how to add players.
  11. If you did read this post: viewtopic.php?f=91&t=47897 You would have known what the purpose of the scripting section is and where to post request posts. Good luck. Put requests for scripts on the resource section.
  12. Nope, Most scripters truly hate begging people like you. Also pls go to the right section, they will come to you there.
  13. Afaik using https://wiki.multitheftauto.com/wiki/LoadMapData will load faster and probably using less cpu. The more mta functions you require, the slower the code. But I haven't test the speed of the loadMapData function yet, so I can't really say how much faster it is. This function will also be called behind the scenes when you start a resource which includes in the meta.xml a .map file. When you do not include this file in the meta.xml, you can start it manually using the loadMapData function. Afaik the only reason why people started using clientside maps, is because your can use the function https://wiki.multitheftauto.com/wiki/Tr ... lientEvent This function will make it possible to show a custom download bar. (which indicates how long it takes before the map is downloaded)
  14. It has one purpose, saving space on your server. Since mta copies everything that is running in the cache folder, you will lose space anyway. Space using: 334(cache unzipped) + 150(resource folder) = 484 mb -- zipped 334(cache unzipped) + 334(resource folder) = 668 mb -- not zipped This example doesn't tell you anything extra, except it can make your HDD faster in search results. Because they don't consider it as priority, it is sad I know...
  15. He means that clientside code is running on the players their pc, so it is edit able. Yet, I haven't seen any hackers successfully do anything with it. But: Using onPlayerWasted serverside would be more effective because it uses less bandwidth.
  16. It is flashing because of your counter part... local pissBarStatus = false function showBar() pissBarStatus = not pissBarStatus end addEvent("onClientShowBar",true) addEventHandler("onClientShowBar", root, showBar) addCommandHandler("piss", showBar) local sx,sy = guiGetScreenSize () local barx = sx/800*683 local bary = sy/600*89 local barxoverlay = sx/800*685 local baryoverlay = sy/600*91 local barName = "PISS" addEventHandler("onClientRender",root, function () if pissBarStatus then local barRelative = math.max(math.min(tonumber(getElementData(localPlayer, "piss")) or 0,100),0)/100 dxDrawText ( barName, barx/0.499 + 1, bary/0.492, 76, 12, tocolor ( 255, 255, 255, 255 ), 1, "default", "center", "center", false, false, true ) dxDrawRectangle (barx, bary, 80, 14, tocolor (0,0,0,255), false) dxDrawRectangle (barxoverlay-0.5, baryoverlay-0.8, 77, 10, tocolor (235,141,45,127), false) dxDrawRectangle (barxoverlay-0.5, baryoverlay-0.8, 75.5*barRelative, 10, tocolor (235,141,45,185), false) end end)
  17. and what is the counter for? Well if that is what you want, you don't need all that code. local pissBarStatus = false function showBar() pissBarStatus = not pissBarStatus end addEvent("onClientShowBar",true) addEventHandler("onClientShowBar", root, showBar) addCommandHandler("piss", showBar) local sx,sy = guiGetScreenSize () local barx = sx/800*683 local bary = sy/600*89 local barxoverlay = sx/800*685 local baryoverlay = sy/600*91 local barName = "PISS" local counter = 0 addEventHandler("onClientRender",root, function () if pissBarStatus then local barRelative = math.max(math.min(tonumber(getElementData(localPlayer, "piss")) or 0,100),0)/100 if (counter > 25) then dxDrawText ( barName, barx/0.499 + 1, bary/0.492, 76, 12, tocolor ( 255, 255, 255, 255 ), 1, "default", "center", "center", false, false, true ) dxDrawRectangle (barx, bary, 80, 14, tocolor (0,0,0,255), false) dxDrawRectangle (barxoverlay-0.5, baryoverlay-0.8, 77, 10, tocolor (235,141,45,127), false) dxDrawRectangle (barxoverlay-0.5, baryoverlay-0.8, 75.5*barRelative, 10, tocolor (235,141,45,185), false) counter = counter +1 else counter = counter +1 end if (counter >= 50) then counter = 0 end end end)
  18. That is right, since there are no comments of your own in the code I do not know what the code should do. You are adding bars in to a all in one bar manage system, it is still unclear what your end result must be.
  19. Updated, previous post. > local values = listBRS[i]
  20. function showBar(barx, bary, barxoverlay, baryoverlay, barRelative, counter, barName) return table.insert(listBRS, {barx, bary, barxoverlay, baryoverlay, barRelative, counter, barName}) end addEvent("onClientShowBar",true) addEventHandler("onClientShowBar", root, showBar) function renderBar() if (#listBRS > 0) then --for i, values in ipairs(listBRS) do for i=#listBRS,1, -1 do -- make sure you can remove items properly. (using table.remove) This is only possible when you inverse your loop. local values = listBRS[i] -- first make sure you know at which array your variables are. local barx, bary, barxoverlay, baryoverlay, barRelative, counter, barName = values[1], -- barx values[2], -- bary values[3], -- barxoverlay values[4], -- baryoverlay values[5], -- barRelative values[6], -- counter = at array 6 << very important. values[7] -- barName if (counter > 25) then dxDrawText ( barName, barx/0.499 + 1, bary/0.492, 76, 12, tocolor ( 255, 255, 255, 255 ), 1, "default", "center", "center", false, false, true ) dxDrawRectangle (barx, bary, 80, 14, tocolor (0,0,0,255), false) dxDrawRectangle (barxoverlay-0.5, baryoverlay-0.8, 77, 10, tocolor (235,141,45,127), false) dxDrawRectangle (barxoverlay-0.5, baryoverlay-0.8, 75.5*barRelative, 10, tocolor (235,141,45,185), false) counter = counter +1 else counter = counter +1 end values[6] = counter -- now save the edited variable counter back at array 6 if (counter >= 50) then --counter = 0 --(Don't you need to remove that item?) table.remove(listBRS,i) -- removed! end end end end addEventHandler("onClientRender",getRootElement(),renderBar) function :~() local sx,sy = guiGetScreenSize () local x = sx/800*683 local y = sy/600*89 local x1 = sx/800*685 local y1 = sy/600*91 -- Making sure the value is always correct. (between 0 t/m 100) Never trust element data, since all resources can edit it. local pissData = math.max(math.min(tonumber(getElementData(getLocalPlayer(), "piss")) or 0,100),0)/100 -------------------- local pissBar = 100 local title = "PISS" showBar(x, y, x1, y1, pissData, pissBar, title) end addCommandHandler("piss", :~)
  21. Post full code, I can't find the problem in this part.
  22. You could try something like this: (NOT TESTED) local calculateProgress = function (timeNow,futureTime, startValue,endValue,duration) local timeNow = timeNow or getTickCount() if timeNow < futureTime then if startValue > endValue then local factor = 1-(futureTime-timeNow)/duration return ((startValue-endValue)* factor) + endValue elseif startValue < endValue then local factor = ((futureTime-timeNow)/duration) return ((endValue-startValue)* factor) + startValue else -- remember you can't do 0/number, so... return startValue end else return endValue end end local futureTime = getTickCount()+500 addEventHandler("onClientRender",root, function () dxDrawText(tostring(calculateProgress(getTickCount(),futureTime,1,10,500)),300,300) end) Make sure that the futureTime-startTime matches the duration.
  23. This is not a request!!! Custom onClientPlayerWeaponSwitch event which will now trigger for all players, instead only for the localPlayer. Use it like you want... So: [b]Source[/b] The source of this event is the player who changed his weapon. [strike](Local player only)[/strike] Example: addEventHandler ( "onClientPlayerWeaponSwitch",root, function ( prevSlot, newSlot, custom) outputDebugString (prevSlot .. ", " .. newSlot .. " " .. tostring(custom)) end) Source code. local playerDataBase = {} addEventHandler("onClientResourceStart",resourceRoot, function () local allPlayers = getElementsByType("player") for i=1,#allPlayers do local player = allPlayers[i] if player ~= localPlayer then local slot = getPedWeaponSlot ( player ) playerDataBase[player] = slot end end end) addEventHandler("onClientPlayerJoin",root, function () playerDataBase[source] = getPedWeaponSlot (source) end) addEventHandler("onClientRender",root, function () for player,oldSlot in pairs(playerDataBase) do if isElement(player) then local newSlot = getPedWeaponSlot ( player ) if oldSlot ~= newSlot then triggerEvent("onClientPlayerWeaponSwitch",player,oldSlot,newSlot,true) playerDataBase[player] = newSlot end else playerDataBase[player] = nil end end end)
  24. = "what ever" .. nil setVehicleColor(kar, tonumber(a) or 0,tonumber(b) or 0,tonumber(c) or 0) Do you see here .. ?????? I don't think so...
  25. function consoleSetPlayerGravity ( player, commandName, level ) if ( player ) then local money = getPlayerMoney(player) if money >= 15000 then local success = setPedGravity ( player, tonumber ( 0.0055 ) ) if (not success) then outputConsole( "Failed to set player gravity", player ) else -- success! outputChatBox("Weed is now Activated (it will auto Disabled when you Disconnect)",player, 255, 171, 0) takePlayerMoney ( player, 15000) end else -- not enought money outputChatBox("You dont have enough of money to use weed", player, 255, 0, 0) end end end addCommandHandler ( "sb", consoleSetPlayerGravity )
×
×
  • Create New...