Jump to content

Map Shop error Help please?


denny199

Recommended Posts

Hi there I've got some problems with my map shop it works perfectly If I'm admin But Not When i'm not Admin how can i resolve it?

Example: I clicking on the button with admin account it's working perfectly with a non mod/admin account it don't set the next map

But i want that evrybody can set a map

Code:

Client:

  
-- GUI things and much more u don't need 
addEventHandler("onClientGUIClick",getRootElement(), 
function (player) 
   if (source == GUIEditor_Button[1]) then 
outputChatBox("Button Is here") 
    mapName = guiGetText ( GUIEditor_Edit[1] ) 
    triggerServerEvent ("nm", getLocalPlayer(), mapName) 
  end 
end) 

server:

  
--import map functions u not needing 
function snm(mapName) 
outputChatBox("Trigger Is working") 
    executeCommandHandler("nextmap", source, mapName) 
end 
addEvent("nm", true) 
addEventHandler("nm", getRootElement(),snm) 

executeCommandHandler("nextmap", source, mapName) 
--This works perfectly with admin but not if i'm logged out/logged in with a non amdin/mod/smod account 

Greetings Danny

Link to comment
Hmm maybe show full code?

Whole code ok:

client

GUIEditor_Window = {} 
GUIEditor_Button = {} 
GUIEditor_Label = {} 
GUIEditor_Edit = {} 
GUIEditor_Grid = {} 
GUIEditor_Image = {} 
  
GUIEditor_Window[1] = guiCreateWindow(701,328,584,394,"Map Shop",false) 
GUIEditor_Image[1] = guiCreateStaticImage(11,19,564,366,"back.png",false,GUIEditor_Window[1]) 
GUIEditor_Label[1] = guiCreateLabel(273,13,289,21,"Local Money:",false,GUIEditor_Image[1]) 
guiLabelSetColor(GUIEditor_Label[1],0,0,0) 
guiSetFont(GUIEditor_Label[1],"default-bold-small") 
GUIEditor_Label[2] = guiCreateLabel(270,75,284,70,"A Map Costs 4000$\n\nHow To Get Money?\nStand in the top3 of winners or reach the hunter",false,GUIEditor_Image[1]) 
guiLabelSetColor(GUIEditor_Label[2],0,0,0) 
guiSetFont(GUIEditor_Label[2],"default-bold-small") 
GUIEditor_Button[1] = guiCreateButton(280,264,265,91,"Buy Map [ -4000 ]",false,GUIEditor_Image[1]) 
GUIEditor_Label[3] = guiCreateLabel(272,36,252,19,"Local Map Status:",false,GUIEditor_Image[1]) 
guiLabelSetColor(GUIEditor_Label[3],0,0,0) 
guiSetFont(GUIEditor_Label[3],"default-bold-small") 
GUIEditor_Edit[1] = guiCreateEdit(286,211,252,45,"Local Map",false,GUIEditor_Image[1]) 
GUIEditor_Label[4] = guiCreateLabel(293,170,233,37,"Selected Map:",false,GUIEditor_Image[1]) 
guiLabelSetColor(GUIEditor_Label[4],0,255,0) 
guiLabelSetVerticalAlign(GUIEditor_Label[4],"center") 
guiLabelSetHorizontalAlign(GUIEditor_Label[4],"center",false) 
guiSetFont(GUIEditor_Label[4],"default-bold-small") 
mapGridList = guiCreateGridList(3,5,254,357,false,GUIEditor_Image[1]) 
guiGridListSetSelectionMode(mapGridList,2) 
  
  
mapsColumn = guiGridListAddColumn(mapGridList,"Maps",0.85) 
guiGridListSetSelectionMode(mapGridList,2) 
guiSetVisible (GUIEditor_Window[1], false) 
guiSetVisible (GUIEditor_Image[1], false) 
  
  
  
function set1( ) 
    selectedRow, selectedCol = guiGridListGetSelectedItem( mapGridList ) 
    gridMapName = guiGridListGetItemText( mapGridList, selectedRow, selectedCol ) 
    guiSetText( GUIEditor_Edit[1], gridMapName ) 
