Jump to content

[HELP] Quick Race Query


deltamta

Recommended Posts

Hello there,

I'm making a MySQL stats system that you can buy / unbuy maps from.

I already made the buying maps function and it works : ( executeCommandHandler("nextmapcommand", thePlayer, MapName ) ) and i wanna make the unbuying map and im not so sure how I could do that... i tried many things but they dont seem to work : ex. ( unbuy = executeCommandHandler( "nextmapcommand", thePlayer, nil ) ) Doesn't work though... Still keeps the same map as next map. Could you please tell me how could I make it unbuy the map that was bought? That would be great if you could :) Thanks in advance. *Delta^#

Link to comment
addCommandHandler ( "bm",  
    function( thePlayer, command, ... ) 
        local mapName = #{...}>0 and table.concat({...},' ') or nil 
            if mapbought == false then 
                local cash = tonumber( getElementData( thePlayer, "Cash" ) ) 
                if cash >= mapcost then 
                    buymap = executeCommandHandler("asdasdfavaginabomb", thePlayer, mapName ) 
                    if ( buymap ) then 
                        setElementData ( thePlayer, "Cash", cash-mapcost ) 
                        mapbought = thePlayer 
                    end 
                else 
                    outputChatBox("#ff8900[iNFO] #ffffffYou don't have enough money to set a map.", thePlayer, 255, 255, 255, true ) 
                end 
            else 
                outputChatBox("#ff8900[iNFO] #ffffffA map has been already set. Please try again later.", thePlayer, 255, 255, 255,true ) 
            end 
        end 
) 
  
  
  
  
  
addCommandHandler ( "ubm",  
    function ( thePlayer ) 
        if mapbought ~= false then 
            if mapbought == thePlayer then 
                unbuy = executeCommandHandler( "asdasdfavaginabomb", thePlayer, nil ) 
                if ( unbuy ) then 
                    local cash = tonumber( getElementData( thePlayer, "Cash" ) ) 
                    outputChatBox("#ff8900[iNFO] #ffffff"..getPlayerName( thePlayer ).. " #ffffffhas unbought next map",getRootElement(),255,255,255,true) 
                    mapbought = false 
                    setElementData ( thePlayer, "Cash", cash+mapcost ) 
                end 
            end 
        end 
    end 
) 

This is the stats system part and bellow is the racevoting_server.lua or whatever part :

addCommandHandler('asdasdfavaginabomb', 
    function( player, command, ... )  
        local query = #{...}>0 and table.concat({...},' ') or nil 
        if not query then 
            if g_ForcedNextMap then 
                outputRace( 'Next map is ' .. getMapName( g_ForcedNextMap ), player ) 
            else 
                outputRace( 'Next map is not set', player ) 
            end 
            return 
        end 
        local map, errormsg = findMap( query ) 
        if not map then 
            outputRace( errormsg, player ) 
            return 
        end 
        if g_ForcedNextMap == map then 
            outputRace( 'Next map is already set to ' .. getMapName( g_ForcedNextMap ), player ) 
            return 
        end 
        g_ForcedNextMap = map 
        outputChatBox( "#ff8900[iNFO] #ffffff"..getPlayerName( player ).." #ffffffhas bought next map.", getRootElement(), 255, 255, 255, true) 
        outputChatBox( "#ff8900[iNFO] #ffffffNext map : #ff8900 "..getMapName( g_ForcedNextMap ), getRootElement(), 255, 255, 255, true ) 
    end 
) 
  

Link to comment
Guest Guest4401

That's not how you unbuy a map. To clear the nextmap, g_ForcedNextMap (a variable in racevoting_server.lua) has to be nil or false.

For e.g: (This won't work because "bm" command is not in the same resource and mapbought would be nothing. I suggest you using setElementData to the player and checking if he was the person who bought the next map or not. And replace line 4 in this code later on.

Alternatively, you can move the /bm command in the same resource - race, to continue with mapbought variable rather than element data)

addCommandHandler("ubm", 
    function(p) 
        if g_ForcedNextMap then 
            if p == mapbought then 
                g_ForcedNextMap = nil 
                outputChatBox(getPlayerName(p).." has unbought the next map") 
                -- return him the cash here 
            else 
                outputChatBox("You did not buy the next map.",p) 
            end 
        else 
            outputChatBox("Next map isn't set.",p) 
        end 
    end 
) 

Link to comment
Guest Guest4401
ehm is there a way to use /ubm and to replace the map you bought with a random map? So basically like buy a random map?

If you want to set a random map, you can make a simple function out of these:

exports.mapmanager:getMapsCompatibleWithGamemode ( getResourceFromName'race' ) 
math.random 

What I'm trying to say is - Get a list of maps in a table and pick a random map out of it.

And assign the map to g_ForcedNextMap variable.

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...