Jump to content

Bueno,duda scripting


Carlossg

Recommended Posts

Oh, yo puse las funciones del MTA, me equivoque.

addCommandHandler("flip", 
    function(thePlayer, flip, ammount) 
       if tonumber(ammount) > tonumber(getElementData(thePlayer,"data.money")) then 
             outputChatBox("You don't have that kind of money",thePlayer,255,0,0) 
       elseif ammount > 1000 then 
             outputChatBox("You can't flip more than 1000$",thePlayer,255,0,0) 
       end 
       local money = tonumber(getElementData(thePlayer,"data.money")) 
       if math.random ( 2 ) == 1 then setElementData(thePlayer, "data.money", money+tonumber(ammount)) 
       else setElementData(thePlayer, "data.money", money-tonumber(ammount)) end 
end) 

Link to comment

Bueno, funciona pero no actualiza el dinero en la scoreboard.

El código solo(lo he modificado un poco):

    addCommandHandler("flip", 
    function(thePlayer, flip, ammount) 
       if tonumber(ammount) > tonumber(getElementData(thePlayer,"data.money")) then 
             outputChatBox("You don't have that kind of money",thePlayer,255,0,0) 
       elseif tonumber(ammount) > 1000 then 
             outputChatBox("You can't flip more than 1000$",thePlayer,255,0,0) 
       end 
       local money = tonumber(getElementData(thePlayer,"data.money"))    
       if math.random (2) == 1 then setElementData(thePlayer, "data.money", money+tonumber(ammount)) outputChatBox("Flip: "..getPlayerName(thePlayer):gsub("#%x%x%x%x%x%x","").. " flip " ..tonumber(ammount).. " and Wins!!",0,255,0, true ) 
       else setElementData(thePlayer, "data.money", money-tonumber(ammount)) outputChatBox("Flip: "..getPlayerName(thePlayer):gsub("#%x%x%x%x%x%x","").." flip " ..tonumber(ammount).. " and Lose!!",255,0,0, true )       end 
     end) 

No sé por que no se configuran los colores y, tampoco por qué no funciona el TRUE que he puesto para que acepte los color codes, ya que he tenido que poner

gsub("#%x%x%x%x%x%x","") 

