Jump to content

-Bane-

Members
  • Posts

    108
  • Joined

  • Last visited

Posts posted by -Bane-

  1. allora:

    1) calcola quanti sono i giocatori on-line

    2) appena uno muore avvia un ciclo che calcoli quanti giocatori sono ancora vivi (all'inizio 0, poi 1, poi 2) così evitti il problema che avresti con due giocatori che muoiono contemporaneamente.

    3) termina il ciclo quando il numero di giocatori vivi sarà uguale a 0

    4) (non ho ben capito cosa intendi) re-spawna i giocatori e "riavvia" la partita. (Non il server!!!)

  2. In the chat the message reports "nil" instead of the amound of money stolen.

    client:

    -- Player aims at another player or objcet 
    cooldown = {} 
    function targetingActivated ( target ) 
        -- Check so the team is criminals, that the criminal  
        -- is aiming and that the location is interior 
        local theTeam = getPlayerTeam ( localPlayer ) 
        if not isTimer(cooldown[localPlayer] ) and getControlState("aim_weapon") and  
            getElementInterior( localPlayer ) > 0 and isElement( target ) and  
            ( getPlayerTeam( localPlayer ) == getTeamFromName( "Criminals" ) or 
            getPlayerTeam( localPlayer ) == getTeamFromName( "Civilians" ) or 
            getPlayerTeam( localPlayer ) == getTeamFromName( "Gangsters" ) or  
            getPlayerTeam( localPlayer ) == getTeamFromName( "Unemployed" )) then  
            -- Stores may only be robbed every 5 minutes 
            outputChatBox( "You have robbed this store, stay inside until you get the cash!", 255, 0, 0 ) 
            triggerServerEvent( "onRob", localPlayer, target )  
            cooldown[localPlayer] = setTimer(function() end, 200000, 1 ) 
        end 
    end 
    addEventHandler ( "onClientPlayerTarget", getRootElement(), targetingActivated ) 
      
    function showTimeLeft( ) 
        if getElementData( localPlayer, "rob" ) then 
            local endTime = tonumber( getElementData( localPlayer, "robTime" )) 
            local currentTime = tonumber( getElementData( localPlayer, "robTime2" )) 
            local sx, sy = guiGetScreenSize( ) 
            dxDrawText ( "Time left: "..tostring(math.floor((endTime-currentTime)/1000)), sx-300, sy-50, 0, 0,  
                tocolor( 0, 255, 0, 255 ), 1.5, "default-bold" ) 
        end 
    end 
    addEventHandler( "onClientRender", root, showTimeLeft ) 
    

    server:

    ped = { } 
    peds = { 
        --x, y, z, dimension, interior, rotation, skinID 
        [1]={ 161, -81, 1001.8046875, 3, 18, 180, 93 }, 
        [2]={ 161, -81, 1001.8046875, 2, 18, 180, 93 }, 
        [3]={ 161, -81, 1001.8046875, 1, 18, 180, 93 }, 
        [4]={ 161, -81, 1001.8046875, 0, 18, 180, 93 }, 
         
        [5]={ 204.7978515625, -7.896484375, 1001.2109375, 2, 5, 270, 93 }, 
        [6]={ 204.7978515625, -7.896484375, 1001.2109375, 1, 5, 270, 93 }, 
        [7]={ 204.7978515625, -7.896484375, 1001.2109375, 0, 5, 270, 93 }, 
         
        [8]={ 203.4, -41.7, 1001.8046875, 2, 1, 180, 93 }, 
        [9]={ 203.4, -41.7, 1001.8046875, 1, 1, 180, 93 }, 
        [10]={ 203.4, -41.7, 1001.8046875, 0, 1, 180, 93 }, 
         
        [11]={ 204.2080078125, -157.8193359375, 1000.5234375, 0, 14, 180, 93 }, 
         
        [12]={ 206.3759765625, -127.5380859375, 1003.5078125, 1, 3, 180, 93 }, 
        [13]={ 206.3759765625, -127.5380859375, 1003.5078125, 0, 3, 180, 93 }, 
         
        [14]={ 206.3349609375, -98.703125, 1005.2578125, 3, 15, 180, 93 }, 
        [15]={ 206.3349609375, -98.703125, 1005.2578125, 2, 15, 180, 93 }, 
        [16]={ 206.3349609375, -98.703125, 1005.2578125, 1, 15, 180, 93 }, 
        [17]={ 206.3349609375, -98.703125, 1005.2578125, 0, 15, 180, 93 }, 
    } 
      
    cancelTimers = {} 
    function loadPeds() 
        for k=1, #peds do 
            -- Create the ped 
            ped[k] = createPed ( peds[k][7], peds[k][1], peds[k][2], peds[k][3] ) 
            setElementDimension( ped[k], peds[k][4] ) 
            setElementInterior( ped[k], peds[k][5] ) 
            setPedRotation ( ped[k], peds[k][6] ) 
            setTimer( setElementHealth, 100, 0, ped[k], 100 ) 
        end 
    end 
    addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), loadPeds) 
      
    -- Robbery time 
    function CounterTime( crim ) 
        if isElement( crim ) then 
            local time = getTickCount( ) 
            setElementData( crim, "robTime2", time ) 
        end 
    end 
      
    -- Define law  
    lawTeams = { 
        [getTeamFromName("Police")] = true,  
        [getTeamFromName("SAPD")] = true,  
        [getTeamFromName("SWAT")] = true,  
        [getTeamFromName("FBI")] = true,  
        [getTeamFromName("Army")] = true,  
        [getTeamFromName("Emergency service")] = true  
    } 
    -- Antispam timer 
    robTimer = { } 
      
    -- Do the rob 
    function robStore( target ) 
        if getElementType( target ) == "ped" and not isTimer(robTimer[target]) then 
            -- Robbery in progress 
            setElementData( client, "rob", true ) 
            local money = math.random( 500, 30000 ) 
            local robtime = math.random(120000, 240000) 
             
            -- Allow count down timer 
            setElementData( client, "robTime", robtime+getTickCount( )) 
            setElementData( client, "robTime2", getTickCount( )) 
            setTimer( CounterTime, 1000, (math.floor(robtime)/1000), client ) 
             
            -- When the robbery is finished 
            setTimer( payForRob, robtime, 1, client, money ) 
            setTimer( robStatus, robtime, 1, client, target ) 
            cancelTimers[client] = setTimer( cancelRob, (math.floor(robtime)/100), 100, client, target ) 
             
            -- Set the wanted level 
            if getPlayerWantedLevel( client ) <= 3 then 
                setPlayerWantedLevel( client, getPlayerWantedLevel( client ) + 3 ) 
            else 
                setPlayerWantedLevel( client, 6 ) 
            end 
            setPedAnimation( target, "shop", "shp_rob_givecash", -1, false ) 
            outputChatBox( "You committed the crime of robbery ("..round(money*0.0001,2).." stars)", client, 255, 255, 0 ) 
             
            -- Send alarm call to all the cops 
            local cops = getElementsByType( "player" )  
            for theKey,cop in ipairs(cops) do  
                if lawTeams[getPlayerTeam(cop)] then 
                    cx,cy,cz = getElementPosition( client ) 
                    outputChatBox( "#0000BB(911): #EEEEEERobbery in progress at: "..getZoneName( cx, cy, cz ), cop, 255, 255, 255, true ) 
                    outputChatBox( "Robbery in progress at: "..getZoneName( cx, cy, cz ), cop, 255, 0, 0 ) 
                end 
            end 
             
            -- Set Timer 
            robTimer[target] = setTimer(function() end, 10800000, 1 ) 
        elseif isTimer(robTimer[target]) then 
            outputChatBox( "Get the hell out of here, this store was just robbed!", client, 255, 0, 0 ) 
        end 
    end 
    addEvent( "onRob", true ) 
    addEventHandler( "onRob", root, robStore ) 
      
    function payForRob( crim, amount ) 
        if isElement( crim ) then 
            if getElementData( crim, "rob" ) then  
                givePlayerMoney( crim, amount )  
                outputChatBox( "Robbery sucsessfull, you earned: "..tostring(money), crim, 0, 150, 0 )  
            end  
        end 
    end 
      
    function robStatus( crim, target, money )  
        if isElement( crim ) then 
            if getElementData( crim, "rob" ) then  
                outputChatBox( "Rob successfully, now escape before the cops arrive!", crim, 0, 255, 0 )             
            end 
            setPedAnimation( target, nil, nil ) 
            setElementData( crim, "rob", false ) 
        end  
    end 
      
    -- Check if the rob should be interrupted 
    function cancelRob( crim, target ) 
        if isElement( crim ) then 
            if getElementInterior( crim ) == 0 or getElementData( crim, "arrested" ) or getElementData( crim, "Jailed" ) == "Yes" then 
                setElementData( crim, "rob", false ) 
                outputChatBox( "Robbery failed because you left the store!", crim, 255, 0, 0) 
                setPedAnimation( target, nil, nil ) 
                if isTimer( cancelTimers[crim] ) then 
                    killTimer( cancelTimers[crim] ) 
                end 
            end 
        end 
    end 
      
    -- Round float values 
    function round(number, digits) 
        local mult = 10^(digits or 0) 
        return math.floor(number * mult + 0.5) / mult 
    end 
    

×
×
  • Create New...