Jump to content

Hunter reach script!


Zin

Recommended Posts

Hey i need help with my script.

Im trying to make it so when the last player reaches the hunter on DM the map ends but this is confusing? im new to scripting but maybe you guys can help like in my other posts. I have learned more from asking people then looking on the wiki.

Here is my script

    function getActivePlayers() 
        return g_CurrentRaceMode.activePlayerList 
    end 
    function isDM() 
    end 
        for i,v in ipairs(getElementsByType'racepickup') do 
            if getElementData(v,'vehicle') == '425' then 
            end 
               end 
            if getActivePlayerCount() <= 1 then 
                RaceMode.endMap() 
                return true 
                  end 

Im getting this error code : "attempt to call global "getactiveplayercount" (a nil value)

Link to comment

Hi,

First, the function that you're trying to call seems to be undefined. You want to get the number of active players, I see also that you have a function getActivePlayers who returns an array of the active players. If you want to get the number of active players you can do like this:

if(#getActivePlayers() <=  1)then 

Second, If I understood right you want to end the map when the last player reach the Hunter. If you read the Wiki, you will see that the race gamemode gives you some usefull events like this one:

onPlayerPickUpRacePickup     
int/string pickupID, string pickupType, int vehicleModel 

(source: http://wiki.multitheftauto.com/index.ph ... ource:Race)

That events actives himself when a player pick up a racepickup like nitro, vehiclechange or repair.

So, for your script, what you need to do is: when we have 1 active player, we add the event using addEventHandler per example. If the event is activated, we check if the pickup is the hunter pickup like this: if pickupType == "vehiclechange" and vehicleModel == "HUNTERID" then

If this is right, then you can call the function RaceMode.endMap() to end the map.

Hope that helps you.

Regards.

Link to comment
  
addEvent ( "onPlayerPickUpRacePickup", true ) 
addEventHandler ( "onPlayerPickUpRacePickup", getRootElement(), 
function ( id, type, model ) 
  if type == "vehiclechange" and tonumber(id) == 425 then 
    -- your message 
    outputChatBox ( "The hunter has been reached!" ) 
    -- if you want the player's name use 'getPlayerName ( source )' as the source is the player who picked that pickup up 
  end 
end ) 
  

Link to comment
  • 2 weeks later...

Hey i tried that but when last player gets hunter nothing happens no errors nothing.

script

        function getActivePlayers() 
            return g_CurrentRaceMode.activePlayerList 
        end 
        function isDM() 
        end 
                  
    addEvent ( "onPlayerPickUpRacePickup", true ) 
    addEventHandler ( "onPlayerPickUpRacePickup", getRootElement(), 
    function ( id, type, model ) 
      if type == "vehiclechange" and tonumber(id) == 425 then 
      end 
    end ) 
      
                end 
                   end 
                if(#getActivePlayers() <=  1)then 
                    RaceMode.endMap() 
                    return true 
                      end 

Link to comment

Still not working

        function getActivePlayers() 
            return g_CurrentRaceMode.activePlayerList 
        end 
        function isDM() 
        end 
                  
    addEvent ( "onPlayerPickUpRacePickup", true ) 
    addEventHandler ( "onPlayerPickUpRacePickup", getRootElement(), 
    function ( id, type, model ) 
      if type == "vehiclechange" and tonumber(id) == 425 then 
      if(#getActivePlayers() <=  1)then 
                    RaceMode.endMap() 
                    return true 
                      end 
      end 
    end ) 
  

Link to comment
Still not working

        function getActivePlayers() 
            return g_CurrentRaceMode.activePlayerList 
        end 
        function isDM() 
        end 
                  
    addEvent ( "onPlayerPickUpRacePickup", true ) 
    addEventHandler ( "onPlayerPickUpRacePickup", getRootElement(), 
    function ( id, type, model ) 
      if type == "vehiclechange" and tonumber(id) == 425 then 
      if(#getActivePlayers() <=  1)then 
                    RaceMode.endMap() 
                    return true 
                      end 
      end 
    end ) 
  

where did u put this code?

u have to put it in your race gamemode

race\modes\destructionderby.lua

Link to comment

I put it in my destructionderby.lua and now the map does not change when the last player dies and when last player gets the hunter it says "attempt to call getactiveplayers (a nil value)

this is my destructionderby.lua

    DestructionDerby = setmetatable({}, RaceMode) 
    DestructionDerby.__index = DestructionDerby 
    DestructionDerby:register('Destruction derby') 
    function DestructionDerby:isApplicable() 
        return not RaceMode.checkpointsExist() and RaceMode.getMapOption('respawn') == 'none' 
    end 
    function DestructionDerby:getPlayerRank(player) 
        return #getActivePlayers() 
    end 
    -- Copy of old updateRank 
    function DestructionDerby:updateRanks() 
        for i,player in ipairs(g_Players) do 
            if not isPlayerFinished(player) then 
                local rank = self:getPlayerRank(player) 
                if not rank or rank > 0 then 
                    setElementData(player, 'race rank', rank) 
                end 
            end 
        end 
        -- Make text look good at the start 
        if not self.running then 
            for i,player in ipairs(g_Players) do 
                setElementData(player, 'race rank', '' ) 
                setElementData(player, 'checkpoint', '' ) 
            end 
        end 
    end 
    function DestructionDerby:onPlayerWasted(player) 
        if isActivePlayer(player) then 
            self:handleFinishActivePlayer(player) 
            if getActivePlayerCount() <= 0 then 
                RaceMode.endMap() 
            else 
                TimerManager.createTimerFor("map",player):setTimer(clientCall, 2000, 1, player, 'Spectate.start', 'auto') 
            end 
        end 
        RaceMode.setPlayerIsFinished(player) 
        showBlipsAttachedTo(player, false) 
    end 
    function hunterAlert(mapInfo, pickupID, pickupType, vehicleModel) 
        if pickupType == "vehiclechange" then 
            if vehicleModel == 425 then 
                if getActivePlayerCount() <= 1 then 
                    RaceMode.endMap() 
                end 
            end 
        end 
    end 
    addEventHandler("onPlayerPickUpRacePickup",getRootElement(),hunterAlert) 
    function DestructionDerby:onPlayerQuit(player) 
        if isActivePlayer(player) then 
            self:handleFinishActivePlayer(player) 
            if getActivePlayerCount() <= 1 then 
                RaceMode.endMap() 
            end 
        end 
    end 
          
    function DestructionDerby:handleFinishActivePlayer(player) 
        -- Update ranking board for player being removed 
        if not self.rankingBoard then 
            self.rankingBoard = RankingBoard:create() 
            self.rankingBoard:setDirection( 'up', getActivePlayerCount() ) 
        end 
        local timePassed = self:getTimePassed() 
        self.rankingBoard:add(player, timePassed) 
        -- Do remove 
        finishActivePlayer(player) 
        -- Update ranking board if one player left 
        local activePlayers = getActivePlayers() 
        local resource = exports["mapmanager"]:getRunningGamemodeMap( )  
        local mapName = getResourceInfo ( resource, "name" ) 
        if string.find ( mapName, "[DM]" ) then  
        if #activePlayers == 1 then 
            self.rankingBoard:add(activePlayers[1], timePassed) 
            showMessage(getPlayerName(activePlayers[1]) .. ' won the map!', 255, 0, 0) 
            RaceMode.endMap() 
        end 
        elseif string.find ( mapName, "[DD]" ) then  
           if #alivePlayers == 1 then 
               if getElementModel (getPedOccupiedVehicle ( alivePlayers[1] )) == 425 then 
            self.rankingBoard:add(activePlayers[1], timePassed) 
            showMessage(getPlayerName(activePlayers[1]) .. ' won the map!', 255, 0, 0) 
            RaceMode.endMap() 
             end 
          end 
        end 
    end 
      
    ------------------------------------------------------------ 
    -- activePlayerList stuff 
    -- 
    function isActivePlayer( player ) 
        return table.find( g_CurrentRaceMode.activePlayerList, player ) 
    end 
    function addActivePlayer( player ) 
        table.insertUnique( g_CurrentRaceMode.activePlayerList, player ) 
    end 
    function removeActivePlayer( player ) 
        table.removevalue( g_CurrentRaceMode.activePlayerList, player ) 
    end 
    function finishActivePlayer( player ) 
        table.removevalue( g_CurrentRaceMode.activePlayerList, player ) 
        table.insertUnique( g_CurrentRaceMode.finishedPlayerList, _getPlayerName(player) ) 
    end 
    function getFinishedPlayerCount() 
        return #g_CurrentRaceMode.finishedPlayerList 
    end 
    function getActivePlayerCount() 
        return #g_CurrentRaceMode.activePlayerList 
    end 
    function isDM() 
        end             
    addEvent ( "onPlayerPickUpRacePickup", true ) 
    addEventHandler ( "onPlayerPickUpRacePickup", getRootElement(), 
    function ( id, type, model ) 
      if type == "vehiclechange" and tonumber(id) == 425 then 
      if(#getActivePlayers() <=  1)then 
                    RaceMode.endMap() 
                    return true 
                      end 
      end 
    end ) 
     

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...