-
Posts
1,803 -
Joined
-
Last visited
-
Days Won
8
Everything posted by Citizen
-
Haha, I dunno either. I just found that ratio when I was helping someone (can't find the thread back) in a code I didn't made. But if I had to, I would process like this: 1 - Find in GTA a spot that is really far from the center of the map (i.e: near the top right corner of the map) 2 - Find an easy spot to let us pick the right pixel on the map image (i.e: a corner of a building) 3 - Get the coordinates X and Y of the spot in the game and the coordinates of the pixel on the map image. 4 - Do some math to get the ratio. Well, I just gave it a try ! I used this image (6000 x 6000 px): Click here And I did the 3 first steps (click on it to see the fullsize): it's 70 not 71 sorry Now we just need to de math part: We know that the image size is 6000 x 6000 px and the coordinates (0, 0) is the top left corner of the image. We also know that (2832, 2931) in GTA corresponds to (5831, 70) on the image file and that (0, 0) in GTA corresponds to (3000, 3000) on the image (if the map is well centered in the image ofc). First we need to be in the same referential (both the same origin (0, 0)). So we will just substract 3000 to x (of the pixel) and substract y (of the pixel) to 3000 3000 - x = 3000 - 5831 = 2831 --looks really close to the x position of the spot in GTA unit Oo 3000 - y = 3000 - 70 = 2930 -- omg, looks really close to the y position of the spot in GTA unit !! Well the randomness wanted that the image I found has exactly a ratio of 1:1 ! (1px = 1 GTA unit) So to get back on what I said: I was maybe drunk when I read the code and assumed the ratio was 1:100 The same map at 3000 x 3000 px has a ratio of 1:2 This probably worth writing a tutorial. Best regards, Citizen
-
No problem Have fun
-
So if a player comes with a resoultion of 800 x 600, what will happen ? Yeah, it will draw the image at 1920 x 1080. To make the image filling the screen perfectly, use the WhoAmI's code. @Evaldas101: can you upload your login_bg.jpeg on an image hoster like imgur.com ? To know what we are trying to deal with.
-
So what do you want to do ? Display something on screen while downloading ? or delay the download ?
-
You right, the event isn't triggered (just check the sources). You can't trigger buit-in events but you can just override the guiComboBoxSetSelected function to trigger a new custom event each time you do use this function: --Copying the original function into _guiComboBoxSetSelected _guiComboBoxSetSelected = guiComboBoxSetSelected --Creating our custom event: addEvent("onClientGUIComboBoxSelected") --overriding the original one function guiComboBoxSetSelected( comboBox, itemIndex ) --trigger our custom event: triggerEvent("onClientGUIComboBoxSelected", comboBox, comboBox) --call the original function with the same arguments: return _guiComboBoxSetSelected( comboBox, itemIndex ) end --Add this if you want to be triggered when the user select it too: addEventHandler("onClientGUIComboBoxAccepted", root, function ( comboBox ) triggerEvent("onClientGUIComboBoxSelected", comboBox, comboBox) end) And use that event instead of onClientGUIComboBoxAccepted: function onComboSelected() outputChatBox("comboBox selected") end addEventHandler("onClientGUIComboBoxSelected", root, onComboSelected)
-
This resource is broken, and the author probably won't fix it. Try to find another one or do it yourself.
-
As far I know, a map of 3000 x 3000 has a ratio of 1:100 (1px = 100 gta units) So paste this function somewhere into your script: local mapWidth, mapHeight = 3000, 3000 local ratio = 1/100 --100 gta units = 1 pixel function gtaToMapCoordinates(x, y) return x*ratio + mapWidth/2, y*ratio + mapHeight/2 end And use it like that to get the posistion of the player on the image: ... local px, py = getElementPosition(localPlayer) --convert gta coordinates into local mpx, mpy = gtaToMapCoordinates(px, py) ...
-
You're welcome. Hope you will do nice interfaces
-
I didn't ask you the content of your .map but how you were adding it to your resource. By not guessing I was talking about the meta, I can guess you didn't added your map into the meta.xml of your resource. Open your resource folder and create a "maps" folder (it's a example, you can use another name if you need to) and put your myMap.map in it. Then open your meta.xml and add this line: <map src="maps/myMap.map" /> Then restart your resource and it should be fine.
-
This addEventHandler is executed at load time (when the server starts) but of course, am is equal to nil because no one can start the job before the server has been started. And WTF ! Your code would give the player 1034$ twice ! Because the event will be triggered for the vehicle AND the player. By the way, we can't do it like that with the code I posted above. We have to add the event handler when the marker is created (and optionally use an anonymous function). Here is the new OnEnter function (it's a good practice to start the function names with a lowercase letter => onEnter): function OnEnter ( thePlayer, seat, jacked ) if ( getElementModel ( source ) == 448 ) then outputChatBox ( "Job started !",thePlayer,255,255,0 ) local am = createMarker(-2075.11133,900.70227,64.13281 - 1, "cylinder", 3, 0, 102, 51, 153) local ab = createBlip (-2075.11133,900.70227,64.13281, 0, 3, 102,51,153 ) --Link the blip to the marker this way, if you destroy the marker, it will destroy the blip too setElementParent(ab, am) -- saving the marker on the player element setElementData(source, "jobDestination", am) --Adding the event handler: addEventHandler( "onMarkerHit", am, function ( elem ) if not getElementType(elem) ~= "player" then return end --abort if not a player --abort if the player who entered in it wasn't HIS marker if getElementData(elem, "jobDestination") ~= source then return end local money = 1034 givePlayerMoney(elem, money) --give him his cash outputChatBox("[You won "..money.."$ !", elem, 255, 255, 0 ) end) -- You probably want to do that too (I didn't think about it in my previous post) -- hide the marker for everyone setElementVisibleTo(marker, root, false) --show it back for the player setElementVisibleTo(marker, thePlayer, true) end end addEventHandler ( "onVehicleEnter", getRootElement(), OnEnter ) As you can see, I also added this: -- You probably want to do that too (I didn't think about it in my previous post) -- hide the marker for everyone setElementVisibleTo(marker, root, false) --show it back for the player setElementVisibleTo(marker, thePlayer, true)
-
Wow Wow guys slow down a bit and just let's get back into the first problem: The code WhoAmI and iAbo told you are just bad ! They will work for at most 1 player at a time ! If a second player start the job, then ab and am that were holding the blip and the marker of the first player will now contain the blip and the marker of the second. So when the first player will exit the vehicle, his blip and marker will still be visible for him because the code destroyed the blip and the marker of the second player. Is it still what you wanted ? I don't think so. This code will work on client side (you just need to replace the 2 server events by the clients ones). Or do it nicely doing like this: function OnEnter ( thePlayer, seat, jacked ) if ( getElementModel ( source ) == 448 ) then outputChatBox ( "Job started !",thePlayer,255,255,0 ) local am = createMarker(-2075.11133,900.70227,64.13281 - 1, "cylinder", 3, 0, 102, 51, 153) local ab = createBlip (-2075.11133,900.70227,64.13281, 0, 3, 102,51,153 ) --Link the blip to the marker this way, if you destroy the marker, it will destroy the blip too setElementParent(ab, am) -- saving the marker on the player element setElementData(source, "jobDestination", am) end end addEventHandler ( "onVehicleEnter", getRootElement(), OnEnter ) function OnExit ( thePlayer, seat, jacked ) if ( getElementModel ( source ) == 448 ) then -- getting the marker stored on the player element local am = getElementData(thePlayer, "jobDestination") if am then --if we got the marker destroyElement( source ) outputChatBox ( "You quitted your job.",thePlayer, 255, 0, 0 ) -- destroy the marker and it's children (blip is a child of marker) destroyElement ( am ) setElementData(thePlayer, "jobDestination", false) end end end addEventHandler ( "onVehicleExit", getRootElement(), OnExit )
-
Show us how you do add it.
-
Sure, here is how you should process to make your dx stuffs look the same on every resolutions: First, just draw your stuff for your own resolution, do no matter of compatibilities. function showGUI() dxDrawRectangle(628.0, 309.0, 664.0, 498.0, tocolor(0,0,0,210), false) dxDrawRectangle(779.0, 374.0, 496.0, 414.0, tocolor(90,134,255,180), false) dxDrawRectangle(779.0, 348.0, 86.0, 26.0, tocolor(90,134,255,180), false) dxDrawRectangle(628.0, 258.0, 664.0, 51.0, tocolor(90,134,255,210), false) dxDrawImage(871.0, 272.0, 178.0, 27.0, "report.png", 0.0, 0.0, 0.0 , tocolor(255,255,255,255), false) end Once done, just use a calculator to translate the absolute positions and sizes into relatives ones. To do that, you need to know the resolution of your game when you made your dx stuffs (so 1600x900 in your case): the new relative positions must be calculated like so: newX = X / 900 newY = Y / 1600 newW = W / 900 newH = H / 1600 You should end with this: function showGUI() dxDrawRectangle(0.393, 0.343, 0.415, 0.553, tocolor(0,0,0,210), false) dxDrawRectangle(0.487, 0.415, 0.310, 0.460, tocolor(90,134,255,180), false) dxDrawRectangle(0.487, 0.387, 0.054, 0.029, tocolor(90,134,255,180), false) dxDrawRectangle(0.393, 0.287, 0.415, 0.057, tocolor(90,134,255,210), false) dxDrawImage(0.544, 0.302, 0.111, 0.030, "report.png", 0.0, 0.0, 0.0 , tocolor(255,255,255,255), false) end But dx functions only accept absolute positions and sizes. So we just have to multiply these values by resolution of the current player: (the x and w by the horizontal resolution and the y and h by the vertical resolution): local scW, scH = guiGetScreenSize() function showGUI() dxDrawRectangle(0.393*scH, 0.343*scW, 0.415*scH, 0.553*scW, tocolor(0,0,0,210), false) dxDrawRectangle(0.487*scH, 0.415*scW, 0.310*scH, 0.460*scW, tocolor(90,134,255,180), false) dxDrawRectangle(0.487*scH, 0.387*scW, 0.054*scH, 0.029*scW, tocolor(90,134,255,180), false) dxDrawRectangle(0.393*scH, 0.287*scW, 0.415*scH, 0.057*scW, tocolor(90,134,255,210), false) dxDrawImage(0.544*scH, 0.302*scW, 0.111*scH, 0.030*scW, "report.png", 0.0, 0.0, 0.0 , tocolor(255,255,255,255), false) end And here you go ! You just got your dx stuffs that will look the same on all resolutions. I would suggest you to use the guiEditor resource that also let you create dx stuffs. But be sure to set the Rel/Abs to relative on child and parents (right click on the screen then click on the right menu item): https://community.multitheftauto.com/ind ... ils&id=141
-
Sounds nice but can you add screenshots from a reliable image hoster please ?
-
Please use a setTimer instead ! CVC said it would be better but he is wrong because you are actually updating the text 30 times per second at 30FPS ! (and 60 for 60FPS etc) You can use a setTimer to update it every 5 seconds for example (not 60 (= 1min) because the timers aren't really accurate so by setting it at 5 seconds, the clock can be late from 5 secs at most which is totally acceptable for a clock the player won't really care about). By doing that you are reducing the client CPU load because your script will be executed 1 times every 5 seconds instead of 150 times at 30 FPS (and 300 at 60FPS). Hope it will help to understand what onClientRender is really used for.
-
Ok, and what's the problem you want us to fix ?
-
Les setElementData ou getElementData : empoisonné ?
Citizen replied to TheCapn's topic in French / Français
Salut Abraham, Tout dépends de ce que tu entends par "gérer les données". Les Element Datas sont des variables attribués à un élément spécifique. Ils ne remplacent en aucun cas les tableaux ! Donc en général, on utilisera un Element Data lorsque la donnée que l'on veut stocker à un lien fort avec l'élément sur lequel on veut le stocker. Ainsi, pour stocker l'XP d'un joueur par exemple, on préférera utiliser un Element Data qui aura pour nom "XP" par exemple. Pour récupérer l'XP du joueur, un simple getElementData sur ce joueur suffit et ça tiens en une ligne. Un autre avantage, c'est que les données enregistrées sur un élément seront automatiquement détruites lorsque cet élément sera détruit (déconnexion dans le cas d'un joueur) libérant ainsi de la RAM pour d'autres variables ou pour le reste du système (je parle ici du serveur/pc qui héberge le serveur MTA). Avec un tableau, il faudrait faire du code supplémentaire afin de supprimer à la main les données référencé par un élément qui n'existe plus. La réponse est non, les ressources utilisées par ces fonctions sont presque insignifiantes. Et si l'Element Data n'as pas besoin d'être accessible pour le client, on peut également précisé de ne pas la synchroniser avec ce dernier grâce au 4ème arguement optionel du setElementData. En conclusion, les Element Datas sont vivement conseillés lorsqu'il s'agit de stocker des données personnelles à un élément. -
Oh wups ! You're right, I forgot to replace the name after I copied pasted that piece of code. Thanks.
-
Ok I think I did it, the only way to be sure is to test it. I checked the code 3 times line per line and in my head it does work Add this right under the loop for the blips (or right over if you want the blips to be rendered over the radar areas). for k, radararea in ipairs(getElementsByType("radararea")) do local rint = getElementInterior(radararea) local rdim = getElementDimension(radararea) if pi == rint and pd == rdim then local rx, ry = getElementPosition(radararea) local rw, rh = getRadarAreaSize(radararea) local rx2, ry2 = rx + rw, ry + rh local dist = getDistanceBetweenPoints2D(px, py, rx, ry) local dist2 = getDistanceBetweenPoints2D(px, py, rx2, ry2) --- As I already said, I don't understand this part, but if you are sure it's working nice for blips then it should work --- --top left corner local angle = 180 + findRotation(px, py, rx, ry) local crx, cry = getDistanceRotation(0, 0, range*(dist/range)/2, angle) local rX = math.max(rmapX, math.min(rmapX + rmapW, (rmapX+(rmapW/2))+crx)) local rY = math.max(rmapY, math.min(rmapY + rmapH, (rmapY+(rmapH/2))+cry)) -- bottom right corner local angle2 = 180 + findRotation(px, py, rx2, ry2) local crx2, cry2 = getDistanceRotation(0, 0, range*(dist2/range)/2, angle2) local rX2 = math.max(rmapX, math.min(rmapX + rmapW, (rmapX+(rmapW/2))+crx2)) local rY2 = math.max(rmapY, math.min(rmapY + rmapH, (rmapY+(rmapH/2))+cry2)) ---------------------------------------------------------------------------------------------------------------------------- if rX ~= rX2 and rY ~= rY2 then --means it's out of the radar local rr, rg, rb, ra = getRadarAreaColor(radararea) local rW, rH = rX2 - rX, rY2 - rY --- I dunno if that part really does what it should. I assume it does. --- if (isRadarAreaFlashing(radararea)) then ra = ra*math.abs(getTickCount()%1000-500)/500 end -------------------------------------------------------------------------- dxDrawRectangle(rX, rY, rW, rh, tocolor(rr, rg, rb, ra)) end end end Note: Do not create the radar area with a too high alpha if you want to see the map under the rectangles. I really hope it will work EDIT: Fixed typo at line 32 (cf. next post)
-
You're welcome
-
Wei just told you the solution but you don't really seem to care about it: Solidsnake's code with Wei's fix: function replaceModel ( ) local txd = engineLoadTXD ( "bobcat.txd" ) engineImportTXD ( txd, 422 ) local dff = engineLoadDFF ( "bobcat.dff" ) engineReplaceModel ( 422 ) end addEventHandler ( "onClientResourceStart", resourceRoot, replaceModel )
-
@KRZO and @novo: Please be carefull when you want to help someone, check setElementModel syntax addEventHandler ( 'onClientGUIClick', resourceRoot, function() if ( source == GUIEditor.button[1]) then setElementModel(localPlayer, 77) elseif ( source == GUIEditor.button[2]) then setElementModel(localPlayer, 78 ) elseif ( source == GUIEditor.button[3]) then setElementModel(localPlayer, 72 ) elseif ( source == GUIEditor.button[4]) then setElementModel(localPlayer, 71) end end )
-
Haha yeah I was like "WTF" when he said it didn't work, I immediatly checked what I posted and I don't know why the setElementData disapeared (because I added the comments after I did the code ...). So yeah, just a fail in my copy paste from my ide. Thanks WhoAmI