-
Posts
114 -
Joined
-
Last visited
Everything posted by Vector
-
i mean, for example, if you want to save the dimension of the player .... addEventHandler ("onPlayerQuit", getRootElement (), function () local account = getPlayerAccount (source); setAccountData (account, "dimension", getElementDimension(source)); end); when player connects again to the server, you can do this to restore the dimension in which the player is in. addEventHandler ("onPlayerJoin", getRootElement(), function () local account = getPlayerAccount(source); local dimension = getAccountData(accout,"dimension"); if dimension then setElementDimension (source, tonumber(dimension); end; end); is just another way to do it.
-
check Level variable!. You set that variable as local in the function scoreLevel. remove local keyword and it will work. i guess.
-
for that case, is not better to use setAccountData / getAccountData. ?
-
this is not a script problem. Is a MATH problem. for the circurference ... you need to check if the distance from the center of the circurference to the position of the mouse is less or equal than the radius of such circurference. in that case, the cursor is inside... local x,y = getCursorPosition (); if ( (circurference.x-x)^2 + (circurference.y-y)^2) <= circurference.radius^2 then --- inside else --- outside. end; for any irregular polygon, like your trapeze, subdivide it in triangles and check if the point is inside of any of those triangles... if it´s insides, then, it´s inside of the polygon. i wil not tell you how to check if a point is inside of a triangle, just i´ll show you the code. (need basic vector algebra knowledge) trapeze.width and trapeze.height will be the dimension of the bounding rectangle. trapeze.x, trapeze.y will be the position of that rectangle that surrounds your trapeze. trapeze.wt will be the width of the triangle. local x,y = getCursorPosition (); if isPointInTriangle (x, y, trapeze.x, trapeze.y+trapeze.height, trapeze.x+trapeze.wt, trapeze.y, trapeze.x+trapeze.width-trapeze.wt, trapeze.y+trapeze.height) or isPointInTriangle (x,y, trapeze.x+trapeze.width-trapeze.wt, trapeze.y+trapeze.height, trapeze.x+trapeze.wt, trapeze.y, trapeze.x+trapeze.width, trapeze.y) then --- inside else --- outside. end; -- and this is the function to check whatever a point is inside of a triangle. function isPointInTriangle (x,y, x0,y0, x1,y1,x2,y2) -- implementation of the barycentric technique... local v0x,v0y = x2 - x0, y2 - y0; local v1x, v1y = x1 - x0, y1 - y0; local v2x, v2y = x - x0, y - y0; local dot00 = v0x^2 + v0y^2; local dot01 = v0x*v1x + v0y*v1y; local dot02 = v0x*v2x + v0y*v2y; local dot11 = v1x^2 + v1y^2; local dot12 = v1x*v2x + v1y*v2y; local i = 1 / (dot00 * dot11 - dot01 * dot01); local u,v = (dot11 * dot02 - dot01 * dot12) * i, (dot00 * dot12 - dot01 * dot02) * i; return ((u+v)<1) and (u>=0) and (v>=0); -- more info here: [url=http://www.blackpawn.com/texts/pointinpoly/]http://www.blackpawn.com/texts/pointinpoly/[/url] end;
-
-- this will draw "hallo" in the middle of the screen for 5 seconds when you use the command hallo local timer; local function draw () local screenWidth, screenHeight = guiGetScreenSize (); dxDrawText ("hallo", screenWidth/2-50,screenHeight,0,0, tocolor(255,0,0,255), 1, "pricedown"); end; addCommandHandler ("hallo", function () if isTimer (timer) then -- is message shown already? -- if it is, just draw message for 5 more seconds. resetTimer (timer); else -- not, so ... addEventHandler ("onClientRender", getRootElement(), draw); -- timer to hide the message 5 seconds later. timer = setTimer (removeEventHandler,5000,1, "onClientRender", getRootElement(), draw); end; end);
-
if (kills >= 3) and (kills<= 6) then ...
-
maybe there is something wrong in the meta.xml file. (a XML sintax error). because of that, it cannot be loaded.
-
i think the name of the gamemode is tdm not dm, addEventHandler ("onGamemodeMapStart", getRootElement (), function (startedMap) -- check if map is only compatible with tdm gamemode. local mapCompatibleGamemodes = exports.mapmanager:getGamemodesCompatibleWithMap (startedMap); -- mapCompatibleGamemodes is a list of compatible gamemodes for the map. -- you just need to check if only tdm is compatible with it. local tdmGamemode = getResourceFromName ("tdm"); local isTdmOnly = (table.getn (mapCompatibleGamemodes)==1) and (mapCompatibleGamemodes[1] == tdmGamemode); if isTdmOnly then -- tdm only... end; end);
-
setGameSpeed is client-side and server-side function. if you call setGameSpeed in a server-side script, then, the game speed will be changed for all players. otherwise, if you use it in client-side, the game speed will be changed only for the client.
-
type in server console refreshall or restart server.
-
both ways are correct.
-
function spawn () toggleAllControls (source, false); toggleControl (source, "forwards", true); setControlState (source, "forwards", true) setTimer ( function (thePlayer) setControlState (thePlayer, "forwards", false); toggleAllControls (thePlayer, true); end, 10000, 1, source); end;
-
destroying the GUI root element will destroy all the GUI elements. local gui_root = getResourceGUIElement (getThisResource ()); destroyElement (gui_root);
-
you can´t do that. dxDrawImage is just for textures created via dxCreateTexture and not for world textures.
-
addEventHandler ("onClientClick", getRootElement (), function (button,state,absoulteX,absoluteY,worldX,worldY,worldZ,elementClicked) if not elementClicked then return end; -- if set to false, there is no element clicled. -- elementClicked is the element clicked by the client. -- do whatever... end);
-
ok. I don´t know that. i said it´s best because its a more clear solution.
-
this is better.. local fps; local updateTick; addEventHandler ("onClientPreRender", getRootElement (), function (dt) if (not updateTick) or ((getTickCount () - updateTick)>1000) then fps = math.floor ( 1000 / dt ); updateTick = getTickCount (); end; end); addEventHandler ("onClientRender", getRootElement (), function () dxDrawText ("FPS: " .. tostring(fps) , 898, 689, 1018, 736, tocolor(0, 255, 0, 255), 1.00, "default", "left", "top", false, false, true, false, false); end);
-
getPedOccupiedVehicle is client-side as well. and you can hide/show your GUI with this... addEventHandler ("onClientVehicleEnter", getRootElement (), function (thePlayer) if thePlayer ~= getLocalPlayer() then return; end; guiSetVisible (gui, true); -- show the gui. end); addEventHandler ("onClientVehicleExit", getRootElement (), function (thePlayer) if thePlayer ~= getLocalPlayer () then return; end; guiSetVisible (gui, false); -- hide gui. end);
-
I write the code just because I'm bored and I have nothing to do. you have to try it by yourself.! local destroyDelay = 20; -- delay in minutes (20) local hunterID = 425; local timers = {}; addEventHandler ("onVehicleExit", getRootElement (), function () -- check if vehicle is a hunter. if getElementModel (source) ~= hunterID then return; end; -- check if there are any player in the vehicle. local occupants = getVehicleOccupants (source); local anyPlayerInside = false; for _,pairs (occupants) do anyPlayerInside = true; break; end; -- do nothing if there is a player inside. if anyPlayerInside then return; end; -- otherwise... timers [source] = setTimer ( destroyElement, destroyDelay * 60000, 1, source); end); addEventHandler ("onVehicleEnter", getRootElement (), function () -- check if vehicle is a hunter if getElementModel(source) ~= hunterID then return; end; if isTimer (timers [source]) then killTimer(timers[source]); end; end);
-
what does not work?
-
aa ok. . carefull with that function, only work if the GUI font of the gridlist is the default one. if any question: [email protected]
-
you can´t do that directly, but you can use a little trick, leaving spaces at left and right side. I guess. use this function, instead of guiGridListSetItemText function guiGridListSetItemTextAligned(gridList, rowIndex, colIndex, text, section, number, colSize) local gridListWidth = guiGetSize (gridList, false); local gridListColumnWidth = colSize * gridListWidth; local textWidth = dxGetTextWidth (text); -- font must be default. local spaceWidth = dxGetTextWidth (" "); local numSpaces = math.floor ((gridListColumnWidth-textWidth)/2)/spaceWidth); local spaces = string.rep (" ", numSpaces); local alignedText = spaces .. text .. spaces; guiGridListSetItemText (gridList, rowIndex, colIndex, alignedText, section, number); end; -- i have not test it. instead of... guiGridListSetItemText (gridList, itemRow, nameColumn, name, false, false); guiGridListSetItemText (gridList, itemRow, cashColumn, cash, false, true); guiGridListSetItemText (gridList, itemRow, scoreColumn, score, false, true); do this... guiGridListSetItemTextAligned (gridList,itemRow,nameColumn,name,false,false, .233); guiGridListSetItemTextAligned (gridList,itemRow,cashColumn,cash,false,true,.233); guiGridListSetItemTextAligned (gridList,itemRow,scoreColumn,score,false,true,.233);
