-
Posts
6,062 -
Joined
-
Last visited
-
Days Won
208
Everything posted by IIYAMA
-
There is no global Lua environment afaik, atleast not that I am aware of. Each resource has it's own environment. But that doesn't mean a resource can't get information through http. If you want MTA to native support custom Lua env. variables, you probably need to create a module or modify MTA itself.
-
Just use the config file. https://wiki.multitheftauto.com/wiki/GetResourceConfig While the syntax might be different, it's goal is exactly the same.
-
That is because the `return` keyword stops the whole function. You are currently executing the following code, while I left most of the details out of it. How many times do you think this loop will run? (no matter what outcome of math.random is) for i=1, 1000 do if math.random(2) == 1 then return true else return false end end A : 1000 times B : 0 times C : 1 time Try to move the NOT state (as in no team has been found), after the loop. --[[ ... ]] local thePlayer = source for _, v in pairs(teams) do if teamName == v[1] then setTimer(function() spawnPlayer(thePlayer ,v[2],v[3],v[4],v[5],v[6],0,0,playerTeam) giveWeapon(thePlayer , v[7],ammo,false) giveWeapon(thePlayer , v[8],ammo,false) giveWeapon(thePlayer , v[9],ammo,false) end,2000,1) return -- this stops the whole function... end end setTimer(function() spawnPlayer(thePlayer,guestSpawns[num][1],guestSpawns[num][2],guestSpawns[num][3],guestSpawns[num][4],guestSpawns[num][5],0,0,playerTeam) end,2000,1) --[[ ... ]] By the way, this is just 1 out of many solutions.
- 1 reply
-
- 1
-
Use a table, so that you can separate player data. And if you do not know how to work with a table, then go watch table tutorials on Youtube. local allPlayerData = {} addEventHandler("onPlayerJoin", root, function () allPlayerData[source] = {} -- initial state end) addEventHandler("onPlayerQuit", root, function () allPlayerData[source] = nil end, true, "low") local box = createObject(1271, x, y, z) allPlayerData[player]["box"] = box -- save local box = allPlayerData[player]["box"] -- load
-
Not sure what you want to achieve. But you could add a DX effect, that shows the whole label when hovering.
-
Too all clients: -- server local theElement = createElement("<element-type>", "<element-id>") setElementData(theElement, "<key>", "<data>") setTimer(function () setElementData(theElement, "<key>", getTickCount()) end, 4000, 0) -- client addEventHandler("onClientResourceStart", resourceRoot, function () local theElement = getElementByID("<element-id>") iprint("start value:", getElementData(theElement, "<key>")) addEventHandler("onClientElementDataChange", theElement, function (theKey, oldValue, newValue) iprint(theKey, oldValue, newValue) end, false) end, false)
-
The big difference is that the object created on clientside, is not added to the element tree of serverside. (so unavailable/invisible) <!-- serverside / clientside --> <resource id="resource-id"> <map id="dynamic"> <!-- START clientside ONLY for redditing --> <object/><!-- invisible/unavailable for serverside and other players --> <!-- END clientside --> <!-- START clientside ONLY for IIYAMA --> <object/><!-- invisible/unavailable for serverside and other players --> <!-- END clientside --> <!-- START clientside ONLY for Tekken --> <object/><!-- invisible/unavailable for serverside and other players --> <!-- END clientside --> </map> </resource>
-
Use timestamp: local currentTime = getRealTime().timestamp Since the index seconds is only from 0 > 59.
-
Get real time uses seconds. ------------ -- server -- local timestamp = getRealTime().timestamp -- seconds local jailDuration = (60 * 4) -- seconds local jailEndTime = timestamp + jailDuration -- local remainingJailTime = jailEndTime - timestamp triggerClientEvent(player, "sync-jail-time", player, remainingJailTime ) -- the client only has to know this once ------------ -- client -- local jailEndTime addEvent("sync-jail-time", true) addEventHandler("sync-jail-time", localPlayer, function (remainingJailTime) jailEndTime = (remainingJailTime * 1000) + getTickCount() -- convert to miliseconds, to make it more accurate (as the machine times are not aligned by seconds) end, false) function getRemainingJailTime () if jailEndTime then local timeNow = getTickCount() return math.ceil(math.max(jailEndTime - timeNow, 0) / 1000) -- seconds end return 0 end
-
Please use normal text format, it makes it hard to dxDraw functions are like paint, the last colour you put on the canvas will be visible. Which means that it is all about timing, this can be adjusted by changing the addEventHandler priority. https://wiki.multitheftauto.com/wiki/AddEventHandler removedEventHandler > addEventHandler addEventHandler( "onClientRender", root, function () end, false, "high" ) -- first layer of paint = back addEventHandler( "onClientRender", root, function () end, false, "normal" ) -- normal = middle addEventHandler( "onClientRender", root, function () end, false, "low" ) -- last layer of paint = top addEventHandler( "onClientRender", root, function () end, false, "low-1" ) -- last layer of paint = top top addEventHandler( "onClientRender", root, function () end, false, "low-2" ) -- last layer of paint = top top top An alternative is looping through a table and changing the item order.
-
You are not stupid, it might be too complex to begin with. This is called the element tree: https://wiki.multitheftauto.com/wiki/Element_tree And as you know, tree's do start with the root element. (With this tree, there is a single root, yea I know that is strange...) Under this (inverted) tree you can see it is branching in to different other elements. This is how MTA organize it's elements. resourceRoot is the start of a single resource. Under the resourceRoot, you can see 1 resourceDynamicElementRoot. (This is where all your elements created by script are childs of) There are also resourceMapRootElement(s). Each element represents a map element, created by a .map file. Knowing all this and look at this representation of your resource (based on the code above): Serverside <resource id="your-resource"> <!-- resourceRoot --> <map id="dynamic"> <!-- resourceDynamicElementRoot --> </map> </resource> Clientside <resource id="your-resource"> <!-- (serverside) resourceRoot --> <map id="dynamic"> <!-- (serverside) resourceDynamicElementRoot --> <!-- START clientside --> <vehicleBlipRoot> <blip/> <blip/> <blip/> </vehicleBlipRoot> <!-- END clientside --> </map> <!-- (serverside) --> </resource> <!-- (serverside) --> As I said before, clientside has access to all serverside elements. But serverside has no access/isn't ware of clientside elements. You want to destroy client elements with serverside, but serverside is not ware that they exist. With the following element structure you can solve that: <resource id="your-resource"> <map id="dynamic"> <vehicleBlipRoot> <blipServerSide> <!-- START clientside --> <blip/> <!-- END clientside --> </blipServerSide> <blipServerSide> <!-- START clientside --> <blip/> <!-- END clientside --> </blipServerSide> <blipServerSide> <!-- START clientside --> <blip/> <!-- END clientside --> </blipServerSide> </vehicleBlipRoot> </map> </resource> If you delete blipServerSide, with the function destroyElement, then the blip clientside will also be deleted. This is happening because when you call the destroyElement function on serverside, the same function will be called on clientside on the same element (behind the scenes). And thx to propagation (already enabled) the function will also be called for all the children of the element that is about to be destroyed, which is in this case the client element blip. I can't explain it better than this.
-
Exactly, that is why I gave you an example of how to do that, don't waste it. Since you still do not understand it, this is my last attempt to show you how you can delete clientside elements by also using a serverside element. If you still don't understand it, then that is unfortunately. Serverside local playerBlipElementContainerElement = createElement("playerBlipElementContainer", "playerBlipElementContainer:24436dg45632Ddfg") addEventHandler("onPlayerJoin", root, function () local serverSideElement = createElement("playerBlipElement_serverSide") setElementData(serverSideElement, "owner", source) setElementParent(serverSideElement, playerBlipElementContainerElement) end) --[[ -- Players already ingame addEventHandler("onClientResourceStart"... getElementsByType("player") ... ]] Clientside local playerBlipElementContainerElement = getElementByID("playerBlipElementContainer:24436dg45632Ddfg") ------------------- -- MODIFY THIS, for players already ingame (add a little delay) and for new players (onClientPlayerJoin + add a little delay) local serverSideElements = getElementChildren(playerBlipElementContainerElement) for i=1, #serverSideElements do local serverSideElement = serverSideElements[i] local owner = getElementData(serverSideElement, "owner") local blip = createBlipAttachedTo(owner, 0, 1, 150, 150, 150, 255, 1) setElementParent(blip, serverSideElement) end
-
Server created elements are available clientside. Client created elements are NOT available on serverside. But there is 1 trick you can use to delete clientside elements by serverside. Start the following example when you are not downloading other resources, clientside must have been started before 10 seconds. Server local serverSideElement = createElement("exampleElement", "id:3563454hasduy3685dsfs") setTimer(function () -- destroy the element over 10 seconds destroyElement(serverSideElement) end, 10000, 1) Client local clientSideElement = createElement("exampleExample") -- get the serverside element local serverSideElement = getElementByID("id:3563454hasduy3685dsfs") if isElement(serverSideElement) then setElementParent(clientSideElement, serverSideElement) -- set the clientside element as child of the serverside element end addEventHandler("onClientElementDestroy", clientSideElement, function () iprint("onClientElementDestroy") end, false) *** Fixed the wrong ID value.
-
Server local pedParentElement = createElement("pedParent", "pedParent-323536") ---------------- local ped1 = createPed ( 120, 5540.6654, 1020.55122, 1240.545 ) local ped2 = createPed ( 120, 5550.6654, 1020.55122, 1240.545 ) local ped3 = createPed ( 120, 5560.6654, 1020.55122, 1240.545 ) setElementParent(ped1, pedParentElement) setElementParent(ped2, pedParentElement) setElementParent(ped3, pedParentElement) Client addEventHandler("onClientPedDamage", getElementByID("pedParent-323536"), function() cancelEvent() end )
-
As far I know there are not very advanced AI implementations, at least not how AI decides it's tasks. But there is an ped controller (makes a ped do stuff) with a task sequencer (makes a ped do stuff according to sequence/list of tasks): https://web.archive.org/web/20160727231206/http://crystalmv.net84.net/pages/scripts/npc_hlc.php https://web.archive.org/web/20170123100149/http://crystalmv.net84.net/pages/scripts/npc_tseq.php But how the AI interacts, that is something you have to create on your own.
-
local commandObject = { collection = { ["fly"] = true }, playerAccess = { ["<playerserial>"] = { -- put your serial in here. ["fly"] = true } } } addEventHandler("onPlayerCommand", root, function(command) if commandObject.collection[command] then local serial = getPlayerSerial(source) local playerAccess = commandObject.playerAccess[serial] if playerAccess and playerAccess[command] then return end cancelEvent() end end ) Sure. I am not going to teach you stuff that is beyond your current level, for obvious reasons.
-
If there is no cursor visible by script (chat cursor doesn't count), then the function getCursorPosition returns nil.
-
I think you meant cores* (auto correction?) More cores will only relieve the main MTA server thread from doing other tasks. So you could have gone with less cores and not even notice the difference. About the network. Your server can bombard your clients with an 5GBPs amount of bandwidth, but that doesn't mean the clients will be able to handle it. If you are 100% sure that it max usage is 40%, then I would recommend to check the packets that going in an out per client. Use this command: /shownetstat 1 And send me a screenshot at the point where you have 190 players in your server. That's when we can see if there is a possible resource that kills the network. (for example use too frequently elementdata)
-
Or it is not available, you have neighbours after all. Especially when they put too many VPS instances on 1 server, with slow storage solutions or not enough internet bandwidth. Of course it can be an MTA issue after all, but you want to benchmark that correctly by comparing it with another VPS. If it takes too long to open the admin panel (every single time, instead only the first time), that it is more often caused by slow internet. (in my experience) Topic moved to server
-
Then here you are: https://wiki.multitheftauto.com/wiki/OnPlayerCommand https://wiki.multitheftauto.com/wiki/CancelEvent Database stuff etc. can be found on the wiki. Keep in mind that A-sync database requests with cancelled commands are not possible.
-
Commands are set based on the Account Control List (ACL). Admin panel does have an user interface to modify this, that can be found under resources: click on the right top to modify the ACL. For creating the exact thing you want, modify the example on this page: https://wiki.multitheftauto.com/wiki/AclSetRight <right name="command.givecommand" access="true" /> <right name="command.YOUR COMMAND NAME" access="true" /> Note, this works only for Groups. Else you will have to create something custom.
-
I would recommend to modify that function(+code) if I was you, since stopping an animation based on table indexes doesn't really work well, when array mutate functions + collapse effect are used: table.remove When using it for 1 animation at the same time, it will work fine. But when destroying multiple animations, it might causes some unexpected results.
-
Well, yes it worked in the past for me. There were a few issues with transparent/shoot through element components. Like the watch towers in area69. Those banister were blocking the line, while the arguments were set correctly. Not sure if they fixed that by now. @majqq I can send you another script, which was an experimental serverside bullet detection. It does use processLineOfSight, but not for player hit detection. Just mapping the end point of the bullet. Instead it compares the bone position of the ped VS the line. Which means you can also hit feed and hands (which normally does not have collision). Do you want to take a look at that for inspiration or use it like it is? (the code is a monstrosity by the way... sorry )
-
There are not more items in the table playerid than if you do it directly in the table data. Unless you load the entire database in to the memory, there is no direct performance benefit gained by the way you do it now (2x indexing is slower).