Jump to content

Emanuel

Members
  • Posts

    18
  • Joined

  • Last visited

Posts posted by Emanuel

  1. I will try to explain my idea using a scheme.

    1. A person commits a crime that gives a wanted level of 5.
    2. Start timer to decrease his wanted level to 0.
    3. If there is a timer, destroy it, and start a new one. (Here is the problem. Since it is creating multiple ones, the wanted level goes to zero quickly because each timer is decreasing it.)
    4. In each time step, wanted level = wanted level - 1
    5. When the wanted level becomes 0, destroy the timer.
  2. Good day! This is my code where the objective is to set the player wanted level. After increasing the wanted level, I want to create a timer in order to start decreasing it. The problem is that in my code, at each wanted level increase, it creates a timer, which is pretty annoying. The thing is, how can I check if there is a timer and destroy it, before starting the new one? I thought I did that, but the code is not working!

    function setWantedLevel(player)
    	local wantedLevel = getElementData(player,"wantedLevel")
    
    	if wantedLevel == 10 then
    		setElementData(player,"wantedLevel",10,true)
    		exports.SASCnotifications:drawNotification("#FF0000[Wanted Level System]#FFFFFF Wanted level is "..wantedLevel..".",localPlayer)
    	else
    		setElementData(player,"wantedLevel",wantedLevel+1,true)
    		exports.SASCnotifications:drawNotification("#FF0000[Wanted Level System]#FFFFFF Wanted level increased to "..(wantedLevel+1)..".",localPlayer)
    		if getElementData(player,"wantedLevel") == 3 then
    			triggerServerEvent("setCriminalJob",player,player)
    		end
    	end
    	
    	timer = nil 
    	timer = setTimer(function(myTimer)
    		if isTimer(myTimer) then killTimer(myTimer) timer=nil end
    		local wantedLevel = getElementData(player,"wantedLevel")
    		if wantedLevel == 0 then
    			killTimer(myTimer)
    		elseif wantedLevel ~= 0 then
    			setElementData(player,"wantedLevel",wantedLevel-1,true)
    			exports.SASCnotifications:drawNotification("#FF0000[Wanted Level System]#FFFFFF Wanted level decreased to "..(wantedLevel-1)..".",player)
    		end
    	end,5000,0,timer)
    end

     

     

  3. Ora muito obrigado pela resposta esclarecedora que estava à espera !!!

    Só tenho mais uma questão. Será que me poderia explicar a linha 65 e 66 do seu código ? É só para perceber mais profundamente essas condições.

    Muito agradecido,

    Emanuel

  4. Está aqui o link, que eu pedi ajuda, mas parece que ninguém quer ajudar, por isso venho aqui pedir a vossa ! Também quero pedir que alguém me esclareça qual a diferença entre resourceRoot, root,getElementRoot() e essas coisas, pois estou muito confuso, e penso que o problema neste script, é por causa disso.

    EDIT : Já tentei passar o script todo para client side.

    https://forum.multitheftauto.com/viewtopic.php?f=91&t=90395

    Ficaria muito agradecido com uma resposta esclarecedora :)

    Emanuel Camacho

  5. Hello ! I need you help in this script. First of all, I am not a good scripter, that's why I am asking you why this is not working properly. When two players are playing, one can steal bus stops from other. Also, when one leaves his bus, the other one will not see the markers. Can you help me, and explain everything as I was the dumbest person in the world ?

    -----------------------------------------------<< 
    -- MTA : Multi Theft Auto : Emanuel's Server 
    -- Date: 21 July 2015 
    -- Resource: [MTA][Jobs]/[MTA]BusDriver/server.lua 
    -- Type: Server Side 
    -- Author: Emanuel Camacho 
    -----------------------------------------------<< 
    local busses = {[431] = true, [437] = true} 
    local rootElement = getRootElement() 
      
    local markers = { 
    [1] = {-1798.63940, 83.94303, 15.10938}, 
    [2] = {-1800.16284, 102.19742, 15.10938}, 
    [3] = {-1800.60095, 126.91389, 15.10938}, 
    } 
      
    function getNewBusLocation( thePlayer, ID ) 
        local x, y, z = markers[ID][1], markers[ID][2], markers[ID][3] 
        triggerClientEvent(thePlayer,"setNextBusStopPosition",thePlayer,x,y,z) 
    end 
      
    function onVehicleEnter(client) 
        if not busses[getElementModel(source)] then return end 
        if not getPlayerTeam(client) then return end 
        if getTeamName(getPlayerTeam(client)) == "Bus Driver" then 
            local x, y, z = getNewBusLocation(client, 1) 
            setElementData(client,"busData",1) 
        end 
    end 
    addEventHandler("onVehicleEnter",rootElement,onVehicleEnter) 
      
    addEvent("updateBusStop",true) 
    addEventHandler("updateBusStop",rootElement, 
    function (client) 
        if not isPedInVehicle(client) then return end 
        if not busses[getElementModel(getPedOccupiedVehicle(client))] then return end 
        givePlayerMoney(client, 100) 
        if #markers == tonumber(getElementData(client,"busData")) then 
            setElementData(client,"busData",1) 
        else 
            setElementData(client,"busData",tonumber(getElementData(client,"busData"))+1) 
        end 
        getNewBusLocation(client, tonumber(getElementData(client,"busData"))) 
    end) 
    

    -----------------------------------------------<< 
    -- MTA : Multi Theft Auto : Emanuel's Server 
    -- Date: 21 July 2015 
    -- Resource: [MTA][Jobs]/[MTA]BusDriver/client.lua 
    -- Type: Client Side 
    -- Author: Emanuel Camacho 
    -----------------------------------------------<< 
    local client = getLocalPlayer( ) 
    local rootElement = getRootElement() 
    local marker = nil 
    local blip = nil 
      
    function createNextStop ( x, y, z ) 
        marker = createMarker(tostring(x), tostring(y), tostring(z)-1, "cylinder", 3.5, 255, 255, 0, 170) 
        blip = createBlipAttachedTo( marker, 0, 2, 255, 255, 0, 255 ) 
        addEventHandler("onClientMarkerHit",marker,onBusStopHit) 
    end 
      
    addEvent("setNextBusStopPosition",true) 
    addEventHandler("setNextBusStopPosition", rootElement, createNextStop ) 
      
    function onBusStopHit( hitPlayer ) 
        if not hitPlayer == localPlayer then return end 
        triggerServerEvent("updateBusStop",localPlayer,localPlayer) 
        if isElement(blip) then destroyElement(blip) end 
        if isElement(marker) then 
            removeEventHandler("onClientMarkerHit",marker,onBusStopHit) 
            destroyElement(marker)  
        end 
    end 
      
    function leavingVehicle() 
        if isElement(marker) then 
            removeEventHandler("onClientMarkerHit",marker,onBusStopHit) 
            destroyElement(marker)  
        end 
        if isElement(blip) then destroyElement(blip) end 
    end 
    addEventHandler("onClientVehicleExit",rootElement, leavingVehicle ) 
    

  6. you can create weapon with same command but problem if player joined server after create weapon will don't see him
    -->  Client 
    local weapons = { } 
      
    function turret(thePlayer) 
        if not (weapon[thePlayer]) then 
            local x, y, z = getElementPosition(thePlayer) 
            weapon[thePlayer] = createWeapon("m4", x, y, z) 
            setWeaponState(weapon[thePlayer],"firing") 
            attachElements(weapon[thePlayer], thePlayer, 0, 0, 1.5) 
        else 
            destroyElement (weapon[thePlayer]) 
            weapon[thePlayer] = nil 
        end 
    end 
    addEvent("turret", true) 
    addEventHandler("turret", root, turret) 
      
    -->  Server 
    function turret(thePlayer) 
            triggerClientEvent(root, "turret", thePlayer) 
    end 
    addCommandHandler("turret", turret) 
    

    This isn't working :/

    Use a loop to get the all the players to fire at, then add a check to see if the player isn't yourself and I think you'll be fine.

    You're using getLocalPlayer(), which gets the player who triggered the function, so yea, it's obviously gonna shoot at you :P

    Do you even know how noob I am in this ? lol .I really need help in this xD

    PS : Someone said that I could use triggerServerEvent("eventName", root, theResultOfFunction)

    Any suggestion ?

    NOTE : It is something like this. It is set on a determinated position, not attacked to a player, or a car.

    MUWskNm.jpg?1

  7. you can create weapon with same command but problem if player joined server after create weapon will don't see him
    -->  Client 
    local weapons = { } 
      
    function turret(thePlayer) 
        if not (weapon[thePlayer]) then 
            local x, y, z = getElementPosition(thePlayer) 
            weapon[thePlayer] = createWeapon("m4", x, y, z) 
            setWeaponState(weapon[thePlayer],"firing") 
            attachElements(weapon[thePlayer], thePlayer, 0, 0, 1.5) 
        else 
            destroyElement (weapon[thePlayer]) 
            weapon[thePlayer] = nil 
        end 
    end 
    addEvent("turret", true) 
    addEventHandler("turret", root, turret) 
      
    -->  Server 
    function turret(thePlayer) 
            triggerClientEvent(root, "turret", thePlayer) 
    end 
    addCommandHandler("turret", turret) 
    

    This isn't working :/

    Use a loop to get the all the players to fire at, then add a check to see if the player isn't yourself and I think you'll be fine.

    You're using getLocalPlayer(), which gets the player who triggered the function, so yea, it's obviously gonna shoot at you :P

    Do you even know how noob I am in this ? lol .I really need help in this xD

    PS : Someone said that I could use triggerServerEvent("eventName", root, theResultOfFunction)

    Any suggestion ?

  8. First of all, I am a beginner in this gigantic world, and sorry for my ignorance.

    I have some bugs, that I want to be solved.

    Bugs:

    - The project is not synchronized. Each player gets attacked by his own turret, and not from the one I have created.

    - When I use the command /turret it creates one on me, and other players have one on their head. For example, if anyone uses /turret, I will have a turret on me, which doesn't make sence.

    Here is the project :

    Client :

    function turret() 
        x, y, z = getElementPosition(getLocalPlayer()) 
        weapon = createWeapon("m4", x, y, z+1.5) 
        setWeaponClipAmmo ( weapon,99999) 
        setWeaponState ( weapon,"firing") 
            setWeaponTarget ( weapon, true ) 
            setWeaponTarget ( weapon ,getLocalPlayer(), 255 )       
    end 
    addEvent("turret", true) 
    addEventHandler("turret", root, turret) 
      
    function destroy() 
            destroyElement (weapon) 
    end 
    addEvent("destroy", true) 
    addEventHandler("destroy", root, destroy) 
    

    Server :

    function turret() 
            triggerClientEvent(root, "turret", root, x, y, z) 
    end 
    addCommandHandler("turret", turret) 
      
    function destroy() 
            triggerClientEvent(root, "destroy", root, x, y, z) 
    end 
    addCommandHandler("end", destroy) 
    

    Meta :

    <meta> 
        <script src="client.lua" type="client" /> 
        <script src="server.lua" type="server" /> 
        <min_mta_version client="1.3.0-9.04555"></min_mta_version> 
    </meta> 
      
    

    I would appreciate if you could fix it. thanks.

  9. Hello, I have a question. Is possible to make admins the only ones who can use the map editor in their server. For example, if an admin starts the mapeditor resources, the other players can continue playing, and he is the only only editing ? If its not possible, can you give me a simple map editor, since I can't find any ...

    Thanks in advance !

  10. a51_labglass this is it,. What to do with it ?

    EDIT : Ok, the problem is resolved.

    The code was :

    <removeWorldObject id="removeWorldObject (object) (1)" radius="100" interior="0" model="16655" lodModel="0" posX="280.3281" posY="1874.234" posZ="7.75" rotX="0" rotY="0" rotZ="0"></removeWorldObject> 
    

  11. I have a doubt.

    I was making a map, in the area 51, and I decided to delete the lab glasses (on the underground part). The problem is that it can't be selected, and I can't erase it. Any suggestions ?

    As I know, that this is the code to delete an object ...

    <removeWorldObject id="removeWorldObject (a51_sdsk_3_) (1)" radius="4.282804" interior="0" model="3395" lodModel="0" posX="280.3281" posY="1874.234" posZ="7.75" rotX="0" rotY="0" rotZ="0"></removeWorldObject> 
    

    I tryed to use this one :

    <removeWorldObject id="removeWorldObject (a51_labglass) (1)" </removeWorldObject> 
    

    But it didn't work.

  12. Olá !

    É o seguinte, eu quero eliminar um objecto que se encontra na área 51, que são os vidros dos laboratórios, mas no entanto, não os consigo apagar, por não consegui seleccioná-los. Existe alguma maneira de os eliminar ?

    Nota : Sei que isto é o código para eliminar um objecto :

    <removeWorldObject id="removeWorldObject (a51_sdsk_3_) (1)" radius="4.282804" interior="0" model="3395" lodModel="0" posX="280.3281" posY="1874.234" posZ="7.75" rotX="0" rotY="0" rotZ="0"></removeWorldObject> 
    

    Por isso, tentei utilizar este :

    <removeWorldObject id="removeWorldObject (a51_labglass) (1)" </removeWorldObject> 
    

    No entanto, não funcionou.

    Espero por uma resposta,

    Obrigado,

    Emanuel

×
×
  • Create New...