end 
addEventHandler( "onClientGUIClick", mapGridList, set1 ) 
  
  
addEvent("sendMaps", true ) 
function sendmaps(name) 
    row = guiGridListAddRow ( mapGridList ) 
    guiGridListSetItemText ( mapGridList, row, mapsColumn, name, false, false ) 
end 
addEventHandler( "sendMaps", getLocalPlayer(), sendmaps ) 
  
  
  
  
  
  
addEventHandler("onClientGUIClick",getRootElement(), 
function (player) 
   if (source == GUIEditor_Button[1]) then 
outputChatBox("Button doet het") 
    mapName = guiGetText ( GUIEditor_Edit[1] ) 
    triggerServerEvent ("nm", getLocalPlayer(), mapName) 
  end 
end) 
  
  
  
  
addEvent( "clearGridList", true ) 
function clearGridList() 
    guiGridListClear( mapGridList ) 
end 
addEventHandler( "clearGridList", getLocalPlayer(), clearGridList ) 
  
  
function onresourceStart () 
  bindKey ("F1", "down", showPanel) 
end 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), onresourceStart) 
  
function showPanel () 
getVisible = guiGetVisible (GUIEditor_Window[1]) 
playerName = getPlayerName ( getLocalPlayer() ) 
if (getVisible == true) then 
    guiSetVisible (GUIEditor_Window[1], false) 
guiSetVisible (GUIEditor_Image[1], false) 
    showCursor (false) 
end 
if (getVisible == false) then 
 triggerServerEvent ( "dannyevent", getRootElement()) 
    guiSetVisible (GUIEditor_Window[1], true) 
guiSetVisible (GUIEditor_Image[1], true) 
    showCursor (true) 
    local playerMoney = getPlayerMoney(source) 
  
    guiSetText ( GUIEditor_Label[1], "Local Money: [ " .. playerMoney .. " ]" ) 
end 
end 
     

Server

local rootElement = getRootElement() 
  
function raceWin(rank) 
    if rank ~= 1 then 
    return  
    end 
    local playername = getPlayerName(source) 
    givePlayerMoney(source,1500) 
    outputChatBox("*Race: "..playername.." took $1500 for finishing first!",rootElement,255,153,0) 
end 
addEventHandler("onPlayerFinish", rootElement, raceWin ) 
  
  
function snm(mapName) 
outputChatBox("Trigger Doet het") 
exports.mapmanager:changeGamemodeMap(mapName)  
--executeCommandHandler("nextmap", source, mapName) 
end 
addEvent("nm", true) 
addEventHandler("nm", getRootElement(),snm) 
  
function mappenerin() 
    local resourceTable = getResources() 
    triggerClientEvent ( "clearGridList", getRootElement() ) 
    for resourceKey, resourceValue in ipairs(resourceTable) do 
          local name = getResourceName(resourceValue) 
          local type1 = getResourceInfo ( resourceValue, "type" ) 
          local gamemode1 = getResourceInfo ( resourceValue, "gamemodes" ) 
          if type1 == "map" and gamemode1 == "race" then 
           triggerClientEvent ( "sendMaps", getRootElement(), name) 
         else 
            cancelEvent() 
        end 
    end 
end 
addEvent("dannyevent", true ) 
addEventHandler( "dannyevent", rootElement, mappenerin ) 
  

Link to comment

Hmm check

  
GUIEditor_Window = {} 
GUIEditor_Button = {} 
GUIEditor_Label = {} 
GUIEditor_Edit = {} 
GUIEditor_Grid = {} 
GUIEditor_Image = {} 
  
