Andres99907
-
Posts
44 -
Joined
-
Last visited
Posts posted by Andres99907
-
-
I am making a script to use flares on aircraft, the script works fine until two players use a flare at the same time, the declared variables change and one of the flares is not destroyed.
Here is a video of my script:
I was checking the creator of the flare with an outpuchatbox at the end of the script, and I saw that the creator changed, which means that the variable was declared again.Flares = {} Chaffs = {} function FlarePhys(x, y, z, distance, gz) player = client index = #Flares + 1 Flares[index] = { ["Vehicles"] = { getPedOccupiedVehicle(player) }, ["Lights"] = { createMarker(x,y,z,"corona", 1, 255,0,0) }, ["Flares"] = { createObject(2060, x,y,z) } } setElementData(Flares[index]["Vehicles"][1], "Dismissile", true) setElementCollisionsEnabled(Flares[index]["Flares"][1], false) attachElements(Flares[index]["Lights"][1], Flares[index]["Flares"][1]) moveObject(Flares[index]["Flares"][1], distance*100, x, y, gz +1.5) setTimer ( function() if isElement(Flares[index]["Vehicles"][1]) then removeElementData(Flares[index]["Vehicles"][1], "Dismissile") else destroyElement(Flares[index]["Flares"][1]) destroyElement(Flares[index]["Lights"][1]) end end, 1000, 1 ) setTimer ( function() outputChatBox(getPlayerName(player)) destroyElement(Flares[index]["Flares"][1]) destroyElement(Flares[index]["Lights"][1]) end, 8000, 1 ) end addEvent("UseFlares", true) addEventHandler("UseFlares", getRootElement(), FlarePhys)
I need help because i don't know how to make the function work for every player and not for the player that uses the Flare i will appreciate the help, I think i can do this script clientside triggering it for all players but if i do this serverside i will be happy haha.
-
9 hours ago, Zango said:
That's interesting. I would have guessed it was caused by MTA.
There's a bug report about this issue here: https://github.com/multitheftauto/mtasa-blue/issues/1326
It's an old bug and even though it's only visual it's really annoying and happens on a lot of servers (also without peds)
If anyone has information about it feel free to add!
I will try to fix it using SetCameraMatrix and check if still happen.
I think it will not work but i will keep trying.
-
Sometimes when i see peds on the screen some bugs occur, I have tested on several computers and the same bug happens, the bug can be reproduced with some popular scripts like npchlc_traffic, slothbot or zombies, and I have never found out that it can be
Here is a video of the glitchy screen
I need help, because i can't find any topic about this u_u
-
On 19/12/2020 at 04:04, Addlibs said:
The reason is that your script only has storage for one flames element, while there can be multiple people. What you need to do is use tables, with the vehicle element as the key, and its flames element as the value. That way, you index the table to get the element, check if it exists, delete it if so, create new one if necessary, etc.
Here, I've fixed one of the functions for you as an example, and you should be able to
-- beginning of serverside code firethrusters = { --structure: [vehicle] = {[1] = firethrustl, [2] = firethrustr} } -- ... the rest of the code here ... function ThrustersOff(veh, x, y, z) -- you forgot to collect the parameters the event was sending over --if thePlayer ~= localPlayer then return end -- no idea what this line does. localPlayer isn't defined on the server, neither is thePlayer in this function if not firethrusters[veh] then return end -- if there is no firethruster for this vehicle, abort here destroyElement(firethrusters[veh][1]) destroyElement(firethrusters[veh][2]) firethrusters[veh] = nil -- presence of this data determines whether an attempt will be made to delete, remove this data to prevent potential 'nil passed instead of element to destroyElement' error end addEvent("thrustersoff", true) addEventHandler("thrustersoff", getRootElement(), ThrustersOff)
You'll need to do the same for the light. You'll also want to handle the event onElementDestroy to catch the vehicle disappearing for whatever reason, and make sure these thruster elements and stuff are also deleted, otherwise they'll remain in the place where the vehicle last was, forever.
That was a lot of work because i don't know much about tables, but i made the table and i made my script work thank you
-
Im working on a script wich create flames on the Thrusters of a vehicle (Mammoth Thruster of GTA Online), works well if you are the only that has a Thruster, but if someone also has a Thruster and gets out the vehicle, your Thruster will keep the attached elements and will not destroy the flames if you get out of the vehicle:
Here is a video of what is happening:
https://www.youtube.com/watch?v=Q3z9fdnBG0w
and serverside and clientside scripts that are involved
Serverside: (Functions for creating the flames)
function LightOn(vehicle, x, y, z) if thePlayer ~= localPlayer then return end light = createMarker ( x , y , z, "corona", 0.5, 255, 160, 0, 170 ) attachElements(light, vehicle, 0, -0.3, -0.8) end addEvent("lighton", true) addEventHandler("lighton", getRootElement(), LightOn) function LightOff() if thePlayer ~= localPlayer then return end if light then destroyElement(light) end end addEvent("lightoff", true) addEventHandler("lightoff", getRootElement(), LightOff) function ThrustersOn(vehicle, x, y, z) if thePlayer ~= localPlayer then return end superhitbox = createObject (3471, x , y , z) setElementAlpha(superhitbox, 0) firethrustl = createObject (2031, x , y , z) firethrustr = createObject (2031, x , y , z) attachElements(superhitbox, vehicle, 0, -10, -1) attachElements(firethrustl, vehicle, 0.47, -0.4, -0.2) attachElements(firethrustr, vehicle, -0.47, -0.4, -0.2) setElementCollisionsEnabled(firethrustl, false) setElementCollisionsEnabled(firethrustr, false) end addEvent("thrusterson", true) addEventHandler("thrusterson", getRootElement(), ThrustersOn) function ThrustersOff() if thePlayer ~= localPlayer then return end if not firethrustl then return end destroyElement(firethrustl) destroyElement(firethrustr) end addEvent("thrustersoff", true) addEventHandler("thrustersoff", getRootElement(), ThrustersOff)
Clientside: (Functions that triggers serverside events when you are in the Thruster)
Thruster = 465 function SitOnThruster(thePlayer) if thePlayer ~= localPlayer then return end local vehicle = getPedOccupiedVehicle(localPlayer) if ( vehicle and getElementModel (vehicle) == Thruster ) then bindKey("vehicle_fire", "down", shootProjectile) triggerServerEvent ( "onthruster", resourceRoot) local x, y, z = getElementPosition(vehicle) local h, m = getTime() triggerServerEvent("thrusterson", getRootElement(), vehicle, x, y, z) if h > 20 then triggerServerEvent("lighton", getRootElement(), vehicle, x, y, z) else return end end end addEventHandler ( "onClientVehicleEnter", root, SitOnThruster ) function Notsit(thePlayer) if thePlayer ~= localPlayer then return end if Thruster then triggerServerEvent("thrustersoff", getRootElement(), vehicle, x, y, z) triggerServerEvent("lightoff", getRootElement(), vehicle, x, y, z) else return end end addEventHandler ( "onClientVehicleExit", root, Notsit ) function killed() if Thruster then if (isPedInVehicle(localPlayer) and Cars[getElementModel(getPedOccupiedVehicle(localPlayer))]) then if getPedOccupiedVehicleSeat ( localPlayer ) == 1 then return end triggerServerEvent("thrustersoff", getRootElement(), vehicle, x, y, z) triggerServerEvent("lightoff", getRootElement(), vehicle, x, y, z) else return end end end addEventHandler ( "onClientPlayerWasted", localPlayer, killed ) function shootProjectile() if not disparado then local vehicle = getPedOccupiedVehicle(localPlayer) if ( vehicle and getElementModel (vehicle) == Thruster ) then if isVehicleOnGround(vehicle) == false then local x, y, z = getElementPosition(vehicle) projectile = createProjectile(vehicle, 15, x, y+4, z-10) disparado = true setTimer ( function() disparado = false end, 1500, 1 ) else local x, y, z = getElementPosition(vehicle) createProjectile(vehicle, 15, x, y, z-3) disparado = true setTimer ( function() disparado = false end, 1500, 1 ) end end end end
I'm very confused, i'm trying to make the script only create element for each player.
-
I created this script:
this script makes the helicopter able to fire an invisible minigun, and the script does it very well.
The problem...
All it's clientside
i don't know how to make the miniguns fire serverside
Setweaponstate doesn't work serverside
and the minigun cannot harm any player clientside except LocalPlayer
-
On 10/09/2020 at 17:37, IIYAMA said:
That would be a little bit hard, since the effect is applied globally, so there will always be a little bit desync.
But you can make sure the code doesn't do anything when other players are entering vehicles:
addEventHandler("onClientVehicleEnter", getRootElement(), function(thePlayer) if thePlayer ~= localPlayer then return end
Note: Even if the "onClientVehicleEnter" event is clientside, it does still trigger for remote players.
You helped me a loot bro : D thank you
- 1
-
function comprarbandito ( thePlayer, command) local playeraccount = getPlayerAccount ( source ) takePlayerMoney ( thePlayer, 500000 ) setAccountData ( playeraccount, "rc.bandito", adquirido ) end addCommandHandler ( "comprarbandito", comprarbandito ) function Banditoadquirido (_, playeraccount ) if ( playeraccount ) then local ban = getAccountData ( playeraccount, "rc.bandito" ) if ( ban ) then Banditocomprado = true end end end addEvent ( "banditobuyed", true ) addEventHandler ( "banditobuyed", getRootElement(), Banditoadquirido )
This function takes 500000 dollars to give a player permission to use a RC Bandito in a gui (Like in GTA Online)
but, when i put the command "comprarbandito" Bad argument @ getplayeraccount, got nil, i never used getplayeraccount or setplayeraccount, and i don't know if the other function (Banditoadquirido) will work
-
I'm using this script to make Thruster fly, only the Player who uses the Thruster will fly, but if other player enters to other Thruster, the script executes one more time the function and the Player in the First Thruster stop flying (because the function is executed again by the other player) I don't know how to make this script not affect the other players
here is a video.
and this the part of the script wich has the Problem:
addEventHandler("onClientVehicleEnter", getRootElement(), function() if (isPedInVehicle(localPlayer) and Cars[getElementModel(getPedOccupiedVehicle(localPlayer))]) then if isWorldSpecialPropertyEnabled("aircars") then setWorldSpecialPropertyEnabled ( "aircars", false ) setWorldSpecialPropertyEnabled ( "hovercars", false ) setAircraftMaxVelocity( 2.3 ) setWorldSoundEnabled ( 11, true, true) setWorldSoundEnabled ( 7, true, true) setWorldSoundEnabled ( 8, true, true) setWorldSoundEnabled ( 9, true, true) setWorldSoundEnabled ( 10, true, true) setWorldSoundEnabled ( 12, true, true) setWorldSoundEnabled ( 13, true, true) setWorldSoundEnabled ( 14, true, true) setWorldSoundEnabled ( 15, true, true) setWorldSoundEnabled ( 16, true, true) setWorldSoundEnabled ( 40, true, true) playSound("ThrusterOff.wav") setSoundVolume(sound, 0.3) if isFlying then removeEventHandler("onClientRender", root, checkFlight) end isFlying = false else setWorldSpecialPropertyEnabled ( "aircars", true ) setWorldSpecialPropertyEnabled ( "hovercars", true ) triggerServerEvent ( "onjetpack", resourceRoot) setWorldSoundEnabled ( 11, false, true) setWorldSoundEnabled ( 7, false, true) setWorldSoundEnabled ( 8, false, true) setWorldSoundEnabled ( 9, false, true) setWorldSoundEnabled ( 10, false, true) setWorldSoundEnabled ( 12, false, true) setWorldSoundEnabled ( 13, false, true) setWorldSoundEnabled ( 14, false, true) setWorldSoundEnabled ( 15, false, true) setWorldSoundEnabled ( 16, false, true) setWorldSoundEnabled ( 40, false, true) playSound("ThrusterOn.wav") setAircraftMaxVelocity( 1) setSoundVolume(sound, 0.9) if not isFlying then addEventHandler("onClientRender", root, checkFlight) end isFlying = true end end end) function checkFlight() if (not isPedInVehicle(localPlayer)) or (not Cars[getElementModel(getPedOccupiedVehicle(localPlayer))]) or isPlayerDead(localPlayer) then setWorldSpecialPropertyEnabled ( "aircars", false ) setWorldSpecialPropertyEnabled ( "hovercars", false ) setAircraftMaxVelocity( 2.3 ) setWorldSoundEnabled ( 11, true, true) setWorldSoundEnabled ( 7, true, true) setWorldSoundEnabled ( 8, true, true) setWorldSoundEnabled ( 9, true, true) setWorldSoundEnabled ( 10, true, true) setWorldSoundEnabled ( 12, true, true) setWorldSoundEnabled ( 13, true, true) setWorldSoundEnabled ( 14, true, true) setWorldSoundEnabled ( 15, true, true) setWorldSoundEnabled ( 16, true, true) setWorldSoundEnabled ( 40, true, true) playSound("ThrusterOff.wav") setAircraftMaxVelocity( 2.3 ) setSoundVolume(sound, 0.3) if isFlying then removeEventHandler("onClientRender", root, checkFlight) end isFlying = false end end local ms = 1000
-
1 hour ago, IIYAMA said:
This code is executed every frame. I can see that you add some validation checks.
But check the execution rate of the following code, if it is too high it will be a much bigger than not playing sounds:
As for the not playing sound, you forgot to index the table:
themes[math.random(#themes )]
:3 Thk you bro, it worked
- 1
-
local themes = { "sounds/RADAR.mp3", "sounds/RADAR2.mp3", "sounds/RADAR3.mp3", } local sound = {} function Ruiner2000theme() local allVehicles = getElementsByType("vehicle") for index, veh in ipairs (allVehicles) do local model = getElementModel(veh) if model == 494 then if getVehicleEngineState(veh) then if isElement(sound[veh]) then triggerServerEvent ( "fullyloaded", resourceRoot) else local x, y, z = getElementPosition(veh) sound[veh] = playSound3D( math.random( 1,#themes ), x, y, z, true) attachElements(sound[veh], veh) setSoundMaxDistance(sound[veh], 1000) end else if isElement(sound[veh]) then destroyElement(sound[veh]) end end end end end addEventHandler("onClientPreRender", root, Ruiner2000theme)
I have tried to make a script that when I get on the Ruiner 2000 it plays songs randomly, it works if I put the song as "RADAR.mp3", but it doesn't work if I put the mathrandom table, I have added the songs correctly in the meta and I don't know why it does not work
-
2 minutes ago, IIYAMA said:
function deluxe ( ) local player = client
addEventHandler doesn't work the same as the addCommandHandler.
Use the predefined variable `client`, to get the player that did activate the event.
Thx man! it has helped me a lot!
- 1
-
I'm very noob at scripting :' (, but i did this: (It's a script for the Imponte Deluxo of GTA Online)
Serverside:
function deluxe ( player ) local vehicle = getPedOccupiedVehicle(player) if isElement(vehicle) then if getVehicleDoorOpenRatio(vehicle,5) > 0 then setVehicleDoorOpenRatio(vehicle,5,0,ms) setVehicleDoorOpenRatio(vehicle,4,0,ms) setVehicleDoorOpenRatio(vehicle,0,0,ms) else setVehicleDoorOpenRatio(vehicle,5,1,ms) setVehicleDoorOpenRatio(vehicle,4,1,ms) setVehicleDoorOpenRatio(vehicle,0,1,ms) end end end addEvent( "deluxo", true ) addEventHandler( "deluxo", resourceRoot, deluxe)
This function puts the Deluxo on flying mode, works fine if i use addCommandHandler instead addEventHandler...
Clientside:
triggerServerEvent ( "deluxo", resourceRoot)
this is the triggerServerEvent that is activated by BindKey (Shift)
but i got at line2 on serverside:
Bad Argument @ ´getPedoccupiedvehicle´ [Expected Ped at Argument 1, got nil]
I need help
-
last week I had a login panel that worked with HTML, the panel had a background video and music, but now it appears on white background and without sound, I tried to put another HTML panel and the same thing happens, both use videos in webm format and sound in ogg format, I do not know exactly what happens D :
-
It worked!! I really appreciate it very much
-
This is the script:
function check ( player, seat, jacked ) if getElementData(source, "privado") then if getElementData(source, "dueño") == getAccountName(getPlayerAccount(player)) then else cancelEvent() outputChatBox("Este vehículo no es tuyo.", player) end end end addEventHandler ( "onVehicleStartEnter", getRootElement(), check ) function adueñar(playerSource, player, cmd, who) local who = getPlayerName(playerSource), playerSource(who) local co = getPedOccupiedVehicle(who) setElementData(co, "privado", true) setElementData(co, "dueño", getPlayerName(who)) outputChatBox("Este auto ahora es de:"..getPlayerName(who), player) end addEventHandler ( "onVehicleEnter", getRootElement(), adueñar )
the script makes that when a player gets into a car it is saved in his account so no other can use it, the script needs to get the player's name, but I think that in a server-type script it is impossible :(, I have tried everything and nothing has worked...
Help :C
the script works when you change "addEventHandler" to "addCommandHandler" but, i want everything to be automatic.
-
Thanks!
-
function check ( player, seat, jacked )
if getElementData(source, "policeman") then
if getElementData(source, "owner") == getAccountName(getPlayerAccount(player)) then
else
cancelEvent()
outputChatBox("You need to be a Policeman", player)
end
end
end
addEventHandler ( "onVehicleStartEnter", getRootElement(), check )function setcop(player, cmd, who)
local who = getPlayerName(playersource), setcop(who)
local co = getPedOccupiedVehicle(who)
setElementData(co, "policeman", true)
setElementData(co, "owner", getPlayerName(who))
outputChatBox("The Policeman:"..getPlayerName(who), player)
endaddEventHandler ( "onVehicleEnter", getRootElement(), setcop )
i made a few changes
-
My script* but i can't change the title
-
I'm trying to make a resource that obtain the name of a player like this line:
local who = getPlayerName(playerSource), playerSource(who)
but i got this
GetPlayerName [expected element at argument 1, got nil]
lua:13: attempt to call global 'playerSource' (a nil value)
I need help :'c
the script is of the type server
-
For a long time he tried to make the players of my server have their own cars and another player can not remove them but I do not know how to do it, I made a resource that affects the doors, but it was not useful and failed in a certain thing,: c Help
-
EspañolInglésItaliano---------------Detectar idiomaAfrikáansAlbanésAlemánAmáricoÁrabeArmenioAzerbaiyanoBengalíBielorrusoBirmanoBosnioBúlgaroCanarésCatalánCebuanoChecoChino (Simplificado)Chino (Tradicional)CingalésCoreanoCorsoCriollo haitianoCroataDanésEslovacoEslovenoEspañolEsperantoEstonioEuskeraFinésFrancésFrisón occidentalGaélico escocésGalésGallegoGeorgianoGriegoGuyaratíHausaHawaianoHebreoHindiHmongHúngaroIgboIndonesioInglésIrlandésIslandésItalianoJaponésJavanésJemerKazajoKirguísKurdoLaoLatínLetónLituanoLuxemburguésMacedonioMalayalamMalayoMalgacheMaltésMaoríMaratíMongolNeerlandésNepalíNoruegoNyanjaPanyabíPastúnPersaPolacoPortuguésRumanoRusoSamoanoSerbioShonaSindhiSomalíSotho meridionalSuajiliSuecoSundanésTagaloTailandésTamilTayikoTeluguTurcoUcranianoUrduUzbekoVietnamitaXhosaYidisYorubaZulúEspañol
Thank you! , I really appreciate it C:
-
I have this:
function Salir()
if isElement(tableVehicles[source]) then
destroyElement(tableVehicles[source])
end
endaddEventHandler("onPlayerVehicleExit",getRootElement(),Salir)
This function destroys the vehicle when the player leaves, I want this to happen after a second and not immediately, i need to use "Set timer", but I do not know how to use it, I tried different ways but none of them
-
this is the script to lock the doors
function lockdoors ( theVehicle, seat )
if ( getElementModel ( theVehicle ) == 601 ) then
if isVehicleLocked ( playervehicle ) then
setVehicleLocked ( v, true )
else
setVehicleLocked ( v, false )
end
addEventHandler ( "onPlayerVehicleEnter", getRootElement(), lockdoors )
[Help] Serverside changing variable?
in Scripting
Posted
it worked , i didn't know the use of local for declaring variables because i alwais did my scripts clientsided, i appreciate it bro, thank you :0