IIYAMA

Scripting Moderators
  • Content Count

    5,347
  • Joined

  • Last visited

  • Days Won

    105

Everything posted by IIYAMA

  1. Be careful with this, doing this every frame will kill the network of other players that are not inside of the local-network. The following function can be used to reduce update. (every 300 milliseconds) if checkPassiveTimer("attachedToWeapon_aim", true, 300) then setElementData ( localPlayer, "attachedToWeapon_aim", {hitX,hitY,hitZ} ) end It is a useful function (by me), source code can be found here: https://wiki.multitheftauto.com/wiki/CheckPassiveTimer
  2. I have experimented with the first part. The rest is for you to do. setElementAlpha(localPlayer, 0) addEventHandler("onClientResourceStop", resourceRoot, function () setElementAlpha(localPlayer, 255) end) addEventHandler("onClientPreRender", root, function () --[[ Creating the direction vector ]] local cameraX, cameraY, cameraZ, lx, ly, lz = getCameraMatrix() local directionVector = (Vector3(lx, ly, lz) - Vector3( cameraX, cameraY, cameraZ)) directionVector:normalize ( ) directionVector = directionVector * 300 local screenX, screenY = guiGetScreenSize() local startPositionX, startPositionY, startPositionZ = x, y, z local turrentX, turretY, turretZ = getElementPosition(localPlayer) -- must be the turret position turretZ = turretZ - 0.2 -- < just for test purposes -- draw turret dxDrawLine3D(turrentX, turretY, turretZ, turrentX, turretY, turretZ - 0.5, tocolor(0,0,0)) dxDrawLine3D(turrentX, turretY, turretZ - 0.5, turrentX + 0.5, turretY, turretZ - 1, tocolor(0,0,0)) dxDrawLine3D(turrentX, turretY, turretZ - 0.5, turrentX - 0.5, turretY, turretZ - 1, tocolor(0,0,0)) dxDrawLine3D(turrentX, turretY, turretZ - 0.5, turrentX, turretY - 0.5, turretZ - 1, tocolor(0,0,0)) dxDrawLine3D(turrentX, turretY, turretZ - 0.5, turrentX, turretY + 0.5, turretZ - 1, tocolor(0,0,0)) -- detect any hits local hit, hitX, hitY, hitZ, elementHit = processLineOfSight ( turrentX, turretY, turretZ, cameraX + directionVector.x, cameraY + directionVector.y, cameraZ + directionVector.z, true, -- checkBuildings true, -- checkVehicles true, -- checkPlayers true, -- checkObjects false, -- checkDummies false, -- seeThroughStuff false, -- ignoreSomeObjectsForCamera false, -- shootThroughStuff localPlayer -- element ignoredElement ) if not hit then hitX, hitY, hitZ = cameraX + directionVector.x, cameraY + directionVector.y, cameraZ + directionVector.z end dxDrawText(hit and "COLLISION!" or "NO COLLISION!", 300, 300) -- draw the line + cursor dxDrawLine3D(turrentX, turretY, turretZ, hitX, hitY, hitZ) local cursorX, cursorY = getScreenFromWorldPosition (hitX, hitY, hitZ) if cursorX then dxDrawCircle ( cursorX, cursorY, 10) dxDrawCircle (screenX / 2, screenY / 2, 10) end end)
  3. That is the first step. Depending on the dimension size. Like milliseconds/seconds/minutes/hours/days, you can also save a lot of data at these 2 dimensions: milliseconds/seconds Are those dimensions included? If yes, then I can explain a little bit more. Server triggerClientEvent(receivers, "<eventName>", resourceRoot, date) Client -- <triggerClientEvent resource> addEvent("<eventName>", true) -- <resource 1> addEventHandler("<eventName>", root, function () end) -- <resource 2> addEventHandler("<eventName>", root, function () end) ---------------------- -- or more specified. ---------------------- -- <resource 1> addEventHandler("<eventName>", getResourceRootElement ( getResourceFromName ("<triggerClientEvent resource name>")), function () end, false) -- <resource 2> addEventHandler("<eventName>", getResourceRootElement ( getResourceFromName ("<triggerClientEvent resource name>")), function () end, false)
  4. Before I give you recommendations. You will have to make a choice. -[x] left and right? - [ ] up and down? Complexity (synchronisation) +1 - [ ] crosshair based on camera? Complexity + 2 - [ ] crosshair based on turret? - [ ] crosshair left/right based on camera Complexity + 1 + crosshair up/down based on turret?
  5. You know what the local keyword does right??? If not, watch this video. local Weapon = createWeapon("minigun",0,0,0) Weapon = createWeapon("minigun",0,0,0) Extra function ClientfireWeapon() if isElement(Weapon) then setWeaponState ( Weapon, "firing" ) end end
  6. IIYAMA

    Server bug!

    "Alphabetical order", I don't think that should be the correct order, that is if the start-up order matters. In most gamemodes there is inside of the meta.xml(of the gamemode) a few <include/> tag located. https://wiki.multitheftauto.com/wiki/Meta.xml These are used to make other resources to start up with them. They also define the start-up order. For example in stealth: <meta> <info author="Slothman" version="1.0.2" name="Stealth" description="Allow scripts to insert a ped that simulates combat with a real player" type="gamemode" /> <!-- ... --> <include resource="scoreboard" /> <include resource="killmessages" /> <include resource="maplimits" /> <!-- ... --> </meta>
  7. IIYAMA

    Server bug!

    Sounds like an configuration setting went wrong after closing the server. Your only friend here, is to add debug lines in the most important components of your gamemode and check which debug line doesn't show up. You might also want to check if the start-up order is correct. Some resources do require other resources to be even working, an incorrect start-up order can mess the initialization up.
  8. @majqq Keep in mind that even if there is no data added, the triggerClientEvent it's (5x?) packet size is bigger than that from setElementData. And triggerClientEvent is also a lot faster and therefore it's data rate is higher, if no buffer is used, it will cause blocking the network a lot faster than with setElementData. So if you broadcast to all players, triggerClientEvent might not always be the best option, because you do not reduce data. triggerClientEvent Fast data rate / requires a slow interval Run code directly / (with elementdata that is only possible for the second time you set the data) More secure No auto download for new players Specify target players* *Before the beta from below. There is a new function available in the beta for element data, that will help shrink the data usage of players that do not need the data. https://wiki.multitheftauto.com/wiki/AddElementDataSubscriber More information here: https://wiki.multitheftauto.com/wiki/SetElementData
  9. WIKI

    Yesterday I added my first wiki page. Which is not necessary something you call 'news'. But it was a lot of fun figuring out how the interface actually works. It is to be honest not very beginner friendly, even though there is a lot of documentation added. documentation

     

    The page/function which I added to the useful functions list:

    https://wiki.multitheftauto.com/wiki/CheckPassiveTimer

    This useful function allows you to use passive timers in your conditions. For example you want to prevent players repeatedly using a command.

    I named the function 'checkPassiveTimer', not sure if that is the best name for it, since it it does SET, CHECK and UPDATE, (+ Clean up cycle), depending on the situation. Checking is what you expect it actually does, so I picked that one.

     

    addCommandHandler("candy", 
    function (player)
    	if checkPassiveTimer("candy timer", player, 5000) then
    		outputChatBox("YES, EAT!", player)
    	else
    		outputChatBox("NO CANDY FOR YOU!", player)
    	end
    end)

     

    Does anybody have any suggestions/idea's/🐛? Or more experience than me with the WIKI + suggestions or improvements for the format?

  10. local nextCommandTime = {} -- function () local key = getPlayerSerial(player) -- serial based -- or local key = player -- element based local timeNow = getTickCount() if timeNow > (nextCommandTime[key] or 0) then nextCommandTime[key] = timeNow + 10000 else -- You will have to wait! end -- end By comparing current operating time with a fixed operating time + future offset, can be used to limit executions. ACL Manually: - Shut down the server (important) Disable commands in ACL: (add to the group: <acl name="Default">) <right name="command.fabricar" access="false" /> Enable commands in ACL: (add to the group you want to have access to this command) <right name="command.fabricar" access="true" /> - Save file - Start the server Or use admin panel to add those rights. @~Sr.Victor
  11. You can only cancel the server variant. onClientVehicleStartExit If the wiki doesn't indicates that it can be cancelled, then you can't cancel it.
  12. local user = dbPoll(qh,500) "=" was missing. And you might also want wait for it a little bit longer, maybe your database is slow. local user = dbPoll(qh, -1) "SELECT * FROM accounts WHERE username=?" Add a limit to speed up your queries: "SELECT * FROM accounts WHERE username=? LIMIT 1" Or your username is incorrect. iprint("username", un)
  13. hmmm, not sure. Maybe your timing is mismatched? setTimer(function () local mysqlResource = getResourceFromName ( "mysql" ) if getResourceState(mysqlResource) == "running" then local con = call ( mysqlResource, "getConnection") iprint("connection", con) else iprint("running state", getResourceState(mysqlResource)) end end, 1000, 1) This is how I handle MySQL failures: function connectMysql() con = dbConnect( "mysql", "dbname="..dbname..";host="..host..";charset=utf8", username, password, "share=1" ); if (con) then outputChatBox("#FFFFFFMySQL connection#00AA00 successful#FFFFFF!", root, 0, 0, 0, true); return true end return false end addEventHandler("onResourceStart", resourceRoot, function () if not connectMysql() then cancelEvent (true, "Can't connect to MySQL server" ) end end)
  14. @RogerPizarro Moved to here: https://forum.mtasa.com/forum/167-scripting/
  15. IIYAMA

    [Help]DGS

    Search on this page with the word: color And you will find what you are looking for per element.
  16. IIYAMA

    [Help]DGS

    Yes, you forgot to explain that... But it wasn't that hard to figure that one out. I answered your question for the most part. You also need to enable propagation: addEventHandler('onDgsMouseClick', getResourceRootElement( getThisResource( ) ), onClickSuicide, true) Not sure why you did change that setting without knowing what it is for. addEventHandler('onDgsMouseClick', getResourceRootElement( getThisResource( ) ), onClickSuicide, true) And even better, attach the event to your button element: addEventHandler('onDgsMouseClick', Olme, onClickSuicide)
  17. IIYAMA

    [Help]DGS

    You can't use killPed on a player clientside. Only serverside. Read the docs: https://wiki.multitheftauto.com/wiki/KillPed Instead (or kill the player serverside, which I would recommend you to do -> prevent strange animation bugs): setElementHealth(localPlayer, 0)
  18. IIYAMA

    Lua f*k sh*t

    No need to bring this not useful 'Lua is :~'(users are :~) topic up from 2 years ago. LOCKED
  19. @erisP You might want to reply at least (, even if you are not going to do anything with it).
  20. @erisP Use the (dynamic) element tree. -- server local colshapeParent = createElement("colshapeParent", "blockColshapeParent") local BlockVehicle = createColCuboid ( 1573.84900,-1637.5,12, 10,6,6 ) setElementParent(BlockVehicle, colshapeParent) local BlockVehicle2 = createColCuboid ( 1573.84900,-1637.5,12, 20,6,6 ) setElementParent(BlockVehicle2, colshapeParent) -- client --[[ -- clientside colshapes do local colshapeParent = getElementByID("blockColshapeParent") if colshapeParent then local BlockVehicle2 = createColCuboid ( 1573.84900,-1637.5,12, 20,6,6 ) setElementParent(BlockVehicle2, colshapeParent) end end ]] function isInColExport () local colshapeParent = getElementByID("blockColshapeParent") if colshapeParent then local colshapes = getElementChildren(colshapeParent) for i=1, #colshapes do local colshape = colshapes[i] if isElementWithinColShape(localPlayer, colshape) then return true end end end return false end Untested. Colshapes must be created in the same resource as the parent, clientside/serverside doesn't matter.
  21. You could try also something like this: https://community.multitheftauto.com/index.php?p=resources&s=details&id=13991 It is probably not what you are looking for, but it might be interesting to look at.
  22. Afaik you can only disable them, which means that you can re-enable them when you are even higher.
  23. most likely
  24. Do you mean that it is inaccurate in some way? Or do you mean that you want to add spread, but that doesn't work out great? @redditing + You have to keep in mind that bullets created by a default weapon do have a different start point. They are NOT created from the weapon muzzle, but from target start. That means that if you set the target of the custom weapon to the target end position, the lines between the two weapons will cross at this point, instead of stay next to each other to the infinity-end position. So maybe try this instead: https://wiki.multitheftauto.com/wiki/GetPedTargetCollision
  25. IIYAMA

    Map files

    Map files Table of contents: Introduction How to read a map file? Broken map file, what to do? Editor bugged, what to do? Modify your maps outside of MTA Extra links Introduction A map-file! What is that? The name already gives away the definition. It is a file which contains a MTA map. The format makes maps portable, so that you can send them over to your friends. You can recognize map-files by the extension: .map Here is an example of a map: Syntax highlight When you open a map file in your text editor. The syntax highlight you should use is XML (HTML will work as well, but the semantic is different and could cause issues with auto complete features, that is if you have enabled those). Changing syntax highlight in for example Visual Studio Code. How to read a map file? Before we start, this is what we call a node: <tagName></tagName> If we take a closer look to the following map file: <map> <object id="object (bevgrnd03b_law) (1)" interior="0" collisions="true" alpha="255" doublesided="false" model="6094" scale="1" dimension="0" posX="635.234375" posY="-3827.2275390625" posZ="5" rotX="0" rotY="0" rotZ="0"></object> <object id="object (gaz9_law) (1)" interior="0" collisions="true" alpha="255" doublesided="false" model="6133" scale="1" dimension="0" posX="625.49114990234" posY="-3771.6955566406" posZ="11.479743003845" rotX="0" rotY="0" rotZ="0"></object> <object id="object (CE_grndPALCST03) (1)" interior="0" collisions="true" alpha="255" doublesided="false" model="13120" scale="1" dimension="0" posX="573.09802246094" posY="-3847.013671875" posZ="3.6442375183105" rotX="0" rotY="22" rotZ="352"></object> <object id="object (CE_grndPALCST03) (2)" interior="0" collisions="true" alpha="255" doublesided="false" model="13120" scale="1" dimension="0" posX="572.64624023438" posY="-3769.0698242188" posZ="4.9519920349121" rotX="0" rotY="21.99462890625" rotZ="343.24649047852"></object> <object id="object (CE_grndPALCST03) (3)" interior="0" collisions="true" alpha="255" doublesided="false" model="13120" scale="1" dimension="0" posX="669.66534423828" posY="-3856.0627441406" posZ="3.6442375183105" rotX="0" rotY="63.99462890625" rotZ="175.99389648438"></object> </map> > we see in there the map node: <map></map> When the map is loaded <map></map> will become our map element. And inside of the map node we see more nodes: <object id="object (bevgrnd03b_law) (1)" interior="0" collisions="true" alpha="255" doublesided="false" model="6094" scale="1" dimension="0" posX="635.234375" posY="-3827.2275390625" posZ="5" rotX="0" rotY="0" rotZ="0"></object> <object id="object (gaz9_law) (1)" interior="0" collisions="true" alpha="255" doublesided="false" model="6133" scale="1" dimension="0" posX="625.49114990234" posY="-3771.6955566406" posZ="11.479743003845" rotX="0" rotY="0" rotZ="0"></object> In this case these two nodes will become two in-game objects. Tagname <tagName></tagName> Each node in the map file will become an element in game. !important A node has a tag name. In this case I gave it the name: "tagName" This tag name specifies in MTA the element type. For example: If it has the name <object></object>, the element-type is an object. If it has the name <ped></ped>, the element-type is a ped. What if the tag name is not matching with one of these entities? (The list is not complete, the rest can be found in this class list, only if the XML syntax is implemented) Then the elements are considered custom elements. They are not visible in game. Custom elements Custom elements have their own purposes. You often see those custom elements used in game modes, for example stealth: <mercenaryspawn id="mercenaryspawn (1)" posX="635.58117675781" posY="-3770.458984375" posZ="18.97974395752" rotX="0" rotY="0" rotZ="0"></mercenaryspawn> The tagname for this node is "mercenaryspawn". The element that is produced after loading the map, is used as a spawnpoint for in a stealth map. Custom elements are invisible. Custom elements do have an orientation. The getElementsByType function can be used to get custom elements. Attributes Attributes are properties applied to a node. They are used to attach data to an element. Example: <entity name="IIYAMA" age="5" type="device" resolutionX="1920" resolutionY="1080" displaySize="31"></entity> An attribute exist out of two parts: <entity name="value"></entity> Name Value The name specifies if the node has the attribute. <entity name></entity> <entity age></entity> If the name is "name", then the node has the attribute "name". And if the name is "age", then the node has the attribute "age". The value will be used for the data for each attribute. <entity name="IIYAMA" age="5"></entity> Identifiers (ID) Every elements can have an identifier attribute, which is used to make an accessible for scripting functions. <tagName id="identifier"></tagName> The identifier of an element can be used in getElementByID to grant access to it. Even though identifiers normally should be unique for each individual, it is not the end of the world if they are not in MTA. They might also be considered as unnecessary for map files without scripts. Element specific attributes There are some attributes that do more than just applying properties. They will change the element appearance and orientation. For example this object: <object interior="0" collisions="true" alpha="255" doublesided="false" model="6094" scale="1" dimension="0" posX="635.234375" posY="-3827.2275390625" posZ="5" rotX="0" rotY="0" rotZ="0"></object> It will be created in interior 0. It will have collisions. (You can walk on it) Alpha. It's opacity is 100%. It is not doublesided. (When you stand inside of the object you can look through it. If doublesided is enabled the same colors/paint from the other side will be applied.) It's model is 6094. It is scaled 100%. (0.5 = 50%, 2 = 200%) Etc. If you want to know which attributes do have influence on the elements appearance and orientation, you have to look that up on the wiki. Here a small list of some those attributes: Broken map file, what to do? If your map file is broken. Step 1 Make a backup. + Always make a backup when re-editing your map. Settings can get lost! Step 2 The first thing you want to do, is just open it in a text-editor. Just give it a quick look and check for anything strange. The file could be empty or some strange values could be used. Do you want to know all the syntax rules (XML)? You can find a list right here: http://www.adobepress.com/articles/article.asp?p=1179145 Step 3 Remove the editor definition. This definition could cause problems in case of invalid characters. From: <map edf:definitions="COBDEF,editor_main"> <!-- Map elements --> </map> To: <map> <!-- Map elements --> </map> Step 4 If you can't find the problem, then you could validate the file. There are services out there that validate XML files. They can help you to find out where your file is broken. Validation tool by W3C: https://validator.w3.org/#validate_by_input Note: You need to do step 3 first. Else you can't parse the file. Step 5 In case of re-opening map files in the editor, but doesn't want to get open. Make a backup. Remove custom elements. See chapter How to read? Retry to open the file. Editor is bugged, what to do? Your editor could be bugged and you are not able to save the map or open a new one. The first thing you want to do is backup the editor_dump folder in your server. This folder is located between all your resources. server\mods\deathmatch\resources\editor_dump Rename the folder name. editor_dump > my_broken_map Stop the map editor. Check if there is a new editor_dump folder. If there is, rename that one as well. Start the map editor again. Modify your maps outside of MTA Sometimes you want to modify your maps without going back in to the editor. Your text-editor is in most cases the way to go. For example you want to move all objects to a new dimension. In Notepad++: Make a backup! (if you are new to this) Select in your file the part you want to replace: dimension="0" Commando: ctrl + H (replacement overlay) Fill in the replace field: dimension="1" Click on: replace ALL. Moving your map? There is a nice online tool that can help you with that: http://mta.dzek.eu/mmove/ Edit your map with the DOM (Document Object Model) Knowing JavaScript? Your browser inspector can be used to modify your maps at a higher level. (If you so desire) Extra links: Parent, child and how this is reflected in MTA https://wiki.multitheftauto.com/wiki/XML https://wiki.multitheftauto.com/wiki/Element_tree Elementdata <sync_map_element_data /> https://wiki.multitheftauto.com/wiki/Meta.xml Load maps (manually + including in meta.xml) https://wiki.multitheftauto.com/wiki/Meta.xml https://wiki.multitheftauto.com/wiki/LoadMapData Save maps https://wiki.multitheftauto.com/wiki/SaveMapData