-
Posts
114 -
Joined
-
Last visited
Everything posted by Vector
-
what does not work?. show us the errors.
-
you can´t do local teams = getElementsByType ("Admins", getRootElement ()); that will return an empty list. you need to do this.... local teams = getElementsByType ("team", getRootElement ()); with this you will get a list of teams. please, read the information about the function getElementsByType to know what parameters need. getElementsByType
-
if getPlayerTeam (player) == getTeamFromName ("StaffTeam") then -- staff only. end;
-
you can use this function if you know the normal of the surface´s object. (without shaders) dxDrawMaterialLine3D https://wiki.multitheftauto.com/wiki/Dx ... rialLine3D
-
you need to reduce the relative size of the columns. ... instead of local nameColumn = guiGridListAddColumn (gridList, "name", .333); -- name column local cashColumn = guiGridListAddColumn (gridList, "cash", .333); -- cash column local scoreColumn = guiGridListAddColumn (gridList, "score", .333); -- score column try this... local nameColumn = guiGridListAddColumn (gridList, "name", .233); -- name column local cashColumn = guiGridListAddColumn (gridList, "cash", .233); -- cash column local scoreColumn = guiGridListAddColumn (gridList, "score", .233); -- score column
-
You can use this function to get all the teams created. getElementsByType ("team", getRootElement ()); Then, iterate over the table and do whatever. You can also use the next function to get the team name. getTeamName(theTeam) for example, local teams = getElementsByType ("team", getRootElement ()); for _, theTeam in ipairs (teams) do local teamName = getTeamName (theTeam); -- do whatever, for example, create a new tab in a tabpanel. guiCreateTab (teamName, theTabPanel); end;
-
set file as a client-side file. suppose your file is towary.xml in the meta file, put this. > src="towary.xml" />> an put a client-side script to load your items into a grid-list > ="client.lua" type="client" /> src="towary.xml" />> this is the client-side script. (client.lua) -- this is your grid list. local gridList = guiCreateGridList (0.4, 0.4, 0.35, 0.3, true); -- I´ll add a column for the cash, another for the name and the score. local nameColumn = guiGridListAddColumn (gridList, "name", .333); -- name column local cashColumn = guiGridListAddColumn (gridList, "cash", .333); -- cash column local scoreColumn = guiGridListAddColumn (gridList, "score", .333); -- score column -- this will load the items. addEventHandler ("onClientResourceStart", getResourceRootElement (getThisResource ()), function () local file = xmlLoadFile ("towary.xml"); -- open file. assert (file, "Fail to load towary.xml"); -- error if file could not be opened. local children = xmlNodeGetChildren (file); -- get children nodes. for _,child in ipairs (children) do -- for each node... if string.lower (xmlNodeGetName (child)) == "item" then -- be sure it´s a item -- get item data. local attrs = xmlNodeGetAttributes (child); local name,cash,score = attrs.name, attrs.cash, attrs.score; -- check if all attributes are set. -- output an error if some attribute is not set. if not name then outputDebugString ("name attribute not set for item", 2); end; if not cash then outputDebugString ("cash attribute not set for item", 2); end; if not score then outputDebugString ("score attribute not set for item", 2); end; if cash and score and name then -- is a valid item ? -- add new item to gridlist. local itemRow = guiGridListAddRow (gridList); guiGridListSetItemText (gridList, itemRow, nameColumn, name, false, false); guiGridListSetItemText (gridList, itemRow, cashColumn, cash, false, true); guiGridListSetItemText (gridList, itemRow, scoreColumn, score, false, true); end; end; end; xmlUnloadFile (file); -- close file end);
-
you can´t delete MTA static objects. i guess.
-
this is a silly example. suppose you want to save information of all the players that enters in your server. (name, tagcolor, ip...) -- this will create the xml file in which info will be holded. addEventHandler ("onResourceStart", getResourceRootElement (getThisResource ()), function () local fileInfo = xmlCreateFile ("playerInfo.xml", "info"); assert (fileInfo, "Fail to create xml file"); xmlSaveFile (fileInfo); xmlUnloadFile (fileInfo); end); -- this will save info about the player who connects to the server. addEventHandler ("onPlayerJoin", getRootElement (), function () -- get player info. local version = getPlayerVersion (source); local ip = getPlayerIP (source); local name = getPlayerName (source); local serial = getPlayerSerial (source); -- open the file local fileInfo = xmlOpenFile ("playerInfo.xml"); -- create a new node for this player. local node = xmlCreateChild (fileInfo, "player"); -- save info. xmlNodeSetAttribute (node, "name", name); xmlNodeSetAttribute (node, "ip", ip); xmlNodeSetAttribute (node, "version", version); xmlNodeSetAttribute (node, "serial", version); xmlSaveFile (fileInfo); -- this will save all the changes done in the file. xmlUnloadFile (fileInfo); -- close file handle. end); suppose a player called __Vector__ enters to the server. when this happens, a new node will be created in the file... name="__Vector__" version="1.3.0...." ip="..." serial="..." />
-
check this local function changeGUI () local playerX, playerY, playerZ = getElementPosition ( localPlayer ) local playerZoneName = getZoneName ( playerX, playerY, playerZ ) local health = getElementHealth ( getLocalPlayer() ) local class = getElementData ( getLocalPlayer(), "Job" ) local cash = getPlayerMoney( getLocalPlayer() ) guiSetVisible(reWnd, true) showCursor(true) guiSetText (money, "Money : "..cash.."$") guiSetText(job, "Job : "..class) guiSetText(hp, "Health : "..health.."%") guiSetText(loc, "Location : "..playerZoneName) end; local function openGUI( ) local playerX, playerY, playerZ = getElementPosition ( localPlayer ) local playerZoneName = getZoneName ( playerX, playerY, playerZ ) local health = getElementHealth ( getLocalPlayer() ) local class = getElementData ( getLocalPlayer(), "Job" ) local cash = getPlayerMoney( getLocalPlayer() ) guiSetVisible(reWnd, true) showCursor(true) money = guiCreateLabel(13, 93, 200, 19, "Money : "..cash.."$", false, reWnd) job = guiCreateLabel(239, 93, 200, 19, "Job : "..class, false, reWnd) hp = guiCreateLabel(239, 55, 200, 19, "Health : "..health.."%", false, reWnd) loc = guiCreateLabel(13, 55, 200, 19, "Location : "..playerZoneName, false, reWnd) removeEventHandler ("onClientPickupHit", disk, openGUI); removeEventHandler ("onClientPickupHit", disk1, openGUI); removeEventHandler ("onClientPickupHit", disk2, openGUI); addEventHandler ("onClientPickupHit", disk, changeGUI); addEventHandler ("onClientPickupHit", disk1, changeGUI); addEventHandler ("onClientPickupHit", disk2, changeGUI); end addEventHandler("onClientPickupHit", disk, openGUI) addEventHandler("onClientPickupHit", disk1, openGUI) addEventHandler("onClientPickupHit", disk2, openGUI)
-
the problem is that the command handler arguments are: 1ºst the Player who type the command. 2ºnd the command. then, the parameters. check this page. https://wiki.multitheftauto.com/wiki/AddCommandHandler
-
function startScript () menopeli34 = createObject (5837, 0, 0, 100, 0, 0, 0) end function menopeli (thePlayer, cmd, posX, posY, posZ) moveObject ( menopeli34, 15000, posX, posY, posZ ) end function kutsumenopeli (thePlayer, cmd) local x, y, z = getElementPosition ( thePlayer ) moveObject ( menopeli34, 15000, x, y, z + 10 ) end function menowarp (who, cmd) local kohde = getPlayerFromName ( who ) if ( kohde ) then local x,y,z = getElementPosition ( kohde ) moveObject ( menopeli34, 15000, x, y, z + 50 ) end end addCommandHandler ( "kohdemeno", menowarp ) addCommandHandler ( "kutsumeno", kutsumenopeli ) addCommandHandler ( "meno", menopeli ) addEventHandler ("onResourceStart", getResourceRootElement(getThisResource()), startScript)
-
you are mixing client-side code with server-side code erroneusly. client-side only! local nightvision = false; addEventHandler ("onClientResourceStart", getResourceRootElement (getThisResource ()), function () bindKey ("n", "down", function () if not ( googles == 44 ) then nightvision = false setCameraGoggleEffect("normal") else nightvision = true setCameraGoggleEffect("nightvision") setFarClipDistance(1000) end; end); end);
-
I hope this will help you. the problem is that when you retrieve the data with getAccountData, you need to convert it to numbers, cause them are strings. (with tonumber). I fix the problem "I'm staying at the same place spawning." also, I change your code a bit to make it look more clear. if you need help -> [email protected] -- Here you can use tables, so that the script remains more clear ... local gamemode = "funmodev2"; function playerLogin (thePreviousAccount, theCurrentAccount, autoLogin) if isGuestAccount (getPlayerAccount (source)) then return; end; -- here I thinks is better hold a data "funmodev2-datasaved" to check if -- data is saved or not. -- check if our data is saved. if getAccountData (gamemode .. "-datasaved") then -- extract the data. -- you need to convert strings to numbers with tonumber. -- be careful with that,cause getAccountData always return a string. local playerMoney = tonumber (getAccountData (theCurrentAccount, gamemode .. "-money")); local playerSkin = tonumber (getAccountData (theCurrentAccount, gamemode .. "-skin")); local playerHealth = tonumber (getAccountData (theCurrentAccount, gamemode .. "-health")); local playerArmor = tonumber (getAccountData (theCurrentAccount, gamemode .. "-armor")); local R = tonumber (getAccountData (theCurrentAccount, gamemode .. "-R")); local G = tonumber (getAccountData (theCurrentAccount, gamemode .. "-G")); local B = tonumber (getAccountData (theCurrentAccount, gamemode .. "-B")); local playerX = tonumber (getAccountData (theCurrentAccount, gamemode .. "-x")); local playerY = tonumber (getAccountData (theCurrentAccount, gamemode .. "-y")); local playerZ = tonumber (getAccountData (theCurrentAccount, gamemode .. "-z")); local playerInt = tonumber (getAccountData (theCurrentAccount, gamemode .. "-int")); local playerDim = tonumber (getAccountData (theCurrentAccount, gamemode .. "-dim")); local playerWanted = tonumber (getAccountData (theCurrentAccount, gamemode .. "-wantedlevel")); local playerWeapon = {}; -- store all player weapons in a table. local playerWeaponAmmo = {}; -- store weapon amnos in a table. -- load all weapons & amno just with few lines. for i=0,12,1 do playerWeapon [i] = tonumber (getAccountData (theCurrentAccount, gamemode .. "-weaponID" .. tostring (i))); playerWeaponAmmo [i] = tonumber (getAccountData (theCurrentAccount, gamemode .. "weaponAmno" .. tostring (i))); end; spawnPlayer (source, playerX, playerY, playerZ+1, 0, playerSkin, playerInt, playerDim); setPlayerMoney (source, playerMoney); -- here just use 1 one timer. why use 3? setTimer ( function (thePlayer, health, armor, wantedLevel) setElementHealth (thePlayer, health); setPedArmor (thePlayer, armor); setPlayerWantedLevel (thePlayer, wantedLevel); end, 500, 1, source, playerHealth, playerArmor, playerWanted); -- give weapons to player with just few lines with a loop. for i=1,12,1 do giveWeapon (source, playerWeapon [i], playerWeaponAmmo [i], false); end; giveWeapon (source, playerWeapon [0], playerWeaponAmmo [0], true); setCameraTarget (source, source); fadeCamera (source, true, 2.0); setPlayerNametagColor (source, R, G, B); else spawnPlayer ( source, 2005.25, 1544.80, 13.5907, 0, 286, 0, 0, nil); setPlayerMoney ( source, 100); setElementHealth ( source, 100); setPedArmor ( source, 10); giveWeapon ( source, 31, 200); end; end; addEventHandler ("onPlayerLogin", getRootElement(), playerLogin) function onLogout () -- instead of kick the player when trying to logout, just cancel the -- event so that you can avoid him to logout without kick him. (I guess) -- tell him that he cannot logout ... outputChatBox ("You cannot logout!", source, 255, 50, 0); end; addEventHandler ("onPlayerLogout", getRootElement(), onLogout); function onQuit (quitType, reason, responsibleElement) if isGuestAccount (getPlayerAccount (source)) then return; end; local account = getPlayerAccount (source); if not account then return; end; -- save the data. local x,y,z = getElementPosition (source); local r,g,b = getPlayerNametagColor (source); setAccountData(account, gamemode .. "-money", tostring (getPlayerMoney (source))); setAccountData(account, gamemode .. "-skin", tostring (getElementModel (source))); setAccountData(account, gamemode .. "-health", tostring (getElementHealth (source))); setAccountData(account, gamemode .. "-armor", tostring (getPedArmor (source))); setAccountData(account, gamemode .. "-R", tostring (r)); setAccountData(account, gamemode .. "-G", tostring (g)); setAccountData(account, gamemode .. "-B", tostring (b)); setAccountData(account, gamemode .. "-x", tostring (x)); setAccountData(account, gamemode .. "-y", tostring (y)); setAccountData(account, gamemode .. "-z", tostring (z)); setAccountData(account, gamemode .. "-int", tostring (getElementInterior (source))); setAccountData(account, gamemode .. "-dim", tostring (getElementDimension (source))); setAccountData(account, gamemode .. "-wantedlevel", tostring (getPlayerWantedLevel (source))); -- to store weapons & weapon amno, you can do it better with a loop. for i=0,12,1 do setAccountData(account, gamemode .. "-weaponID" .. tostring (i), tostring (getPedWeapon (source, i))); setAccountData(account, gamemode .. "-weaponAmmo" .. tostring (i), tostring (getPedTotalAmmo (source, i))); end; end; addEventHandler ("onPlayerQuit", getRootElement(), onQuit) function onWasted(totalAmmo, killer, killerWeapon, bodypart, stealth) if isGuestAccount (getPlayerAccount(source)) then return; end; local theWeapon = getPedWeapon (source) local weaponAmmo = getPedTotalAmmo (source) fadeCamera (source, false) -- here just use 3 timers instead of 4. setTimer (spawnPlayer, 1000, 1, source, 2036.1735839844, -1413.0563964844, 16.9921875, 0, getElementModel (source), 0, 0, getPlayerTeam(source)); setTimer (setCameraTarget, 1250, 1, source, source); setTimer ( function (thePlayer, weapon, ammo) fadeCamera (thePlayer, true); giveWeapon (source, weapon, ammo, true); end, 2000, 1, source, theWeapon, weaponAmmo); end; addEventHandler ("onPlayerWasted", getRootElement(), onWasted); -- with the code below, player will spawn in that position just 1 time... -- look. function spawnLastPlayer ( posX, posY, posZ, rotZ, theSkin, theInterior, theDimension, theTeam ) spawnPlayer ( source, 2005.25, 1544.80, 13.5907, 0, 286, 0, 0, spawnTeam ) givePlayerMoney ( source, 100 ) setElementHealth ( source, 100 ) setPedArmor ( source, 10 ) giveWeapon ( source, 31, 200 ) fadeCamera (source, true) setCameraTarget (source, source) -- prevent that player will spawn in the sample place ... removeEventHandler ("onPlayerSpawn", source, spawnLastPlayer); end addEventHandler ("onPlayerJoin", getRootElement (), function () addEventHandler ( "onPlayerSpawn", source, spawnLastPlayer); end);
-
I think is better cause you don´t have to add a clientside-script (avoid client-side when you think you can do it server-side)
-
solidsnake, there is no reason to add %02 cause the range of hours is 0-23 and for minutes is 0-59. wich is < 100 (3 numbers)
-
----------------------------- -- Userpanel Design --------- ----------------------------- function design () showCursor (true) local realTime = getRealTime ( ) local rTime = string.format ( "%02d:%02d", realTime.hour, realTime.minute) local ikony = { ["pohar"] = guiCreateStaticImage(0.09, 0.11, 0.27, 0.20, "img/1.png", true), -- Obdélník ["ovladac"] = guiCreateStaticImage(0.09, 0.32, 0.13, 0.20, "img/5.png", true), -- Čtverec ["sluchatka"] = guiCreateStaticImage(0.2296, 0.32, 0.13, 0.20, "img/7.png", true), -- Čtverec ["taska"] = guiCreateStaticImage(0.507, 0.11, 0.13, 0.20, "img/9.png", true), -- Čtverec ["fotak"] = guiCreateStaticImage(0.368, 0.11, 0.13, 0.20, "img/8.png", true), -- Čtverec ["posta"] = guiCreateStaticImage(0.368, 0.32, 0.27, 0.20, "img/6.png", true), -- Obdélník ["kalendar"] = guiCreateStaticImage(0.368, 0.53, 0.27, 0.20, "img/2.png", true), -- Obdélník ["kufr"] = guiCreateStaticImage(0.646, 0.53, 0.27, 0.20, "img/3.png", true), -- Obdélník ["statistika"] = guiCreateStaticImage(0.646, 0.32, 0.27, 0.20, "img/11.png", true), -- Obdélník ["cas"] = guiCreateStaticImage(0.646, 0.11, 0.27, 0.20, "img/10.png", true), -- Obdélník ["zpet"] = guiCreateStaticImage(0.09, 0.53, 0.27, 0.20, "img/4.png", true), -- Obdélník }; -- set alpha & disable static images. for _,gui in pairs (ikony) do guiSetEnabled (gui, false); guiSetAlpha (gui, .75); end; local labely = { ["cas"] = guiCreateLabel(0.637, 0.13, 0.27, 0.19, ""..rTime, true), }; font = guiCreateFont( "lithos.ttf", 75 ) guiSetFont( labely["cas"], font ) guiLabelSetHorizontalAlign(labely["cas"], "center", false) guiLabelSetVerticalAlign(labely["cas"], "center") addEventHandler( "onClientMouseLeave", root, function(aX, aY) for _,gui in pairs (ikony) do if source == gui then guiSetAlpha (source, 1); end; end; end ) addEventHandler ( "onClientGUIClick", ikony["pohar"], btn2, false ) end function btn2(button) if button == "left" then outputChatBox ("xaxax") end end addCommandHandler ("up", pohar ) end addCommandHandler ("up", design )
-
why you don´t do this --> function godmode() local team = getPlayerTeam ( source ) if getTeamName (team) == "Freeroam" then extecuteCommandHandler ("godmode", source); end end addEventHandler("onPlayerLogin", getRootElement(), godmode )
-
string.format is like printf in C. function getRealTimeFormatted () local timeInfo = getRealTime (); return string.format ("%d/%d", timeInfo.hour, timeInfo.minute); end; outputChatBox ("Current server time is: " .. getRealTimeFormatted ());
-
guiSetInputMode ("no_binds");
-
you are right. conclussion -> if you don´t care about the order in which functions are executed, they could individually be handlers for that event. if you have to take into account the order in which functions are executed, you must use a single handler for that event which will execute the functions in a particular order. you say that? for the 1º case, you can add your event handlers in different files. (no matter the order in which scripts are executed) for the 2º case, you must take into account how order in which lua loads your scripts. (the functions must be visible for your event handler, so they can be called)
-
but there is an inconvenient. if you want to call a function declared on a different file, lua need to run first that lua script. you need to change the order in which scripts are loaded. (changing meta.xml file) if you add an addEventHandler (...) on each file, you avoid this problem.
