Jump to content

SnoopCat Scripting Problems.


SnoopCat

Recommended Posts

just store the players money from getPlayerMoney in a variable every 1 second with a timer, then use this variable in your function in onClientRender, that way, it will show however much the player has on his hud every frame without calling the function every frame.

something like this:

local root = getRootElement() 
local cash 
  
function updateCashVar() 
    cash = getPlayerMoney() 
end 
  
function scriptStarted() 
    setTimer(updateCashVar,1000,0) 
end 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), scriptStarted) 
  
function drawSpectators() 
    local textX = x - spectatorSettings.xOffset 
    local textY = spectatorSettings.yOffset 
    dxDrawText("MIRANDO: "..tostring(#spectators), textX - 0.2, textY - 0.2, x, y, tocolor(0, 0, 0, 255), 0.4, "bankgothic") 
    drawColor("#00FF00MIRANDO: #ffffff"..tonumber(#spectators), textX, textY, x, y, tocolor(83, 134, 139), 0.4, "bankgothic") 
    dxDrawText("FPS: "..tostring(getElementData(getLocalPlayer(), "fps")), textX - 0.2, textY + 15 - 0.2, x, y, tocolor(0, 0, 0, 255), 0.4, "bankgothic") 
    drawColor("#00FF00FPS: #ffffff"..tostring(getElementData(getLocalPlayer(), "fps")), textX, textY + 15, x, y, tocolor(15, 192, 252, 255), 0.4, "bankgothic") 
    dxDrawText("$: "..tostring(cash), textX - 0.2, textY + 15 + 15 - 0.2, x, y, tocolor(0, 0, 0, 255), 0.4, "bankgothic") 
    drawColor("#00FF00$: #ffffff"..tostring(cash), textX, textY + 15 + 15, x, y, tocolor(15, 192, 252, 255), 0.4, "bankgothic") 
end 
addEventHandler("onClientRender",root,drawSpectators) 

sorry but i dont have time to test it. :mrgreen:

Link to comment
  • Replies 74
  • Created
  • Last Reply

Top Posters In This Topic

just store the players money from getPlayerMoney in a variable every 1 second with a timer, then use this variable in your function in onClientRender, that way, it will show however much the player has on his hud every frame without calling the function every frame.

something like this:

local root = getRootElement() 
local cash 
  
function updateCashVar() 
    cash = getPlayerMoney() 
end 
  
function scriptStarted() 
    setTimer(updateCashVar,1000,0) 
end 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), scriptStarted) 
  
function drawSpectators() 
    local textX = x - spectatorSettings.xOffset 
    local textY = spectatorSettings.yOffset 
    dxDrawText("MIRANDO: "..tostring(#spectators), textX - 0.2, textY - 0.2, x, y, tocolor(0, 0, 0, 255), 0.4, "bankgothic") 
    drawColor("#00FF00MIRANDO: #ffffff"..tonumber(#spectators), textX, textY, x, y, tocolor(83, 134, 139), 0.4, "bankgothic") 
    dxDrawText("FPS: "..tostring(getElementData(getLocalPlayer(), "fps")), textX - 0.2, textY + 15 - 0.2, x, y, tocolor(0, 0, 0, 255), 0.4, "bankgothic") 
    drawColor("#00FF00FPS: #ffffff"..tostring(getElementData(getLocalPlayer(), "fps")), textX, textY + 15, x, y, tocolor(15, 192, 252, 255), 0.4, "bankgothic") 
    dxDrawText("$: "..tostring(cash), textX - 0.2, textY + 15 + 15 - 0.2, x, y, tocolor(0, 0, 0, 255), 0.4, "bankgothic") 
    drawColor("#00FF00$: #ffffff"..tostring(cash), textX, textY + 15 + 15, x, y, tocolor(15, 192, 252, 255), 0.4, "bankgothic") 
end 
addEventHandler("onClientRender",root,drawSpectators) 

sorry but i dont have time to test it. :mrgreen:

i will gonna test it

Link to comment

srry for double but that code isnt working :S i did this

Client:

local x, y = guiGetScreenSize () 
  
local localPlayer = getLocalPlayer() 
  
local spectatorSettings = { 
count = 7, -- how many player names to show, before showing "and x more" 
charLimit = 19, -- max limit of characters in player name 
xOffset = 115, -- how far to the left this should be 
yOffset = (y / 2)-200, -- how far down the screen this should be ~ currently it is almost half way down 
alwaysShow = true -- whether to show anything if there aren't any players spectating you 
} 
  
local spectators = {} 
  
addEvent('addSpectator', true) 
addEvent('removeSpectator', true) 
  
addEventHandler('onClientResourceStart', root, 
    function() 
        triggerServerEvent('addClient', localPlayer) 
    end 
) 
  
addEventHandler('addSpectator', root, 
    function(spectator) 
        table.insert(spectators, spectator) 
    end 
) 
  
addEventHandler('removeSpectator', root, 
    function(spectator) 
        for i, val in ipairs(spectators) do 
            if (val == spectator) then 
                table.remove(spectators, i) 
            end 
        end 
    end 
) 
  
function elementCheck (elem) 
    if elem then 
        if isElement (elem) then 
            if (getElementType (elem) == 'player') then 
                return true 
            end 
        end 
    end 
    return false 
end 
  
function drawColor(str, ax, ay, bx, by, color, scale, font, alignX, alignY) 
  
  if alignX then 
    if alignX == "center" then 
      local w = dxGetTextWidth(str:gsub("#%x%x%x%x%x%x",""), scale, font) 
      ax = ax + (bx-ax)/2 - w/2 
    elseif alignX == "right" then 
      local w = dxGetTextWidth(str:gsub("#%x%x%x%x%x%x",""), scale, font) 
      ax = bx - w 
    end 
  end 
  
  if alignY then 
    if alignY == "center" then 
      local h = dxGetFontHeight(scale, font) 
      ay = ay + (by-ay)/2 - h/2 
    elseif alignY == "bottom" then 
      local h = dxGetFontHeight(scale, font) 
      ay = by - h 
    end 
  end 
  
  local pat = "(.-)#(%x%x%x%x%x%x)" 
  local s, e, cap, col = str:find(pat, 1) 
  local last = 1 
  while s do 
    if cap == "" and col then color = tocolor(tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)), 255) end 
    if s ~= 1 or cap ~= "" then 
      local w = dxGetTextWidth(cap, scale, font) 
      dxDrawText(cap, ax, ay, ax + w, by, color, scale, font) 
      ax = ax + w 
      color = tocolor(tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)), 255) 
    end 
    last = e + 1 
    s, e, cap, col = str:find(pat, last) 
  end 
  if last <= #str then 
    cap = str:sub(last) 
    local w = dxGetTextWidth(cap, scale, font) 
    dxDrawText(cap, ax, ay, ax + w, by, color, scale, font) 
  end 
end 
  
    local root = getRootElement() 
    local cash 
      
    function updateCashVar() 
        cash = getPlayerMoney() 
    end 
      
    function scriptStarted() 
        setTimer(updateCashVar,1000,0) 
    end 
    addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), scriptStarted) 
      
    function drawSpectators() 
        local textX = x - spectatorSettings.xOffset 
        local textY = spectatorSettings.yOffset 
        dxDrawText("MIRANDO: "..tostring(#spectators), textX - 0.2, textY - 0.2, x, y, tocolor(0, 0, 0, 255), 0.4, "bankgothic") 
        drawColor("#00FF00MIRANDO: #ffffff"..tonumber(#spectators), textX, textY, x, y, tocolor(83, 134, 139), 0.4, "bankgothic") 
        dxDrawText("FPS: "..tostring(getElementData(getLocalPlayer(), "fps")), textX - 0.2, textY + 15 - 0.2, x, y, tocolor(0, 0, 0, 255), 0.4, "bankgothic") 
        drawColor("#00FF00FPS: #ffffff"..tostring(getElementData(getLocalPlayer(), "fps")), textX, textY + 15, x, y, tocolor(15, 192, 252, 255), 0.4, "bankgothic") 
        dxDrawText("$: "..tostring(cash), textX - 0.2, textY + 15 + 15 - 0.2, x, y, tocolor(0, 0, 0, 255), 0.4, "bankgothic") 
        drawColor("#00FF00$: #ffffff"..tostring(cash), textX, textY + 15 + 15, x, y, tocolor(15, 192, 252, 255), 0.4, "bankgothic") 
    end 
    addEventHandler("onClientRender",root,drawSpectators) 
  
-- Set up variables and settings 
local x, y = guiGetScreenSize () 
local localPlayer = getLocalPlayer() 
local dxDraw = {} 
local dxDrawOutline = {} 
  
  
local spectatorSettings = { 
xOffset = (x/6.3), 
yOffset = y - (y/1.4)} 
  
  
local showSpectators = true 
  
function changeSpectatorsEnabled() 
    showSpectators = not showSpectators 
end 
  
local spectators = {} 
addEvent('addSpectator', true) 
addEvent('removeSpectator', true) 
  
addEventHandler('onClientResourceStart', root, 
    function() 
        triggerServerEvent ('addClient', localPlayer) 
    end) 
  
addEventHandler('addSpectator', root, 
    function(spectator) 
        table.insert(spectators, spectator) 
    end) 
  
addEventHandler('removeSpectator', root, 
    function(spectator) 
        for i, val in ipairs(spectators) do 
            if (val == spectator) then 
                table.remove(spectators, i) 
            end 
        end 
    end) 
  
function elementCheck (elem) 
    if elem then 
        if isElement (elem) then 
            if (getElementType (elem) == 'player') then 
                return true 
            end 
        end 
    end 
    return false 
end 
-------------------------------------------------------- 
  
  
function drawSpectators() 
    if showSpectators == true then 
        local textX = x - spectatorSettings.xOffset 
        local textY = spectatorSettings.yOffset 
  
        scale = getScale(x) 
  
        dxDrawText("",textX - 1, textY + 1, x, y, tocolor(255,0,0), scale, 'bankgothic') 
        dxDrawText("",textX, textY, x, y, tocolor(255,0,0), scale, 'bankgothic') 
  
        if not (isPlayerDead(localPlayer)) then 
            if (#spectators > 0) then 
                for i, v in ipairs(spectators) do 
                    if elementCheck (v) then 
                        local name = getPlayerName(v) 
                        if (i) then 
                            dxDrawOutline[i] = dxDrawText (" "..string.gsub(name,"#%x%x%x%x%x%x",""), textX - 1, (textY + scale) + (dxGetFontHeight(scale,'bankgothic') * i) + 1.5, x, y, tocolor(0,0,0, 255), scale, 'bankgothic') 
                            dxDraw[i] = dxDrawColorText (" "..name, textX, (textY + scale) + (dxGetFontHeight(scale,'bankgothic') * i), x, y, tocolor(255, 255, 255, 255), scale, 'bankgothic') 
                        end 
                    else 
                        table.remove (spectators, k) 
                    end 
                end 
            else 
            dxDrawOutline[1] = dxDrawText ("", textX - 1, (textY + scale) + dxGetFontHeight(scale,'bankgothic') + 1.5, x, y, tocolor(0,0,0, 255), scale, 'bankgothic') 
            dxDraw[1] = dxDrawColorText ("", textX, (textY + scale) + dxGetFontHeight(scale,'bankgothic'), x, y, tocolor(255, 255, 255, 255), scale, 'bankgothic') 
            end 
        end 
    end 
end 
addEventHandler('onClientRender', root, drawSpectators) 
  
  
function dxDrawColorText(str, ax, ay, bx, by, color, scale, font) 
    local pat = "(.-)#(%x%x%x%x%x%x)" 
    local s, e, cap, col = str:find(pat, 1) 
    local last = 1 
    while s do 
        if cap == "" and col then color = tocolor(tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)), 255) end 
        if s ~= 1 or cap ~= "" then 
            local w = dxGetTextWidth(cap, scale, font) 
            dxDrawText(cap, ax, ay, ax + w, by, color, scale, font) 
            ax = ax + w 
            color = tocolor(tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)), 255) 
        end 
        last = e + 1 
        s, e, cap, col = str:find(pat, last) 
    end 
    if last <= #str then 
        cap = str:sub(last) 
        local w = dxGetTextWidth(cap, scale, font) 
        dxDrawText(cap, ax, ay, ax + w, by, color, scale, font) 
    end 
end 
  
  
function getScale(w) 
    local scale = (w*0.5)/1000 
    return scale 
end 

Link to comment

But getPlayerMoney is for "default" GTA cash. I dont know the race starter but sure u need getElementData or getAccountData.

Made the script server side for get money with event onPlayerSpawn and trig client for dx or GUI element.

Link to comment
But getPlayerMoney is for "default" GTA cash. I dont know the race starter but sure u need getElementData or getAccountData.

Made the script server side for get money with event onPlayerSpawn and trig client for dx or GUI element.

my sistem uses normal cash sistem cuz when i add money from the panel it gets on the money panel...

Link to comment

hello i have another problem. i need to move 2 objects when hitting a marker, this is what i did.

gMe7 = getLocalPlayer() 
  
function waterino1() 
WTF = createMarker( 5942.1000976563,1276.4000244141,8.8000001907349, "corona", 1, 17, 255, 0, 0) 
asd1 = createObject (14548, 5942.7001953125 , 1316.6999511719 , 16.200000762939 , 7.2493896484375 , 359.24401855469 , 180.09539794922) 
WTF2 = createMarker( 5942.1000976563,1276.4000244141,8.8000001907349, "corona", 1, 17, 255, 0, 0) 
asd2 = createObject (14553, 5943.2001953125 , 11319 , 15.89999961853 , 7.2493896484375 , 359.24401855469 , 180.09539794922) 
 end 
  
function MarkerHit ( hitPlayer, matchingDimension ) 
vehicle = getPedOccupiedVehicle ( hitPlayer ) 
if hitPlayer ~= gMe7 then return end 
if source == WTF then 
             moveObject(asd1, 100000, 5906.5 , 3386.6000976563 , 16.200000762939) 
             setTimer(asd1,20000) 
else  
if source == WTF2 then 
 moveObject(asd2, 100000, 5906 , 3388.8999023438 , 15.89999961853) 
 setTimer(asd2,20000) 
              
             
end 
end 
  
addEventHandler( "onClientResourceStart", getResourceRootElement(getThisResource()), waterino1 ) 
addEventHandler ( "onClientMarkerHit", getRootElement(), MarkerHit ) 
  

Link to comment
  • 4 weeks later...

new Problem:

i was trying to create a hunter alert sistem that when someone reach the hunter it says on the screen for 5 secs "Hunter Reached" this is what i do but isnt working :S

Server side:

function someoneReachedHunter(number, sort, model) 
    if sort == "vehiclechange" and model == 425 then 
        dxDrawText("HUNTER ENCONTRADO!",226.0,637.0,625.0,671.0,"bankgothic","left","top",false,false,false) 
setTimer ( someoneReachedHunter, 5000, 1 ) 
    end 
end 
addEvent("onPlayerPickUpRacePickup",true) 
addEventHandler("onPlayerPickUpRacePickup",getRootElement(),someoneReachedHunter) 
end 

meta.xml

    
        "Hunter_Alert" author="SnoopCat" type="script" version="1.1" /> 
        

Link to comment
new Problem:

i was trying to create a hunter alert sistem that when someone reach the hunter it says on the screen for 5 secs "Hunter Reached" this is what i do but isnt working :S

Server side:

function someoneReachedHunter(number, sort, model) 
    if sort == "vehiclechange" and model == 425 then 
        dxDrawText("HUNTER ENCONTRADO!",226.0,637.0,625.0,671.0,"bankgothic","left","top",false,false,false) 
setTimer ( someoneReachedHunter, 5000, 1 ) 
    end 
end 
addEvent("onPlayerPickUpRacePickup",true) 
addEventHandler("onPlayerPickUpRacePickup",getRootElement(),someoneReachedHunter) 
end 

meta.xml

    
        "Hunter_Alert" author="SnoopCat" type="script" version="1.1" /> 
        

WTF ? Why it's on server side?!

dxDrawTexte Client-only function

Edit: Hm dude... if in the map have multiple hunter pickup :roll: I think it will create multiple dxDrawText :|

Link to comment

Like this ? (not tested)

Client-side:

  
addEvent("onPlayerPickUpRacePickup",true) 
addEventHandler("onPlayerPickUpRacePickup",getRootElement(), 
function(number, sort, model) 
    if sort == "vehiclechange" and model == 425 then 
        local thedx = dxDrawText("HUNTER ENCONTRADO!",226.0,637.0,625.0,671.0,"bankgothic","left","top",false,false,false) 
        setTimer(closeTheHunterAlert, 5000, 1) 
        addEventHandler("onClientRender", getRootElement(), showTheHunterAlert) 
    end 
end) 
  
function showTheHunterAlert() 
    dxDrawText("HUNTER ENCONTRADO !",226.0,637.0,625.0,671.0,"bankgothic","left","top",false,false,false) 
end 
  
function closeTheHunterAlert() 
    removeEventHandler("onClientRender", getRootElement(), showTheHunterAlert) 
end 
  

Edited by Guest
Link to comment

soo like this?

Server side:

function someoneReachedHunter(number, sort, model) 
    if sort == "vehiclechange" and model == 425 then 
        dxDrawText("HUNTER ENCONTRADO!",226.0,637.0,625.0,671.0,"bankgothic","left","top",false,false,false) 
        triggerClientEvent ( thePlayer, "text", getRootElement() ) 
setTimer ( someoneReachedHunter, 5000, 1 ) 
    end 
end 
addEvent("onPlayerPickUpRacePickup",true) 
addEventHandler("onPlayerPickUpRacePickup",getRootElement(),someoneReachedHunter) 
end 

Client

  
function text 
dxDrawText("HUNTER ENCONTRADO!",226.0,637.0,625.0,671.0,"bankgothic","left","top",false,false,false) 

meta.xml

    
        "Hunter_Alert" author="SnoopCat" type="script" version="1.1" /> 
        

is thta correct?

Link to comment
Like this ? (not tested)

Client-side:

  
addEvent("onPlayerPickUpRacePickup",true) 
addEventHandler("onPlayerPickUpRacePickup",getRootElement(), 
function(number, sort, model) 
    if sort == "vehiclechange" and model == 425 then 
        local thedx = dxDrawText("HUNTER ENCONTRADO!",226.0,637.0,625.0,671.0,"bankgothic","left","top",false,false,false) 
        setTimer(closeTheHunterAlert, 5000, 1) 
        addEventHandler("onClientRender", getRootElement(), showTheHunterAlert) 
    end 
end) 
  
function showTheHunterAlert() 
    dxDrawText("HUNTER ENCONTRADO !",226.0,637.0,625.0,671.0,"bankgothic","left","top",false,false,false) 
end 
  
function closeTheHunterAlert() 
    removeEventHandler("onClientRender", getRootElement(), showTheHunterAlert) 
end 
  

not working :S

Link to comment

-- client side:

function drawText() 
    dxDrawText("HUNTER ENCONTRADO!",226.0,637.0,625.0,671.0,tocolor (255,0,0,255),1.3,"bankgothic","left","top",false) 
end 
  
addEvent("onHunterReached",true) 
addEventHandler("onHunterReached",root, 
function () 
    addEventHandler("onClientRender",root,drawText) 
    setTimer(function () removeEventHandler("onClientRender",root,drawText) end, 5000, 1) 
end) 

-- server side:

addEvent("onPlayerPickUpRacePickup",true) 
addEventHandler("onPlayerPickUpRacePickup",getRootElement(), 
function(number, sort, model) 
    if (sort == "vehiclechange" and model == 425) then 
        triggerClientEvent("onHunterReached",getRootElement()) 
    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...