GUIEditor_Window[1] = guiCreateWindow(701,328,584,394,"Map Shop",false) 
GUIEditor_Image[1] = guiCreateStaticImage(11,19,564,366,"back.png",false,GUIEditor_Window[1]) 
GUIEditor_Label[1] = guiCreateLabel(273,13,289,21,"Local Money:",false,GUIEditor_Image[1]) 
guiLabelSetColor(GUIEditor_Label[1],0,0,0) 
guiSetFont(GUIEditor_Label[1],"default-bold-small") 
GUIEditor_Label[2] = guiCreateLabel(270,75,284,70,"A Map Costs 4000$\n\nHow To Get Money?\nStand in the top3 of winners or reach the hunter",false,GUIEditor_Image[1]) 
guiLabelSetColor(GUIEditor_Label[2],0,0,0) 
guiSetFont(GUIEditor_Label[2],"default-bold-small") 
GUIEditor_Button[1] = guiCreateButton(280,264,265,91,"Buy Map [ -4000 ]",false,GUIEditor_Image[1]) 
GUIEditor_Label[3] = guiCreateLabel(272,36,252,19,"Local Map Status:",false,GUIEditor_Image[1]) 
guiLabelSetColor(GUIEditor_Label[3],0,0,0) 
guiSetFont(GUIEditor_Label[3],"default-bold-small") 
GUIEditor_Edit[1] = guiCreateEdit(286,211,252,45,"Local Map",false,GUIEditor_Image[1]) 
GUIEditor_Label[4] = guiCreateLabel(293,170,233,37,"Selected Map:",false,GUIEditor_Image[1]) 
guiLabelSetColor(GUIEditor_Label[4],0,255,0) 
guiLabelSetVerticalAlign(GUIEditor_Label[4],"center") 
guiLabelSetHorizontalAlign(GUIEditor_Label[4],"center",false) 
guiSetFont(GUIEditor_Label[4],"default-bold-small") 
mapGridList = guiCreateGridList(3,5,254,357,false,GUIEditor_Image[1]) 
guiGridListSetSelectionMode(mapGridList,2) 
  
  
mapsColumn = guiGridListAddColumn(mapGridList,"Maps",0.85) 
guiGridListSetSelectionMode(mapGridList,2) 
guiSetVisible (GUIEditor_Window[1], false) 
guiSetVisible (GUIEditor_Image[1], false) 
  
  
  
function set1( ) 
    selectedRow, selectedCol = guiGridListGetSelectedItem( mapGridList ) 
    gridMapName = guiGridListGetItemText( mapGridList, selectedRow, selectedCol ) 
    guiSetText( GUIEditor_Edit[1], gridMapName ) 
end 
addEventHandler( "onClientGUIClick", mapGridList, set1 ) 
  
  
addEvent("sendMaps", true ) 
function sendmaps(name) 
    row = guiGridListAddRow ( mapGridList ) 
    guiGridListSetItemText ( mapGridList, row, mapsColumn, name, false, false ) 
end 
addEventHandler( "sendMaps", getLocalPlayer(), sendmaps ) 
  
function test () 
local mapName = guiGridListGetItemText (  mapGridList, guiGridListGetSelectedItem(  row ), 1 ) 
outputChatBox( "cmd:lol mapName = "..tostring( mapName ) ) 
triggerServerEvent("nm", getLocalPlayer(), mapName) 
end 
addCommandHandler ( "lol", test ) 
  
  
  
  
addEventHandler("onClientGUIClick",getRootElement(), 
function (player) 
   if (source == GUIEditor_Button[1]) then 
outputChatBox("Button doet het") 
    mapName = guiGetText ( GUIEditor_Edit[1] ) 
    outputChatBox( "onClientGUIClick mapName = "..tostring( mapName ) ) 
    triggerServerEvent ("nm", getLocalPlayer(), mapName) 
  end 
end) 
  
  
  
  
addEvent( "clearGridList", true ) 
function clearGridList() 
    guiGridListClear( mapGridList ) 
end 
addEventHandler( "clearGridList", getLocalPlayer(), clearGridList ) 
  
  
function onresourceStart () 
  bindKey ("F1", "down", showPanel) 
end 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), onresourceStart) 
  
