
Xabi
Members-
Posts
20 -
Joined
-
Last visited
Everything posted by Xabi
-
It isn't that what I'm searching. I want to get the position in X and Y axis of each corner of the object.
-
Hi, I'm doing a spike strips scripts, so I need the X and Y positions of the spikes strips object corners so I can make a colshape with them. Any way to get this? Thanks in advance.
-
Hi all, I've got a GameMode with some resources forming it. The problem with "onPlayerWasted" is that it gets called in 2 of these resources. [in vehicles.lua I have this] function unbindKeysVehicle() if isKeyBound(source, "num_add", "up", toggleEngine) then unbindKey(source, "LALT", "up", toggleEngine) unbindKey(source, "num_add", "up", toggleLights) end end addEventHandler("onPlayerWasted", root, unbindKeysVehicle) [in medic.lua I have this] function playerDeath() local posX, posY, posZ = getElementPosition(source) local interior = getElementInterior(source) local dimension = getElementDimension(source) local ammo = getPedTotalAmmo(source) local skin = getElementData(source, "rpPlayerSkin") local uniform = getElementData(source, "rpPlayerUniform") if getElementData(source, "rpPlayerWorking") == 1 and uniform ~= 0 and getElementData(source, "rpPlayerPoliceName") == false then skin = uniform end if ammo > 1 then local weapon = getPedWeapon(source) local model = exports.functions:getWeaponModel(weapon) local weaponObject = createObject(model, posX, posY, posZ-0.95, 90.0, 0.0, 0.0, true) local query = dbQuery(connectionHandle, "INSERT INTO weapons (posX, posY, posZ, weapon, ammo, model, interior, dimension) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", posX, posY, posZ, weapon, ammo, model, interior, dimension) local result, num_affected_rows, last_insert_id = dbPoll(query, -1) takeWeapon(source, weapon) setElementInterior(weaponObject, interior) setElementDimension(weaponObject, dimension) droppedWeapon = createElement("droppedweapon") setElementData(droppedWeapon, "weapons.wId", last_insert_id) setElementData(droppedWeapon, "weapons.wType", weapon) setElementData(droppedWeapon, "weapons.wAmmo", ammo) setElementData(droppedWeapon, "weapons.wInterior", interior) setElementData(droppedWeapon, "weapons.wDimension", dimension) setElementData(droppedWeapon, "weapons.wObject", weaponObject) end setElementData(source, "rpPlayerKilled", killerWeapon) spawnPlayer(source, posX, posY, posZ, 0, skin, interior, dimension) end addEventHandler("onPlayerWasted", root, playerDeath) So the problem is that, if I write "resourceRoot" in those events the player won't spawn when it gets killed, but if I put "root" it won't unbind ALT and + keys. Any help, please?
-
Hi all, I've got few errors in my script and I need a little bit of help, thanks: function checkVehicleDestroyed(loss) local vehHealth = getElementHealth(source) if vehHealth < 260 then setElementHealth(source, 150) setVehicleEngineState(source, false) setElementData(source, "vehicles.vEngine", false) setTimer(function() blowVehicle(source) addEventHandler("onVehicleExplode", source, sendVehicleToRespawn) end, 10000, 1) end end function makeVehicleDamageProof(thePlayer, seat) if seat == 0 then setVehicleDamageProof(source, true) end end addEventHandler("onVehicleDamage", root, checkVehicleDestroyed) addEventHandler("onVehicleExit", root, makeVehicleDamageProof) So having that code, when I exit the vehicle it will never explode because of nil parameters (it just sets its health to 150 and stops the engine, but the timer gives a nil parameter warning with the source). Thanks for the help.
-
It worked, thanks for all
-
Hi all, when I trigger a client event, it doesn't detect the localPlayer, so if i don't pass enteredCarshop as parameter, and do getElementData(localPlayer, "rpPlayerEnteredCarshop) in clientside, the script doesn't work: Server: function vehicleCatalogCommand(playerSource, commandName) if playerSource then local enteredCarshop = getElementData(playerSource, "rpPlayerCarshopEntered") if enteredCarshop > -1 then triggerClientEvent(playerSource, "onToggleVehicleCatalog", playerSource, enteredCarshop) end end end Client: function toggleVehicleCatalog(enteredCarshop) local carList = xmlLoadFile("carlist.xml") if carList then for _, group in ipairs(xmlNodeGetChildren(carList)) do local carshop = tonumber(xmlNodeGetAttribute(group, "carshop")) if carshop == enteredCarshop then for _, vehicle in ipairs(xmlNodeGetChildren(group)) do local row = guiGridListAddRow(vehicleList) local model = xmlNodeGetAttribute(vehicle, "model") local name = xmlNodeGetAttribute(vehicle, "name") guiGridListSetItemText(vehicleList, row, modelColumn, model, false, true) guiGridListSetItemText(vehicleList, row, vehicleNameColumn, name, false, false) end addEventHandler("onClientGUIClick", vehicleList, showVehicleStats) break end end xmlUnloadFile(carList) guiSetVisible(vehicleCatalog, true) guiSetVisible(vehicleNameLabel, false) guiSetVisible(vehiclePriceLabel, false) guiSetVisible(vehicleRimsLabel, false) guiSetVisible(vehicleRimsCombo, false) guiSetInputEnabled(true) showCursor(true) end end addEvent("onToggleVehicleCatalog", true) addEventHandler("onToggleVehicleCatalog", localPlayer, toggleVehicleCatalog) Any help on this, please?
-
Anybody knows what can it be, please?
-
Hi all, I've got a problem with this callback, as it's executed twice sometimes in my house system. When I create a house with the command (/crearcasa) it just gets called once, but if I load all houses from the database and step into the pickup, the callback gets called twice. function loadAllHouses() local query = dbQuery(connectionHandle, "SELECT * FROM houses") local result = dbPoll(query, -1) for _, row in ipairs(result) do local housePickup = createPickup(row["posX"], row["posY"], row["posZ"], 3, 1273, 0, 0) setElementData(housePickup, "houses.hId", row["id"]) ... Set all data in database here addEventHandler("onPickupHit", housePickup, showHouseInfo) end dbFree(query) end function createHouseCommand(playerSource, commandName) if playerSource then local posX, posY, posZ = getElementPosition(playerSource) ... Create all needed variables local housePickup = createPickup(posX, posY, posZ, 3, 1273, 0, 0) setElementData(housePickup, "houses.hPosX", posX) ... Setting again all data local query = dbQuery(connectionHandle, "INSERT INTO houses (posX, posY, posZ, interior, dimension, houseType) VALUES (?, ?, ?, ?, ?, ?)", posX, posY, posZ, interior, dimension, houseType) local result, num_affected_rows, last_insert_id = dbPoll(query, -1) setElementData(housePickup, "houses.hId", last_insert_id) addEventHandler("onPickupHit", housePickup, showHouseInfo) end end function showHouseInfo(thePlayer) triggerClientEvent(thePlayer, "onShowHouseInfo", thePlayer, source) end addEventHandler("onResourceStart", getRootElement(), loadAllHouses) addCommandHandler("crearcasa", createHouseCommand) What can be wrong with this code? Thanks in advance
-
Ok, after few attemps got it working, thanks for all
-
The problem with this solution is that the server script and client script are in different resources.
-
Hi all, I have a problem with a client event not being triggered on first server startup, but it does when I disconnect and login back. It should show the login interface but, as I said, when I first launch the server it doesn't show it (the window is being created) but, if I disconnect from the server and go in again, without restarting neither the server nor the game, it shows the window correctly. I will leave you the relevant code as it will explain how is done: function checkPlayerStatus() ... if status == "playable" then triggerClientEvent(source, "onPlayerRequestLogin", source) -- This trigger returns True ... end addEventHandler("onPlayerJoin", getRootElement(), checkPlayerStatus) function createLoginWindow() -- This function is called local X = 0.375 local Y = 0.375 local Width = 0.25 local Height = 0.25 wdwLogin = guiCreateWindow(X, Y, Width, Height, "Please Log In", true) -- define new X and Y positions for the first label X = 0.0825 Y = 0.2 -- define new Width and Height values for the first label Width = 0.25 Height = 0.25 -- create the first label, note the final argument passed is 'wdwLogin' meaning the window -- we created above is the parent of this label (so all the position and size values are now relative to the position of that window) guiCreateLabel(X, Y, Width, Height, "Username", true, wdwLogin) -- alter the Y value, so the second label is slightly below the first Y = 0.5 guiCreateLabel(X, Y, Width, Height, "Password", true, wdwLogin) X = 0.415 Y = 0.2 Width = 0.5 Height = 0.15 edtUser = guiCreateEdit(X, Y, Width, Height, "", true, wdwLogin) Y = 0.5 edtPass = guiCreateEdit(X, Y, Width, Height, "", true, wdwLogin) -- set the maximum character length for the username and password fields to 50 guiEditSetMaxLength(edtUser, 50) guiEditSetMaxLength(edtPass, 50) X = 0.415 Y = 0.7 Width = 0.25 Height = 0.2 btnLogin = guiCreateButton(X, Y, Width, Height, "Log In", true, wdwLogin) addEventHandler("onClientGUIClick", btnLogin, loginButtonSubmited, false) -- make the window invisible guiSetVisible(wdwLogin, false) end function showLogin() -- This function is not called on first login, but it does when login the second time -- output a brief welcome message to the player outputChatBox("Welcome to My MTA:SA Server, please log in.") -- if the GUI was successfully created, then show the GUI to the player if (wdwLogin ~= nil) then guiSetVisible(wdwLogin, true) else -- if the GUI hasnt been properly created, tell the player outputChatBox("An unexpected error has occurred and the log in GUI has not been created.") end -- enable the players cursor (so they can select and click on the components) showCursor(true) -- set the input focus onto the GUI, allowing players (for example) to press 'T' without the chatbox opening guiSetInputEnabled(true) end function loginButtonSubmited(button, state) if button == "left" and state == "up" then -- get the text entered in the 'username' field local username = guiGetText(edtUser) -- get the text entered in the 'password' field local password = guiGetText(edtPass) -- if the username and password both exist if username and password then -- trigger the server event 'submitLogin' and pass the username and password to it triggerServerEvent("submitLogin", getRootElement(), username, password) -- hide the gui, hide the cursor and return control to the player guiSetInputEnabled(false) guiSetVisible(wdwLogin, false) showCursor(false) else -- otherwise, output a message to the player, do not trigger the server -- and do not hide the gui outputChatBox("Please enter a username and password.") end end end addEvent("onPlayerRequestLogin", true) addEventHandler("onPlayerRequestLogin", localPlayer, showLogin) addEventHandler("onClientResourceStart", resourceRoot, createLoginWindow) Thanks in advance for your help.
-
Ok, I solved the problem. There was no error, I just had to close MTA before relaunching the server
-
Yes, I changed that part of resourceRoot. The meta.xml file is correct, as createRegisterWindow() function is working perfectly, the problem comes when executing that showRegisterWindow(). Even if I put just an outputChatBox inside of it, doesn't print anything.
-
Making a debug, it gets into the triggerClientEvent part, so I don't think so. I mean, testing all the SQL cases it works, only fails when executing that triggered event.
-
Still the same, the problem is in the clientside with the showRegisterWindow() function, even if I only write and outputChatBox or a print there, it doesn't show anything. But when I do an if with the triggerClientEvent, it returns true, so it's executing the triggerClientEvent but not showRegisterWindow().
-
If I use source instead of player it gives me an exception saying nil value.
-
It's previously defined as a global function checkSerialStatus(playerNick, playerIP, playerUsername, playerSerial) dbHandle = exports.sql:getDatabaseHandle() player = getPlayerFromName(playerNick) dbQuery(getSerialStatus, dbHandle, "SELECT `date` FROM `bans` WHERE `serial` = ? LIMIT 1", playerSerial) end addEventHandler("onPlayerConnect", getRootElement(), checkSerialStatus)
-
Hi all, I have a problem triggering a client event from server, resulting that the cient's function never got called, it doesn't throw any error, just stops calling client's function. Any help will be appreciated, so thanks in advance. Server: function checkPlayerExists(queryHandle) local result = dbPoll(queryHandle, 0) if(#result == 0)then triggerClientEvent(player, "onPlayerNotRegistered", player) else ... more code here ... end Client: function createRegisterWindow() background = guiCreateStaticImage(0.0, 0.0, 1.0, 1.0, "images/background.png", true) registerWindow = guiCreateWindow(0.25, 0.25, 0.5, 0.5, "Registrar nuevo personaje", true) guiSetVisible(registerWindow, false) guiSetVisible(background, false) end function showRegisterWindow() if(registerWindow ~= nil)then guiSetVisible(background, true) guiSetVisible(registerWindow, true) showCursor(true) guiSetInputEnabled(false) else outputChatBox("Ha habido un error al crear la ventana de registro.") end end addEvent("onPlayerNotRegistered", true) addEventHandler("onPlayerNotRegistered", localPlayer, showRegisterWindow) addEventHandler("onClientResourceStart", root, createRegisterWindow)
-
Thanks for the explanation, I will try like that. The handle is just for testing purposes as I'm new to LUA, when I get deep on it, will change.
-
Hi all, I have the following script to get a registered player: function checkLogin(username, password) dbHandle = dbConnect("mysql", "dbname=mta;host=127.0.0.1", "root", "*****") if isElement(dbHandle) then local result = executeSQLQuery("CREATE TABLE IF NOT EXISTS players (id TEXT, name TEXT, password TEXT)") local result = executeSQLQuery("SELECT `id` FROM `players` WHERE `name` = ? AND `password` = ?", username, password) else outputChatBox("Couldn't connect to database.") end end So when I use that, it works but it doesn't show the created table into mysql (I use HeidiSQL to access to the database). Also, if i create the database manually and do only that SELECT, it says that table 'players' can't be found. I searched in registry.db, and it creates the table there as it was an SQLite database so, anybody knows what could be the problem? Thanks in advance