Jump to content

GTX

Members
  • Posts

    1,273
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by GTX

  1. Double post because can't edit heh... Anyways, here's updated code: function orderedTable(...) local newTable,keys,values={},{},{} newTable.pairs=function(self) local count=0 return function() count=count+1 return keys[count],values[keys[count]] end end setmetatable(newTable,{ __newindex=function(self,key,value) if not self[key] then table.insert(keys,key) elseif value==nil then local count=1 while keys[count]~=key do count = count+1 end table.remove(keys,count) end values[key] = value end, __index=function(self,key) return values[key] end }) return newTable end testTable = orderedTable() testTable["Primary Weapon"] = {} testTable["Secondary Weapon"] = {} testTable["Pistols"] = {} testTable["Specially Weapon"] = {} testTable["Ammo"] = {} testTable["Food"] = {} testTable["Medic Stuff"] = {} testTable["Vehicle Parts"] = {} testTable["Items"] = {} testTable["Toolbelt"] = {} for catName,category in testTable:pairs() do outputChatBox(catName) end It works, I tested it. When you add something to a table, __newindex is invoked and the value you passed is added to a indexed table. You can later fetch it. It also has when you set a key to nil, it will be removed from table, so if you'd like to remove Pistols key, all you need to do is: testTable["Pistols"] = nil.
  2. GTX

    explain !

    You can check out this resource: https://community.multitheftauto.com/index.php?p=resources&s=details&id=10074
  3. Lua does not retain the order that key, value pairs are added. However, this can be emulated. function orderedTable(...) local newTable,keys,values={},{},{} newTable.pairs=function(self) local count=0 return function() count=count+1 return keys[count],values[keys[count]] end end setmetatable(newTable,{ __newindex=function(self,key,value) if not self[key] then table.insert(keys,key) elseif value==nil then local count=1 while keys[count]~=key do count = count + 1 end table.remove(keys,count) end values[key]=value end, __index=function(self,key) return values[key] end }) for x=1,table.getn(arg) do for k,v in pairs(arg[x]) do newTable[k]=v end end return newTable end Example usage: test = orderedTable({value="key"},{anotherValue="anotherKey"}) test["apple"] = "red" test["mta"] = "sa" for k,v in test:pairs() do outputChatBox(k.." "..v) end The output is ordered; something like: Not tested
  4. Try this: addEvent("Login->Try-Spawn",true) addEventHandler("Login->Try-Spawn",getRootElement(),function(Jatekos,X,Y,Z,SKIN,Interior,Dimenzio) spawnPlayer(Jatekos,X,Y,Z) setElementModel(Jatekos, SKIN) setElementInterior(Jatekos,Interior) setElementDimension(Jatekos,Dimenzio) exports['mx_achievement']:givePlayerAchievement(Jatekos,2) setElementData(Jatekos, "loggedIn", true) setTimer(function() if (tonumber(getElementData(Jatekos,"jail->Time") or 0) > 0 ) then setElementDimension(Jatekos, 65400+getElementData(Jatekos, "acc.accountID")) setElementInterior(Jatekos, 6) setCameraInterior(Jatekos, 6) setElementPosition(Jatekos, 263.821807, 77.848365, 1001.0390625) setPedRotation(Jatekos, 267.438446) local jailTimer = setTimer(function() exports['mx_admin']:timerUnjailPlayer(Jatekos) end, 1000*60,getElementData(Jatekos,"jail->Time")) setElementData(Jatekos, "jail->Timer", jailTimer) setElementData(Jatekos, "jail->Time", getElementData(Jatekos,"jail->Time")) setElementData(Jatekos, "jail->Jailtime", getElementData(Jatekos,"jail->Time")) toggleControl(Jatekos,'next_weapon',false) toggleControl(Jatekos,'previous_weapon',false) toggleControl(Jatekos,'fire',false) toggleControl(Jatekos,'aim_weapon',false) setPedWeaponSlot(Jatekos,0) end end,2000,1) end)
  5. GTX

    Question

    Use db functions. dbConnect dbQuery dbExec dbPoll Assuming that you mean row instead of column, you can do it like this: -- Connect to SQLite local d = dbConnect("sqlite", "groups.db") -- Create table dbExec(d,"CREATE TABLE IF NOT EXISTS groups (name TEXT)") -- Insert row dbExec(d,"INSERT INTO groups VALUES (?)","group name") -- Remove row dbExec(d,"DELETE FROM groups WHERE name=?","group name") Note that this isn't full script, just an example.
  6. @Walid No... MrTasty's solution would work just fine. To put it into an example: function onChatMessage(text) if(string.sub(text,1,6) == "login:" or string.sub(text,1,7) == "logout:") then -- Check if it contains login: or logout: strings cancelEvent() -- Cancel it end end addEventHandler("onClientChatMessage",root,onChatMessage)
  7. If you cancel onPlayerLogin then you won't login (According to wiki). What you're doing in your code now is called stack overflow.
  8. Those messages are hardcoded, you cannot turn them off as far as I know.
  9. GTX

    ACL right list

    https://wiki.multitheftauto.com/wiki/Access_Control_List Here's all you need to know about ACL.
  10. You can see all logs in MTA folder if that helps. Example: C:\Program Files\MTA San Andreas\MTA\logs\console.log But yeah, copying from console can be tricky sometimes if someone's spamming because it deselects selected text...
  11. GTX

    API Query for c#

    You can access the MTA Web Interface from almost any programming language that can request web pages using HTTP POST and encode and decode JSON. Now, I don't have much knowledge in C# therefore I can't write an example but I guess you can use cURL or sockets to fetch data from the server. Fetch it from http://<ip>:<http port> or use that IP and port to fetch via socket. You can check PHP or Java SDK on wiki and port it to C#.
  12. You could use table.sort after line 62 in your script. -- Descending table.sort(playersTable, function(a,b) return tonumber(getElementData(a,"alivetime") or 0) > tonumber(getElementData(b,"alivetime") or 0) end ) -- Or ascending table.sort(playersTable, function(a,b) return tonumber(getElementData(a,"alivetime") or 0) < tonumber(getElementData(b,"alivetime") or 0) end ) Assuming that your alivetime element data is integer.
  13. Because I can't edit my post (This) (I didn't test this example, but it should work): -- Server side script local g_Offset = {0,0,2} -- Your offset (How far from vehicle it should be) (X, Y, Z) local lPeds = {} -- Here we store peds of players function onEnter(lPlayer) local lVehicleX, lVehicleY, lVehicleZ = getElementPosition(source) -- Get vehicle's position lPeds[lPlayer] = createPed(getElementModel(lPlayer),lVehicleX,lVehicleY,lVehicleZ) -- Create our dummy attachElements(lPeds[lPlayer],source,g_Offset[1],g_Offset[2],g_Offset[3]) -- Attach our dummy to the car with offset -- You can set your own animation here setPedAnimation(lPeds[lPlayer],"car","sit_relaxed") -- Set our dummy's animation setElementAlpha(lPlayer,0) -- Hide us end addEventHandler("onVehicleEnter",root,onEnter) -- When player sits in the car function onStartExit(lPlayer) setElementAlpha(lPlayer,255) -- Set alpha back destroyElement(lPeds[lPlayer]) -- Destroy our dummy end addEventHandler("onVehicleStartExit",root,onStartExit) -- When you press to exit the car You can edit the script however you want.
  14. GTX

    help

    All resources packed: http://crystalmv.net84.net/files/traffic.zip You can upload those into your resources folder, that is: server/mods/deathmatch/resources, refresh, etc... Read this. Here's documentation: http://crystalmv.net84.net/pages/scripts/docs/npchlc_traffic.php
  15. GTX

    help

    You can't. However, there are scripts that lets you add them. http://crystalmv.net84.net/pages/scripts/npc_hlc.php http://crystalmv.net84.net/pages/scripts/npchlc_traffic.php http://crystalmv.net84.net/pages/scripts/npchlc_traffic_editor.php http://crystalmv.net84.net/pages/scripts/npc_tseq.php They were made by CrystalMV. Make sure you thank him
  16. If you want to download scripts from admin panel to your computer, then yeah, I think it is possible. Under resources tab you can execute functions (Where it says "For advanced users only" or something like that). You can use runcode resource too. You'd need to add an event handler to client side and then write the data into a file using file functions when data is sent. On the server side, open a file using file functions and read it, then send the data to event handler that you added in client side. From computer to server, it's just reversed. Used functions: fileOpen -- Open a file on the server fileCreate -- Create a file client side fileWrite -- Write to client side (it will be in your mods folder) fileRead -- Read the file fileGetSize -- Used for second argument in fileRead fileClose -- Remember to close your file fileFlush -- Not needed really triggerClientEvent -- Send data (You can use triggerLatentEvent if the file is too big) addEventHandler addEvent Now go download some scripts from some server and call yourself a hacker
  17. I know this is old topic, but I'd like to point out something: @darkdreamingdan Why up to 25 minutes? At least in scripting forum, please enable it for infinite amount of time. If there's a room for improvements in the code, we can edit the post instead of creating a new one. For example here: https://forum.multitheftauto.com/topic/90209-set-player-position-inside-a-vehicle/#comment-818887 I wanted to add an example but now I can't and I don't want to double-post. Enable it for infinite amount of time, at least in scripting forum if not globally.
  18. GTX

    setCameraMatrix

    I don't know if I understood your problem/question correctly, but I think getting your bone position (in your case BONE_HEAD) should work. getPedBonePosition I guess you can just insert it instead of getElementPosition in your code.
  19. An example: local myTeam = createTeam("Not logged in",255,255,255) -- Your team element - change name to whatever you like. function onJoin() setPlayerTeam(source,myTeam) -- Set player's team (source is the player element who joined, team is team element that you declared at the top of the script. end addEventHandler("onPlayerJoin",root,onJoin) -- Add an event handler so when player joins it executes onJoin function.
  20. I don't think that's possible but you can do a workaround: Create a ped (dummy) and attach it on the vehicle with specific offset (so in your case, Z => 10) and set its animation to be like he's sitting in a car or whatever you'd like. Next, set your alpha to 0 and you're done. I can do an example, but not now. Functions/events would be: createPed setElementAlpha attachElements "onVehicleExit" "onVehicleEnter"
  21. You made? Then why do I see variables from luadec? (l_2_0 etc) Make your own script.
  22. Note that refreshResources(true) refreshes ALL resources on your server, which can cause lag. Use refreshResources().
  23. Hi, I don't know if this is the right section but is it possible to make a SSL cert for MTA HTTP server? I tried but it keeps loading and then it returns an error (domain unexpectedly closed the connection). I accessed it like https://domain.com:22005/.
  24. Is your interior locked? Intlock in your database should be set to 1 as far as I can see.
  25. I had problems with double siding also. My workaround was: if(objectData.doublesided == true) then element:setDoubleSided(true) end while element:setDoubleSided(objectData.doublesided) didn't work. It is a boolean, I checked. Maybe it works now, who knows.
×
×
  • Create New...