Jump to content

MrCode

Members
  • Posts

    6
  • Joined

  • Last visited

MrCode's Achievements

Vic

Vic (3/54)

1

Reputation

  1. Thanks IIYAMA, FindRotation3D worked for the getting rotation. Did not achieve the desired result with a rocket projectile (19) though. Even after rotating it directly at point_B the projectile eventually starts heading out in a different direction, not exactly sure whats up with that. I think an easy way to fix that is using createObject along with moveObject and stuff, but in this case, what should I use to properly send projectiles from point A to point B since createProjectile only has starting position arguments to work with?
  2. Good evening, Community! I need some help calculating an element's rotation based on the following matrix calculation: 'Point_B' is basically the point of which our player or vehicle element is facing towards, we draw a green "+" to show point_B's position on screen. Using processLineOfSight, we are able to show exactly where we're pointing to in the 3D world. The problem is, or what I would really like achieve in this example snippet is, rotating our test object (AK-47) so that it is pointing directly at "Point_B". -- client.lua -- OOP true setElementPosition( localPlayer, -281.52420, 1539.13477, 75.35938 ) -- Test location local theObject = createObject( 355, -281.52420, 1539.13477, 75.35938, 0, 0, 0 ) -- Test object (AK-47) addEventHandler( "onClientRender", root, function ( ) -- CALCULATE "POINT_A" / "POINT_B" ---------------------------------------- local matrix = localPlayer:getMatrix( 0, 0, 0 ) local point_A = matrix:transformPosition( 0, 0, 0 ) local point_B = matrix:transformPosition( 0, 500, 0 ) local hit, x, y, z, element = processLineOfSight( point_A, point_B, true, true, true, false, false, false, false, true, localPlayer ) local hit_start = Vector3( x, y, z ) local point_B = hit and hit_start or point_B local scr = Vector2( getScreenFromWorldPosition( point_B ) ) ---------------------------------------- -- CALCULATE OBJECT ROTATION: -- Point at which I've lost my brain-cells ----------------------------------- local rotX, rotY, rotZ = math.random( 0, 360 ), math.random( 0, 360 ), math.random( 0, 360 ) -- current position of the final brain cell setElementRotation( theObject, rotX, rotY, rotZ ) -- rotate Test object (AK-47) to point to: "Point_B" ---------------------------------------- -- DRAW GREEN TARGET POINT AT: "Point_B" ---------------------------------------- if ( scr.length > 0 ) then dxDrawText( "+", scr - Vector2 ( 0, 0 ), 0, 0, tocolor ( 0, 255, 0, 255 ), 2, "default" ) end end )
  3. Sorry, I wrote the wrong debug output. The actual error is: Error loading image @ 'dxDrawImage' [:resource2/images/image.png] The PNG file in resource2 does indeed exist in the meta.xml, everything is in order with the path and the image does render normal. It just briefly outputs an error before it renders. It's like fileExists returns true while there is a (clear path to image.png), then when using dxDrawImage it has problems loading the image because the image.png itself is not yet recognized as a PNG file by the MTA client. So perhaps fileExists being used onClientRender is a bad move..
  4. Good day, What is the best way to check if a or (any) file actually exists while using onClientRender? I'm using onClientRender to draw a PNG image located in another resource but if the image is missing (not yet downloaded by the client), then still, debug would output an error message. "Error loading image @ 'dxDrawImage' [:resource2/images/image.png]" To avoid that, should the file path become some type of local variable or? I'm not sure because I've tried a bunch of different ways and each of them have the same result. -- resource1: onClientRender if fileExists ( ":resource2/images/image.png" ) then dxDrawImage ( sx, sy, 32, 32, ":resource2/images/image.png" ) end -- Debug: { Error loading image @ 'dxDrawImage' [:resource2/images/image.png] } (x1)
  5. I need to save a table with some values to a player's account so I can then later on extract those values from the target account. For example: local values = getAccountData ( getPlayerAccount ( source ), "SavedTable" ) print: values[1] being "MrCode" or values[2] being "Deez Nutz 1234" The test function ( saveTableToAccount ) doesn't seem to save the table to the account at all, there are no errors either. So how do we save the table? function saveTableToAccount( source ) -- values what we want to save local playerName = getPlayerName ( source ) local playerInfo = "Deez Nutz 1234" -- set what we have as a table value in account data local tableToSave = { playerName, playerInfo } setAccountData( getPlayerAccount ( source ), "SavedTable", tableToSave ) -- what we saved outputChatBox( "saveTableToAccount - Player Name: (" .. playerName .. ") Infomation: (" .. playerInfo .. ")" ) end addCommandHandler( "save", saveTableToAccount ) -- Management / Utility -- To check what we've saved using 'saveTableToAccount' test function -- This function returns a table containing all the user data for the account provided function printAllData ( thePlayer ) local playerAccount = getPlayerAccount( thePlayer ) -- get his account if ( playerAccount ) then -- if we got the account then local data = getAllAccountData( playerAccount ) -- get data count = 0 for _ in pairs(data) do count = count + 1 end -- get the count outputChatBox ( "table holds " .. count .. " entries" ) -- output number of rows if ( data ) then for k,v in pairs ( data ) do outputChatBox(k..": "..v) -- print the key and value of each entry of data end end end end addCommandHandler( "getall", printAllData ) -- add a command handler for command 'getall'
×
×
  • Create New...