function showPanel () 
getVisible = guiGetVisible (GUIEditor_Window[1]) 
playerName = getPlayerName ( getLocalPlayer() ) 
if (getVisible == true) then 
    guiSetVisible (GUIEditor_Window[1], false) 
guiSetVisible (GUIEditor_Image[1], false) 
    showCursor (false) 
end 
if (getVisible == false) then 
 triggerServerEvent ( "dannyevent", getRootElement()) 
    guiSetVisible (GUIEditor_Window[1], true) 
guiSetVisible (GUIEditor_Image[1], true) 
    showCursor (true) 
    local playerMoney = getPlayerMoney(source) 
  
    guiSetText ( GUIEditor_Label[1], "Local Money: [ " .. playerMoney .. " ]" ) 
end 
end 
  

Link to comment
  • 2 weeks later...

Oke, i was a little time inactive but now i was trying to pass a extra argument like: onServerCallsClientFunction

That Is A Extra Trigger Function but now i got a error

But this error is here now:

[18:11:19] ERROR: mapshop\server.lua:28: attempt to call a nil value

Please help me :)

Client:

  
------------------------------------------ 
-- Calling function from the client's side 
------------------------------------------ 
  
function callClientFunction(funcname, ...) 
    local arg = { ... } 
    if (arg[1]) then 
        for key, value in next, arg do arg[key] = tonumber(value) or value end 
    end 
    loadstring("return "..funcname)()(unpack(arg)) 
end 
addEvent("onServerCallsClientFunction", true) 
addEventHandler("onServerCallsClientFunction", resourceRoot, callClientFunction) 
  
  
  
----------------------- 
-- Call server function 
----------------------- 
  
function callServerFunction(funcname, ...) 
    local arg = { ... } 
    if (arg[1]) then 
        for key, value in next, arg do 
            if (type(value) == "number") then arg[key] = tostring(value) end 
        end 
    end 
    triggerServerEvent("onClientCallsServerFunction", resourceRoot , funcname, unpack(arg)) 
end 
  
  
outputChatBox("Race Shop By Danny Loaded",255,255,0) 
  
GUIEditor_Window = {} 
GUIEditor_Button = {} 
GUIEditor_Label = {} 
GUIEditor_Edit = {} 
GUIEditor_Grid = {} 
GUIEditor_Image = {} 
  
GUIEditor_Window[1] = guiCreateWindow(701,328,584,394,"Map Shop",false) 
GUIEditor_Image[1] = guiCreateStaticImage(11,19,564,366,"back.png",false,GUIEditor_Window[1]) 
GUIEditor_Label[1] = guiCreateLabel(273,13,289,21,"Local Money:",false,GUIEditor_Image[1]) 
guiLabelSetColor(GUIEditor_Label[1],0,0,0) 
guiSetFont(GUIEditor_Label[1],"default-bold-small") 
GUIEditor_Label[2] = guiCreateLabel(270,75,284,70,"A Map Costs 4000$\n\nHow To Get Money?\nStand in the top3 of winners or reach the hunter",false,GUIEditor_Image[1]) 
guiLabelSetColor(GUIEditor_Label[2],0,0,0) 
guiSetFont(GUIEditor_Label[2],"default-bold-small") 
GUIEditor_Button[1] = guiCreateButton(280,264,265,91,"Buy Map [ -4000 ]",false,GUIEditor_Image[1]) 
GUIEditor_Label[3] = guiCreateLabel(272,36,252,19,"Local Map Status:",false,GUIEditor_Image[1]) 
guiLabelSetColor(GUIEditor_Label[3],0,0,0) 
guiSetFont(GUIEditor_Label[3],"default-bold-small") 
GUIEditor_Edit[1] = guiCreateEdit(286,211,252,45,"Local Map",false,GUIEditor_Image[1]) 
GUIEditor_Label[4] = guiCreateLabel(293,170,233,37,"Selected Map:",false,GUIEditor_Image[1]) 
guiLabelSetColor(GUIEditor_Label[4],0,255,0) 
guiLabelSetVerticalAlign(GUIEditor_Label[4],"center") 
guiLabelSetHorizontalAlign(GUIEditor_Label[4],"center",false) 
guiSetFont(GUIEditor_Label[4],"default-bold-small") 
mapGridList = guiCreateGridList(3,5,254,357,false,GUIEditor_Image[1]) 
guiGridListSetSelectionMode(mapGridList,2) 
  
  
mapsColumn = guiGridListAddColumn(mapGridList,"Maps",0.85) 
guiGridListSetSelectionMode(mapGridList,2) 
guiSetVisible (GUIEditor_Window[1], false) 
guiSetVisible (GUIEditor_Image[1], false) 
  
  
  