Y, aquí el código en el escript entero

    function creatingTables() 
        exports.scoreboard:addScoreboardColumn("Cash") 
        executeSQLCreateTable("playerData", "serial STRING, Cash INT, DMAttempts INT, DDAttempts INT") 
        outputChatBox("Cash System by KHD started.") 
        for index, player in ipairs(getElementsByType("player")) do 
            addAccountIfNotExists(player) 
        end 
    end 
    addEventHandler("onResourceStart", resourceRoot, creatingTables) 
      
    function addAccountIfNotExists(player) 
        local serial = getPlayerSerial(player) 
        local CheckPlayer = executeSQLSelect ( "playerData", "*", "serial = '" .. serial .. "'" ) 
          
        if ( type( CheckPlayer ) == "table" and #CheckPlayer == 0 ) or not CheckPlayer then 
            executeSQLInsert ( "playerData", "'"..serial.."','0','0','0'" ) 
        else 
            local Cash  = tonumber(CheckPlayer [1]["Cash"]) 
            setElementData(source,"Cash", Cash) 
            setElementData(source,"data.money",Cash,true)         
        end 
    end 
      
    addEventHandler("onPlayerJoin",root,function () addAccountIfNotExists(source) end) 
      
    function DestructionMoney(mapInfo,mapOptions,gameOptions) 
    info = mapInfo.modename 
    if mapInfo.modename == "Destruction derby" then 
        for k,v in ipairs(getElementsByType("player")) do 
            local serial = getPlayerSerial(v) 
            local DDAttempts = executeSQLSelect ( "playerData", "DDAttempts","serial = '" .. serial .. "'") 
            local DDAttempts = tonumber(DDAttempts[1]["DDAttempts"]) + 1 
            executeSQLUpdate ( "playerData", "DDAttempts = '"..DDAttempts.."'","serial = '" .. serial .. "'") 
            setElementData(v,"data.DDAttempts",DDAttempts,true) 
            end 
        end 
    end 
    addEvent("onMapStarting") 
    addEventHandler("onMapStarting", getRootElement(), DestructionMoney) 
      
    function DestructionMoney2(thePlayer) 
        local playername = getPlayerName(thePlayer) 
        local serial = getPlayerSerial(thePlayer) 
        local Cash = executeSQLSelect ( "playerData", "Cash","serial = '" .. serial .. "'") 
        
        outputChatBox("*Wins: "..playername.." took $"..get('MoneyForDD').." for winning the map!",getRootElement(),255,255,0) 
        local Cash  = tonumber(Cash[1]["Cash"]) + get('MoneyForDD') 
        setElementData(thePlayer ,"Cash", Cash) 
        setElementData(thePlayer ,"data.money",Cash,true) 
        setElementData(thePlayer ,"data.playername",playername,true) 
        executeSQLUpdate ( "playerData", "Cash = '"..Cash.."'","serial = '" .. serial .. "'") 
    end 
      
    function hunterBonus(pickupID, pickupType, vehicleModel) 
    if (info == "Destruction derby" and pickupType == "vehiclechange" and vehicleModel == 425) then     
        local serial = getPlayerSerial(source) 
        local Cash = executeSQLSelect ( "playerData", "Cash","serial = '" .. serial .. "'") 
        local Cash = tonumber(Cash[1]["Cash"]) + 1000   
        outputChatBox("*Hunter: "..getPlayerName(source).." gets a $1000 hunter bonus!",source,25,125,225) 
        setElementData(source ,"Cash", Cash) 
        setElementData(source ,"data.money",Cash,true) 
        executeSQLUpdate ( "playerData", "Cash = '"..Cash.."'","serial = '" .. serial .. "'") 
        end 
    end 
    addEventHandler("onPlayerPickUpRacePickup",getRootElement(),hunterBonus) 
     
        addCommandHandler("cash", 
    function (thePlayer) 
         local money = tonumber(getElementData(thePlayer,"data.money")) 
         if (money) then 
               outputChatBox("Your money is $".. tostring(money) .."!",thePlayer,0,255,0) 
         end 
    end) 
    addCommandHandler("flip", 
    function(thePlayer, flip, ammount) 
       if tonumber(ammount) > tonumber(getElementData(thePlayer,"data.money")) then 
             outputChatBox("You don't have that kind of money",thePlayer,255,0,0) 
       elseif tonumber(ammount) > 1000 then 
             outputChatBox("You can't flip more than 1000$",thePlayer,255,0,0) 
       end 
       local money = tonumber(getElementData(thePlayer,"data.money"))    
       if math.random (2) == 1 then setElementData(thePlayer, "data.money", money+tonumber(ammount)) outputChatBox("Flip: "..getPlayerName(thePlayer):gsub("#%x%x%x%x%x%x","").. " flip " ..tonumber(ammount).. " and Wins!!",0,255,0, true ) 
       else setElementData(thePlayer, "data.money", money-tonumber(ammount)) outputChatBox("Flip: "..getPlayerName(thePlayer):gsub("#%x%x%x%x%x%x","").." flip " ..tonumber(ammount).. " and Lose!!",255,0,0, true )       end 
     end) 

Desde que he añadido lo del flip ya no da 1000$ al coger el hunter :(

P.D.:Ya tengo teclado nuevo.

Link to comment

Hola, primero tengo otra duda

He encontrado en la lista un server llamado SAUR que tiene una idea genial, y es que al principio descargas un pequeño archivo de 800Kb aproximadamente que al descargarse empieza un video o una vista de águila(o pajaro) mostrandote aspectos del servidor para soportar la siguiente descarga de unos 16 o 17 Mb.

Bien me gustaría saber como se hace ésto ya que mi server de race tiene una ENORME descarga de mods y la mayoría de players que entran, se salen.

También me gustaría saber la solucion al problema que postee hace nada (el tema de arriba).

Link to comment

Ese server es el de Castillo (SolidSnake14), y no es nada nuevo, ya que se ha visto muchas otras veces xD

Usa

setCameraMatrix 

En SERVIDOR (server), ya que el cliente funciona una vez que se han bajado los mods de autos y eso...

Lo de arriba... Me da weba leer el script, dejaré que alguien más te ayude ;P

Link to comment

Castillo, desde que he añadido lo del comando flip ya no da el bonus de los 1000$ al coger el hunter, y el script del flip funciona pero tiene unos bugs, que es que no actualiza el money en la base de datos SQL,y el otro es que cuando le dan a flip pueden hacer un flip de 3000$ perfectamente aunque les tira el mensage "You can't flip more than 1000$" y también que aunque no tengan el dinero que sea les da el error pero si ganan se los dan y si no se los pone negativo.

Me gustaría que se actualizara y que no tuviese esos bugs tan feos.

Link to comment

Creo que he solucionado lo del bug de la cantidad pero no estoy seguro ya que no puedo probarlo,

He aquí el script corregido:

     addCommandHandler("flip", 
    function(thePlayer, flip, ammount) 
       if tonumber(ammount) > tonumber(getElementData(thePlayer,"data.money")) then 
             outputChatBox("You don't have that kind of money",thePlayer,255,0,0) 
       elseif tonumber(ammount) > 1000 then 
             outputChatBox("You can't flip more than 1000$",thePlayer,255,0,0) 
       end 
       local money = tonumber(getElementData(thePlayer,"data.money")) 
      if tonumber(ammount) <= tonumber(money) and tonumber(ammount) <= 1000 then   
       if math.random (2) == 1 then 
       setElementData(thePlayer, "data.money", money+tonumber(ammount)) 
       outputChatBox("Flip: "..getPlayerName(thePlayer):gsub("#%x%x%x%x%x%x","").. " flip " ..tonumber(ammount).. " and Wins!!",0,255,0, true ) 
       else  
       setElementData(thePlayer, "data.money", money-tonumber(ammount)) 
       outputChatBox("Flip: "..getPlayerName(thePlayer):gsub("#%x%x%x%x%x%x","").." flip " ..tonumber(ammount).. " and Lose!!",255,0,0, true )        
       end 
      end 
     end) 

Me gustaría que me digeraís si así por encima tiene algún error.

No está corregido lo de que no guarda el dinero ya que no sé como hacerlo :( .

Link to comment

Ok pero siguen sin ir los colorcodes por cierto y he solucinado lo del flip aunque no tengas dinero lo ha probado una persona ahora solo me falta por que no da 1000$ al coger el hunter y por que no guarda el dinero que ganas en la DB.

Edit: ¿Así valdría?:

     addCommandHandler("flip", 
    function(thePlayer, flip, ammount) 
       if tonumber(ammount) > tonumber(getElementData(thePlayer,"data.money")) then 
             outputChatBox("You don't have that kind of money",thePlayer,255,0,0) 
       elseif tonumber(ammount) > 1000 then 
             outputChatBox("You can't flip more than 1000$",thePlayer,255,0,0) 
       end 
       local money = tonumber(getElementData(thePlayer,"data.money")) 
      if tonumber(ammount) <= tonumber(money) and tonumber(ammount) <= 1000 then   
       if math.random (2) == 1 then 
       setElementData(thePlayer, "data.money", money+tonumber(ammount)) 
       outputChatBox("Flip: "..getPlayerName(thePlayer).. " flip " ..tonumber(ammount).. " and Wins!!",getRootElement(),0,255,0, true ) 
       else  
       setElementData(thePlayer, "data.money", money-tonumber(ammount)) 
       outputChatBox("Flip: "..getPlayerName(thePlayer).." flip " ..tonumber(ammount).. " and Lose!!",getRootElement(),255,0,0, true )        
       end 
      end 
     end) 

No entiendo muy bien el uso de getRootElement()

Link to comment

miren,cogí este ejemplo de la wiki, que está mal en la wiki me explico:

function pingkick() 
    local ping = getPlayerPing(thePlayer) 
    if (tonumber(ping) > 400) then  
        outputChatBox("Your ping is pretty high! Please fix it.", thePlayer) 
    end 
end 
addEventHandler("onPlayerJoin", getRootElement(), pingkick) 
setTimer(pingkick, 60000, 0) 

primero lo modifiqué ya que le faltaba tonumber en el if de la linea 3 y ahora tira un fallo:

WARNING: antilag\ping.lua:2: Bad argument @ 'getPlayerPing' 

el cuál provoca:

ERROR: antilag\ping.lua:3: attempt to compare number with nil 

Me gustaría solucionar este error, por favor ya que estoy haciendo un antilag y eso es solo una parte del código :) .

Link to comment
function pingkick() 
    local ping = getPlayerPing(source) 
    if (tonumber(ping) > 400) then 
        outputChatBox("Your ping is pretty high! Please fix it.", source) 
    end 
end 
addEventHandler("onPlayerJoin", getRootElement(), pingkick) 
  
function checkPlayersPing() 
     for index, player in ipairs(getElementsByType("player")) do 
          local ping = getPlayerPing(player) 
          if (tonumber(ping) > 400) then 
               outputChatBox("Your ping is pretty high! Please fix it.", player) 
          end 
     end 
end 
setTimer(checkPlayersPing, 60000, 0) 

Link to comment
otra cosa,puede ser que esté utiliazando mal el:
GetPlayerIdleTime 

ya que obtengo in kick automático al entrar a mi servidor o.O

:shock:

Available only in MTA SA 1.2 and onwards This function gets the amount of time in milliseconds that a players position has not changed.

Tomaste el ejemplo de la wiki?

No eh usado la funcion, pero segun la wiki es el tiempo que el jugador no se a movido (que no a cambiado su posicion)

PD: En el meta pusiste el: ?

Link to comment

Wow, actualicé y ya funciona correctamente.

Otra cosa; ¿hay alguna función con la que pueda bloquear la descarga de ciertos archivos?.

También este script no funciona por el momento no muestra la gui, lo poco que llevo no funciona.

function getServerMaps() 
local mapsTable = {} 
    for resourceKey, resourceValue in ipairs(getResources()) do 
        local name = getResourceInfo ( resourceValue, "name" ) 
        local type = getResourceInfo ( resourceValue, "type" ) 
        local author = getResourceInfo ( resourceValue, "author" ) 
        local game = getResourceInfo ( resourceValue, "gamemodes" ) 
        if (type == "map" and game == "race") then 
            table.insert(mapsTable, {name=name, author=author or "Unknown"}) 
        end 
    end 
    return mapsTable 
end 
  
function buyMap () 
  
    local mapas = getServerMaps() 
         
      spawnScreenMenu = guiCreateWindow ( 0.15, 0.33, 0.7, 0.34, "Welcome to map customer", true ) 
      
      spawnScreenOKButton = guiCreateButton ( 0.4, 0.85, 0.20, 0.15, "OK", true, spawnScreenMenu ) 
     
      guiWindowSetMovable ( spawnScreenMenu, true ) 
      guiWindowSetSizable ( spawnScreenMenu, false ) 
       
      spawnScreenGridList = guiCreateGridList ( 0, 0.1, 1, 0.9, true, spawnScreenMenu ) 
      guiGridListSetSelectionMode ( spawnScreenGridList, 2 ) 
      
      guiGridListAddColumn ( spawnScreenGridList, "Maps", 0.3 ) 
          guiSetVisible(spawnScreenMenu, false) 
      
  
     for index, map in ipairs(mapas) do 
      guiGridListSetItemText ( spawnScreenGridList, row, 1, mapsTable, false, false ) 
      end 
                 
  
end 
addEventHandler("onClientResourceStart", resourceRoot,buyMap) 
  
-- 
  
  
function bindTheKeys () 
        for k, v in ipairs(getElementsByType("player")) do 
                bindKey(v, "F1", "down", triggerGUI) 
        end 
end 
addEventHandler("onClientResourceStart", resourceRoot, bindTheKeys) 
  
function bindKeyToConnectingPlayer(player) 
        if player then 
                bindKey(player, "F1", "down", triggerGUI) 
        end 
end 
addEventHandler("onClientPlayerJoin", getRootElement(), bindKeyToConnectingPlayer) 
  
function triggerGUI(key,keyState) 
        if key == "F1" and keyState == "down" then 
                guiSetVisible(spawnScreenMenu, true) 
        end 
end 

PD:El script es client-side y creo que es ahí dónde está el error.

Link to comment
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...