Jump to content

[HELP] NextMap


SuleymanM

Recommended Posts

Hi all,

i want to create an resource:

- Buy Next Map with command

why this client.LUA not function command:

HOW SOLVE?

I want help please

local price = 5000; 
  
addCommandHadler (`buymap`, BuyNextMap) 
addEventHandler ( 'onGamemodeMapStart', root, 
    function ( mapres ) 
        local txMapName = getResourceName ( mapres ); 
        pHasBought = false; 
        allGotVehicle = false; 
        getAliveGuys ( 3 ); 
        saveSqlPlayed ( txMapName ); 
    end 
) 
  
function rStart ( ) 
    pHasBought = false; 
    allGotVehicle = false; 
    executeSQLQuery ( "CREATE TABLE IF NOT EXISTS tx_MapShop ( mapName TEXT, played INTEGER )" ); 
    getAllMapsFromManager ( ); 
    txBMaps = { } 
end 
addEventHandler ( "onResourceStart", getResourceRootElement ( getThisResource ( ) ), rStart ) 
  
function buyNextMap ( player, mapName ) 
    if not player or not mapName then return end 
    if ( isGuestAccount ( getPlayerAccount ( player ) ) == false ) then 
        if pHasBought == false then 
            local money = tonumber ( getPlayerMoney ( player ) ); 
            local theTime = getMsFromMin ( 10 ); 
            if money >= tonumber ( price ) then 
                if ( not txBMaps [ mapName ] ) then 
                    txBMaps [ mapName ] = true 
                    executeCommandHandler ( "bm", player, mapName ); --This function need admin rights 
                    pHasBought = player; 
                    setTimer ( removeMapFromList, theTime.ms, 1, mapName ); 
                else 
                    outputChatBox ( "* #ff0000'#ffffff" .. mapName .. "#ff0000' #ffffffwill be #abcdefavailable #ffffffin #abcdef10 #ffffffminutes", player, 255, 255, 255, true ); 
                end 
            else 
                outputChatBox ( "* You #abcdefdon't #ffffffhave enough #abcdefmoney #ffffffto buy the map!", player, 255, 255, 255, true ); 
            end 
        else 
            outputChatBox ( "* A #abcdefmap #ffffffis already bought at the moment! Please #abcdeftry #ffffffagain later", player, 255, 255, 255, true ); 
        end 
    else 
        outputChatBox ( "* You should be #abcdeflogged in to buy the map!", player, 255, 255, 255, true ); 
    end 
end 
addEvent ( "doBuyMap", true ) 
addEventHandler ( "doBuyMap", root, buyNextMap ) 
  
function removeMapFromList ( mapName ) 
    outputChatBox ( "* #abcdef" .. mapName .. " #ffffff - #ffffffis now #abcdefavailable #ffffffat the #abcdefMap Shop!", root, 255, 255, 255, true ); 
    txBMaps [ mapName ] = nil; 
end 
  
addEvent ( "onRaceStateChanging", true ) 
addEventHandler ( "onRaceStateChanging", root, 
    function ( newState ) 
        if  ( newState == "Running" ) then 
            for k,v in pairs ( getElementsByType ( "player" ) ) do 
                local hisVehicle = getPedOccupiedVehicle ( v ); 
                if not hisVehicle then return end 
                setElementData (v, "gotMoney", false ); 
                if isPedInVehicle ( v ) then 
                    allGotVehicle = true; 
                end 
            end 
            if allGotVehicle then 
                getAliveGuys ( 1 ); 
            end 
        end 
    end 
) 

Edited by Guest
Link to comment

this no function

addCommandHandler ( 'bm', 
    function ( player, command, ... ) 
        local query = #{...} > 0 and table.concat ( {...}, ' ' ) or nil 
        if not query then 
            if g_ForcedNextMap then 
                outputDebugString ( 'Next map is ' .. getMapName ( g_ForcedNextMap ) ); 
            else 
                outputDebugString ( 'Next map is not set' ); 
            end 
            return 
        end 
        local map, errormsg = findMap ( query ); 
        if not map then 
            outputRace ( errormsg, player ); 
            return 
        end 
        local account = getPlayerAccount ( player ); 
        if ( isGuestAccount ( account ) == false ) then 
            g_ForcedNextMap = map; 
            outputChatBox ( '* ' .. getPlayerName ( player ) .. ' #ffffffhas bought as next map - #ABCDEF' .. getMapName ( g_ForcedNextMap ), g_Root, 0, 240, 0, true ); 
            takePlayerMoney ( player, 500 ); 
            if account then 
                setAccountData ( account, "money", tostring ( getPlayerMoney ( player ) ) ); 
            end 
        else 
            outputChatBox ( '* Please #abcdefLogin #ffffffor #abcdefRegister!', player, 255, 255, 255, true ); 
        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...