function set1( ) 
    selectedRow, selectedCol = guiGridListGetSelectedItem( mapGridList ) 
    gridMapName = guiGridListGetItemText( mapGridList, selectedRow, selectedCol ) 
    guiSetText( GUIEditor_Edit[1], gridMapName ) 
end 
addEventHandler( "onClientGUIClick", mapGridList, set1 ) 
  
  
addEvent("sendMaps", true ) 
function sendmaps(name) 
    row = guiGridListAddRow ( mapGridList ) 
    guiGridListSetItemText ( mapGridList, row, mapsColumn, name, false, false ) 
end 
addEventHandler( "sendMaps", getLocalPlayer(), sendmaps ) 
  
function test () 
local mapName = guiGridListGetItemText (  mapGridList, guiGridListGetSelectedItem(  row ), 1 ) 
triggerServerEvent("nm", getLocalPlayer(), mapName) 
end 
addCommandHandler ( "lol", test ) 
  
  
  
  
addEventHandler("onClientGUIClick",getRootElement(), 
function (player) 
   if (source == GUIEditor_Button[1]) then 
outputChatBox("Button doet het") 
    mapName = guiGetText ( GUIEditor_Edit[1] ) 
    --local row,column = guiGridListGetSelectedItem(gridMaps) 
    --local mapName = guiGridListGetItemText(gridMaps,row,1) 
    callServerFunction("nm",getLocalPlayer(),mapName) 
  end 
end) 
  
  
  
  
  
addEvent( "clearGridList", true ) 
function clearGridList() 
    guiGridListClear( mapGridList ) 
end 
addEventHandler( "clearGridList", getLocalPlayer(), clearGridList ) 
  
  
function onresourceStart () 
  bindKey ("F1", "down", showPanel) 
end 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), onresourceStart) 
  
function showPanel () 
getVisible = guiGetVisible (GUIEditor_Window[1]) 
playerName = getPlayerName ( getLocalPlayer() ) 
if (getVisible == true) then 
    guiSetVisible (GUIEditor_Window[1], false) 
guiSetVisible (GUIEditor_Image[1], false) 
    showCursor (false) 
end 
if (getVisible == false) then 
 triggerServerEvent ( "dannyevent", getRootElement()) 
    guiSetVisible (GUIEditor_Window[1], true) 
guiSetVisible (GUIEditor_Image[1], true) 
    showCursor (true) 
    local playerMoney = getPlayerMoney(source) 
  
    guiSetText ( GUIEditor_Label[1], "Local Money: [ " .. playerMoney .. " ]" ) 
end 
end 

Server:

local rootElement = getRootElement() 
  
function race(rank) 
ouputChatBox ( "test" ) 
    local playername = getPlayerName(source) 
    givePlayerMoney(source,1500) 
    outputChatBox("*Race: "..playername.." took $1500 for finishing first!",rootElement,255,153,0) 
end 
addEventHandler("onPlayerFinish", rootElement, race ) 
  
  
function snm(mapName) 
outputChatBox("Trigger Doet het") 
--exports.mapmanager:changeGamemodeMap(mapName) 
executeCommandHandler("nextmap", source, mapName)  
end 
addEvent("nm", true) 
addEventHandler("nm", getRootElement(),snm) 
  
  
  
  
function callServerFunction(funcname, ...) 
    local arg = { ... } 
    if (arg[1]) then 
        for key, value in next, arg do arg[key] = tonumber(value) or value end 
    end 
loadstring("return "..funcname)()(unpack(arg)) 
end 
addEvent("onClientCallsServerFunction", true) 
addEventHandler("onClientCallsServerFunction", resourceRoot , callServerFunction) 
  
function callClientFunction(client, funcname, ...) 
    local arg = { ... } 
    if (arg[1]) then 
        for key, value in next, arg do 
            if (type(value) == "number") then arg[key] = tostring(value) end 
        end 
    end 
    -- If the clientside event handler is not in the same resource, replace 'resourceRoot' with the appropriate element 
    triggerClientEvent(client, "onServerCallsClientFunction", resourceRoot, funcname, unpack(arg or {})) 
end 
  
  
function mappenerin() 
    local resourceTable = getResources() 
    triggerClientEvent ( "clearGridList", getRootElement() ) 
    for resourceKey, resourceValue in ipairs(resourceTable) do 
          local name = getResourceName(resourceValue) 
          local type1 = getResourceInfo ( resourceValue, "type" ) 
          local gamemode1 = getResourceInfo ( resourceValue, "gamemodes" ) 
          if type1 == "map" and gamemode1 == "race" then 
           triggerClientEvent ( "sendMaps", getRootElement(), name) 
         else 
            cancelEvent() 
        end 
    end 
end 
addEvent("dannyevent", true ) 
addEventHandler( "dannyevent", rootElement, mappenerin ) 
  

Link to comment
  • 4 weeks later...

And can somebody tell what i need to edit?

  
addCommandHandler('nextmap', 
    function( player, command, ... ) -- CADU !@ HERE 
        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 
        if not _TESTING and not isPlayerInACLGroup(player, g_GameOptions.admingroup) then 
            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 
        --NextMapBuyed = true 
        g_ForcedNextMap = map 
        outputChatBox('#FFFFFF*#0fc0fcNext map Selected: #FFFFFF' .. getMapName( g_ForcedNextMap ) .. ' #0fc0fcby #FFFFFF' .. getPlayerName( player ), g_Root, 255, 255, 255, true) 
        triggerClientEvent ( "setNextMap", getRootElement(), getMapName( g_ForcedNextMap ) ) 
    end 
) 
  
function startingNextText() -- CADU!@ 
    --getMapsCompatibleWithGamemode  
    g_ForcedNextMap = getRandomMapCompatibleWithGamemode( getThisResource(), 10, g_GameOptions.ghostmode and 0 or getTotalPlayerCount() ) 
    if g_ForcedNextMap then 
        triggerClientEvent ( "setNextMap", getRootElement(), getMapName( g_ForcedNextMap ) ) 
    end 
end 
addEventHandler( "onMapStarting", getRootElement(), startingNextText) 

Or am i wrong that i need to change this?

Link to comment

Add this to "race/racevoting_server.lua":

function setNextMap( ... ) 
    local query = #{...}>0 and table.concat({...},' ') or nil 
    if not query then 
        if g_ForcedNextMap then 
            return false, "Next map is already set." 
        end 
    end 
    local map, errormsg = findMap( query ) 
    if (not map) then 
        outputRace( errormsg, player ) 
        return false, "Map not found." 
    end 
    if (g_ForcedNextMap == map) then 
        return false, 'Next map is already set to ' .. getMapName( g_ForcedNextMap ) 
    end 
    g_ForcedNextMap = map 
    return true 
end 

And then add this to the meta.xml:

function="setNextMap" type="server" /> 

Then you can do:

local set, errorMsg = exports["race"]:setNextMap(mapName) 

Link to comment

I got now a another problem when i choose a map and cliock on buy hten it saying 0 matches foudn for blabla map name

example: my own map [fun]hardwithstyle is in my folder:

server/blablabla/resources

and my other maps are in :

server/blablalbal/resources/[gamemodes]/[race]/[maps]

both are not working how can i solve it?

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