Jump to content

knightscript

Members
  • Posts

    127
  • Joined

  • Last visited

Posts posted by knightscript

  1. 18 minutes ago, Pirulax said:

    The table constructor is '{}' not '[]".
    But, back on topic, I'm sure you can pass a table thru without a problem.
    If for some reason you really can't, then use toJSON and fromJSON.

    Thanks, made it work :)

        local spawn = exports["NTTC_Tables"]:getRandomLoot("Los Santos")
     

        local spawn = exports["NTTC_Tables"]:getRandomLoot("Los Santos")
    LV = {}
    LS = {}
    SF = {}
    Other = {}
    
    
    function displayLoadedRes ( res )
    	i = 1
    	for k,v in pairs(spawntables()) do
    		local zone = getZoneName( v[1],v[2],v[3], true )
    		if (zone == "Los Santos") then
    			LS[i] = tostring(v[1]..","..v[2]..","..v[3])
    			i = i+1
    		end
    	end
    end
    addEventHandler ( "onResourceStart", getRootElement(getThisResource(  )), displayLoadedRes )
    
    
    
    function getRandomLoot(location)
    	--local x,y,z = number[1], number[2], number[3]
    	if (location == "Los Santos") then
    		table = spawntables()[math.random ( #LS )]
    		return table
    	else
    		return "other"
    	end
    	--return LS
    end

    Maybe its useful to someone.

  2. Just now, Pirulax said:

    You should be able to send thru a table without a problem.

    I tried to, wasnt able, was just able to send a string, the table I was trying to send was for example:

    table = []
    table['x'] = x
    table['y'] = y
    table['z'] = z
    return table['x'],table['y'],table['z']

     

  3. 2 minutes ago, Pirulax said:

    Is the script you're trying to call the export from on server-side?
    Is the script where 'getRandomLoot' is on server-side?

    Yes, yes, just figured out that it seems I cant send a table through an export, I tried this:

     

        outputServerLog("X = "..exports["NTTC_Tables"]:getRandomLoot("Los Santos"))

    and on my function

    function getRandomLoot(location)
    	local number = table.random(locations_for_items_and_spawns)
    	--outputServerLog( number[1]..","..number[2]..","..number[3] )
    	 return "x,y,z"
    end

    result:

     Untitled.png

  4. Hello, I am trying to export a function called "getRandomLoot", which is in a resource name NTTC_Tables, I am trying to export this function to be able to use it on another resource, the function:

    function getRandomLoot(location)
    	local number = table.random(locations_for_items_and_spawns)
    	--outputServerLog( number[1]..","..number[2]..","..number[3] )
    	local x,y,z = number[1], number[2], number[3]
    	local position = getZoneName ( x, y, z, true )
    	table = []
    	table['x'] = x
    	table['y'] = y
    	table['z'] = z
    	return table
    end
    <meta>
    	<script src="async.lua" type="shared" />
    	<script src="client.lua" type="client" cache="false"/>
    	<script src="locations.lua" type="server"/>
    	<script src="server.lua" type="server"/>
      	<export function="getRandomLoot" type="server" />
      	<export function="spawntables" type="server" />
    </meta>

    This function returns what I want it to when I call it on the same file,  but when I try to call this function from another resource:

    local checkres = exports["NTTC_Tables"]:getRandomLoot("Los Santos") --doesnt work

    ERROR:

    ERROR: [NTTC]/NTTC_Account_Management/server.lua:78: attempt to call
    a nil value
    [09:06:41] ERROR: [NTTC]/NTTC_Account_Management/server.lua:75: call: failed to
    call 'NTTC_Tables:getRandomLoot' [string "?"]
    

    Line 79 is a timer: 

    function test()
      local checkres = exports["NTTC_Tables"]:getRandomLoot("Los Santos") --<<<<< line 75
      --outputServerLog("X = "..checkres['x']..", Y = "..checkres['y']..", Z ="..checkres['z'])
    end
    setTimer( test, 500, 5) --<<<< line 78

     

    I have no idea what is wrong, im running Ubuntu 18.04.1 LTS

     

    Thanks in advance :)

     

    EDIT: Found out that the problem is on my function "getRandomLoot" for some reason, it works in the resource no problem but when trying to call it, it shows the error message listed above, im trying to fix it on my own, will edit if I manage to fix it and will post the fix

    EDIT2: Tried removing the _ from the resource name, didnt fix

  5. 7 minutes ago, WorthlessCynomys said:

    onClientRender is an event, you have to handle with addEventHandler.

    
    addEventHandler("onClientRender", root, functionToCall);
    

    In the function it will call:

    
    function fadingImages()
      dxDrawImage(500, 500, 250, 250, "image1.png", 0, 0, 0, tocolor(255, 255, 255, 255), false);
      -- This line will draw the image (image1.png) on your monitor. It's left top corner will be at (500;500) pixel position and it will spread to the right 250 pixels and down 250 pixels. So it's right bottom corner will be at (750;750) pixel position on your screen. To make it transparent, you have to change the 4th, Alpha value in the tocolor function ( R(ed)G(reen)B(lue)A(lpha) ).
    end
    

    onClientRender gets called every time your PC refreshes/renders the game. If you play at 60 FPS(Frames per second), it means it gets called 60 times per second.

    Now using this knowledge you can make what I recommended:

    This code is NOT tested!

    
    Images = {
     {"image1.png", 255},
     {"image2.png", 0},
    };
    
    function fadeImages()
          
        -- || This part will do the transparency changes || --
        if (Images[1][2] > 0) then -- If the transparency of the first image is greater than none, we subtract 1 from it's value, making it more transparent.
           Images[1][2] = Images[1][2]-1; 
        end
          
        if (Images[2][2] < 255) then -- If the transparency of the second image is less then full, we add 1 to it's value, making it less transparent.
           Images[2][2] = Images[2][2]+1;
        end
          
        -- Doing the part above, will result in the two images changing each other with a fade effect.
          
        -- || This part will draw the 2 images on top of each other || --
    	dxDrawImage(500, 500, 250, 250, Images[1][1], 0, 0, 0, tocolor(255, 255, 255, Images[1][2]), false);
        dxDrawImage(500, 500, 250, 250, Images[2][1], 0, 0, 0, tocolor(255, 255, 255, Images[2][2]), false);
    end
    addEventHandler("onClientRender", root, fadeImages);
    

     

    Thank you so much for explaining this, i will try this and update my comment with the result, one more question not exactly related, is there a way to set a weapons alpha (a gun that i give with giveGun)? thank you :)

  6. 2 minutes ago, WorthlessCynomys said:

    I'm from phone, so I didn't read the code! 

    I would put the images and their alpha values in a table, like:

    
    Images = {
    {"image1", 255}, 
    {"image2", 0}, 
    } 
    

    And I would use 2 dxDrawImages using the alpha values attached to the images and I would change the image to be displayed while changing the numbers representing the alpha values. 

    Hope that you understand what I try to say. 

    Thanks, I do understand, what I dont understand is how can I fade out and fade in an image? i cant manage to understand how onclientrender could work

  7. Hello, I am trying to make a script that swaps the image on screen for a new one from a table I really am lost and dont have idea what to do next,

    local screenW, screenH = guiGetScreenSize()
    local randomize2 = math.random ( #Imagens )
    local alpha = 255
    local current_image = ""
    function ImageRender(image,alpha)
    	if getElementData (getLocalPlayer(  ),"logedin") == false or getElementData (getLocalPlayer(  ),"logedin") == nil then
    		current_image = guiCreateStaticImage(0, 0, screenWidth, screenHeight, tostring(Imagens[image]), false)
    		guiMoveToBack( current_image )
    		guiSetAlpha(current_image, alpha )
    	end
    end
    addEventHandler("onClientResourceStart", resourceRoot,ImageRender)
    function RenderImageSwap()
    	if getElementData (getLocalPlayer(  ),"logedin") == false or getElementData (getLocalPlayer(  ),"logedin") == nil then
    		if (alpha > 0) then
    			newAlpha = alpha < 25
    			if (newAlpha < 0) then
    				ImageRender(randomize2,255)
    			else
    				ImageRender(current_image,newAlpha)
    			end
    		end
    	end
    end
    setTimer( RenderImageSwap, 1000, 0)

    This is my code right know, which unfortunately, isnt working at all, does anyone know how to make a fade out an image (set alpha to alpha - 25.5 in a duration of 10 seconds for example) and if it reaches zero, it fades the next one in (set alpha of new image to alpha + 25.5 in a duration of 5 seconds for example)

     

    thanks :) I really tried my best but I dont know what functions to use, was thinking on getCurrentTick but I dont get how it works

  8. 4 hours ago, KnucklesSAEG said:

    its cool but do you know what revive system im talking? let me explain
    1. Cop killed criminal, criminal is sleeping
    2.If a criminal or someone else clicked criminal while hes still sleeping timer starts
    3. timer ends and criminal is alive again

    well you just have to adapt the code I gave you :) just use getDistanceBetweenPoints3D and i dont know what you use to know if its a criminal that is trying to revive

  9. Just now, Leo Messi said:

    Any example?

    Forgive me, I wasnt at home, I will work on an example and I will send it to you, i will use 1920x1080 and make calculations there, theoretically if I do it relative it should work on any res, i will update my comment when its ready.

    • Thanks 1
  10. 9 hours ago, Leo Messi said:

    So simple and easy, I want to make something like;

    for example; I created an icon (static image) and if I clicked near this image it will add event on it like onClientGUIClick and get a message with 'You clicked on x image' for example.

    Just like CIT rapid transportation map to be clear.

    You could create a PNG image thats bigger than the original one with transparency, have an onclick for it

     

  11. I mean, there was no need to humilliate him, you could of told him more or less what functions to use,

    here, tested it, 

    CLIENT:

    function math.round(number)
        local _, decimals = math.modf(number)
        if decimals < 0.5 then return math.floor(number) end
        return math.ceil(number)
    end
    
    
    local revive_percentage = 0
    local timer = 0
    function add_percentage_per_second()
      if (revive_percentage < 100) then
        revive_percentage = revive_percentage + 1.25
        if (revive_percentage >= 100) then
          setPedAnimation(getLocalPlayer())
          removeEventHandler("onClientRender", getRootElement(), start_revive_process)
          revive_percentage = 0
        end
      end
    end
    
    
    local screenW, screenH = guiGetScreenSize()
    function start_revive_process()
        if (revive_percentage == 0) then
          setTimer(add_percentage_per_second,62.5,80) --ads a timer that executes once every second for 5 seconds, adding 20% each time.
          setPedAnimation(getLocalPlayer(  ),"ped","FLOOR_hit_f",-1,false) --start anim
          revive_percentage = revive_percentage+1
        end
        dxDrawText(math.round(revive_percentage).."%", screenW * 0.4802, screenH * 0.9500, screenW * 0.5198, screenH * 0.9694, tocolor(0, 0, 0, 255), 1.00, "default", "center", "center", false, false, true, false, false)
        dxDrawRectangle(screenW * 0.4219, screenH * 0.9491, screenW * 0.1568, screenH * 0.0204, tocolor(255, 255, 255, 255), false)
        dxDrawRectangle(screenW * 0.4219, screenH * 0.9491, screenW * revive_percentage/638, screenH * 0.0204, tocolor(255, 0, 0, 255), false)
    end
    
    function StartReviveClient()
      addEventHandler( "onClientRender", getRootElement(), start_revive_process )
    end
    addEvent( "startrevive", true )
    addEventHandler( "startrevive", getRootElement(  ), StartReviveClient )

    and add this on your server side, I imagine you know how to adapt it:

    function startRevive(playerSource, commandName)
    	triggerClientEvent( getRootElement(  ), "startrevive", playerSource) --this calls the client event
    end
    addCommandHandler( "revive", startRevive)

     

    how does it work:

    1.) it creates a timer that executes once every 62.5 milliseconds 80 times, which is 5 seconds (62.5 x 80 = 5000) to function "add_percentage_per_second (ignore function name, wanted to do it a little more fast-paced,

    1.25 percent 80 times equals 100%

    if you want to change the total time of revive, you now know the math needed :)

     

    WARNING: THIS IS NOT THE MOST OPTIMIZED WAY TO DO IT

    I did this in 10 minutes, hopefully it helps :)

  12. This is because DayZ gamemode has a protection, you should look for a timer in your gamemode that does something like this

    local skin = getElementData(player,"skin")
    if (skin ~= getElementModel(player) then
        setElementModel(player,skin)
    end

    if you find this, check the element data, and just add

    setElementData(player,"DATANAME",YOURSKINID)

    example, if your DayZ protection dataname is "DayZSkin", and the skin you set is 150

    setElementData(player,"DayZSkin",150)

     

    FULL CODE With dataname "DayZSkin":

    newskin = createMarker ( 1856.0751, 851.0827, 9.408, "cylinder", 1.5, 255, 255, 0, 170 )
    
    function skin(hitPlayer)
        if getElementType(hitPlayer) == "player" then
           setPlayerSkin ( hitPlayer, 211 )
           setElementData( hitPlayer, "DayZSkin",211) --this is what you must add.
        end
    end
    addEventHandler ( "onMarkerHit", newskin, skin )

     

  13. Hello, I dont know if someone has posted this here before, I searched and wasn´t able to find anyone having this problem, my problem is, I have a DayZ script, which I have been modifying, but since the start some of my players were not able to click on the GUI from the Inventory, nor the gang system, nor the login panel, this just happens with some players, for example, everything works on my computer, but with a virtual machine, I am not able to click on anything, here is a video of what I am talking about, I have no idea why this is caused, there is no related problems in my debugscript, actually, there is only 1 thing that is wrong in my server and been lazy to fix it, just a warning and I am missing an event client side which has nothing to do with this, since it affects various resources, the only way I´ve been able to fix this is by restarting the resource, that seems to fix the issue but I cant restart every time someone logs in:

    2018-08-08_23-39-07.png

    VIDEO:

    VIDEO (dont know the tags to embed video here)

    Any help is appreciated :)

  14. 19 hours ago, Hale said:

    Try using setElementFrozen instead of attaching the vehicle and object, and a short setTimer for ~500ms.

    Hello, sorry for late reply, just tried using setElementFrozen, and it just freezes the vehicle and the elevator object goes through the car and goes up

    20 hours ago, idarrr said:

    Maybe use setElementCollisionsEnabled to disable physical interaction between vehicle and an object. 

    Hello, sorry for late reply, tried this yesterday and the problem persists

    Hello, I fixed it in a funny way, what I did is add a second elevator object, and made its alpha 0 (invisible) and attached it to the original elevator, it works now, I´ll leave the code for whoever needs it

    local elevatorcolshape = createColRectangle ( 1666, 1188, 30.6, 20.0 )
    local elevator = createObject(3115, 1676.9, 1197.8, 24.2)
    local elevatorclone = createObject(3115, 1676.9, 1197.8, 24.2)
    attachElements(elevatorclone,elevator )
    setElementAlpha(elevatorclone, 0 )
    local elevatorSTATE = "techo"
    function elevator1337(source,command,goto )
    	local playeraccount = getPlayerAccount( source )
    	local accname = getAccountName( playeraccount )
    	local playerx,playery,playerz = getElementPosition( source )
    	local elevatorx,elevatory,elevatorz = getElementPosition(elevator)
    	local distance = getDistanceBetweenPoints3D(playerx, playery, playerz, elevatorx,elevatory,elevatorz )
    	if (accname == "knight") then
    		if (goto) then
    			if getPedOccupiedVehicle ( source ) then
    				outputDebugString( distance )
    				-- get the vehicle element
    				local playerVehicle = getPlayerOccupiedVehicle ( source )
    				attachElements(playerVehicle, elevator,0,0,1)
    				-- get the current freeze status
    				setElementFrozen ( playerVehicle, true )
    				setTimer(setElementFrozen, 1950, 1, playerVehicle,false )
    				setTimer(detachElements, 1950, 1, playerVehicle,elevator )
    			end
    			if (goto == "piso") then
    				if (elevatorSTATE ~= "piso") then
    					if (isElementWithinColShape(source, elevatorcolshape ) and playerz < 20) then
    						outputChatBox( "[BASE 1337]: NO PUEDES LLAMAR EL ELEVADOR PORQUE TE VA A APLASTAR",source,255,0,0,true )
    					else
    						-- local isinveh = isPedInVehicle( source )
    						-- if (isinveh) then
    						-- 	attachElements(getPedOccupiedVehicle(source),elevator,0,0,15)
    						-- end
    						elevatorSTATE = "piso"
    						outputChatBox( "[BASE 1337]: ELEVADOR MOVIENDOSE A: "..goto,source,0,255,0,true )
    						moveObject( elevator, 500, 1676.9, 1197.8, 18.2)
    						setTimer(moveObject, 750, 1, elevator, 500, 1685.9, 1197.8, 18.2)
    						setTimer(moveObject, 1500, 1, elevator, 500, 1685.9, 1197.8, 9.7)
    						-- if (isinveh) then
    						-- 	setTimer(detachElements,3000, 1,getPedOccupiedVehicle(source),elevator)
    						-- end
    					end
    				else
    					outputChatBox( "[BASE 1337]: EL ELEVADOR YA ESTA EN: "..goto,source,255,0,0,true )
    				end
    			end
    
    			if (goto == "techo") then
    				if (elevatorSTATE ~= goto) then
    						-- local isinveh = isPedInVehicle( source )
    						-- if (isinveh) then
    						-- 	attachElements(getPedOccupiedVehicle(source),elevator,0,0,15)
    						-- end
    					elevatorSTATE = goto
    					outputChatBox( "[BASE 1337]: ELEVADOR MOVIENDOSE A: "..goto,source,0,255,0,true )
    					moveObject( elevator, 500, 1685.9, 1197.8, 18.2)
    					setTimer(moveObject, 750, 1, elevator, 500, 1676.9, 1197.8, 18.2)
    					setTimer(moveObject, 1500, 1, elevator, 500, 1676.9, 1197.8, 24.2)
    					-- if (isinveh) then
    					-- 	setTimer(detachElements,3000, 1,getPedOccupiedVehicle(source),elevator)
    					-- end
    				else
    					outputChatBox( "[BASE 1337]: EL ELEVADOR YA ESTA EN: "..goto,source,255,0,0,true )
    				end
    			end
    
    		end
    	end
    end
    addCommandHandler("elev", elevator1337 )

    Thanks for the help guys :)

    • Like 1
  15. Hello, I am trying to make an elevator script using an createObject, moveObject and attachElements to attach a vehicle to the object, the problem is, the vehicle goes through the object even if I add an Z offset, this is my code:

    
    local elevatorcolshape = createColRectangle ( 1666, 1188, 30.6, 20.0 )
    local elevator = createObject(3115, 1676.9, 1197.8, 24.2)
    local elevatorSTATE = "techo"
    function elevator1337(source,command,goto )
    	local playeraccount = getPlayerAccount( source )
    	local accname = getAccountName( playeraccount )
    	local playerx,playery,playerz = getElementPosition( source )
    	local elevatorx,elevatory,elevatorz = getElementPosition(elevator)
    	if (accname == "knight") then
    		if (goto) then
    			if (goto == "piso") then
    				if (elevatorSTATE ~= "piso") then
    					if (isElementWithinColShape(source, elevatorcolshape ) and playerz < 20) then
    						outputChatBox( "[BASE 1337]: NO PUEDES LLAMAR EL ELEVADOR PORQUE TE VA A APLASTAR",source,255,0,0,true )
    					else
    						local isinveh = isPedInVehicle( source )
    						if (isinveh) then
    							attachElements(getPedOccupiedVehicle(source),elevator)
    						end
    						elevatorSTATE = "piso"
    						outputChatBox( "[BASE 1337]: ELEVADOR MOVIENDOSE A: "..goto,source,0,255,0,true )
    						moveObject( elevator, 1000, 1676.9, 1197.8, 18.2)
    						setTimer(moveObject, 1250, 1, elevator, 1000, 1685.9, 1197.8, 18.2)
    						setTimer(moveObject, 2500, 1, elevator, 1000, 1685.9, 1197.8, 9.7)
    						if (isinveh) then
    							setTimer(detachElements,3000, 1,getPedOccupiedVehicle(source),elevator)
    						end
    					end
    				else
    					outputChatBox( "[BASE 1337]: EL ELEVADOR YA ESTA EN: "..goto,source,255,0,0,true )
    				end
    			end
    
    			if (goto == "techo") then
    				if (elevatorSTATE ~= goto) then
    						local isinveh = isPedInVehicle( source )
    						if (isinveh) then
    							attachElements(getPedOccupiedVehicle(source),elevator,0,0,3)
    						end
    					elevatorSTATE = goto
    					outputChatBox( "[BASE 1337]: ELEVADOR MOVIENDOSE A: "..goto,source,0,255,0,true )
    					moveObject( elevator, 500, 1685.9, 1197.8, 18.2)
    					setTimer(moveObject, 750, 1, elevator, 500, 1676.9, 1197.8, 18.2)
    					setTimer(moveObject, 1500, 1, elevator, 500, 1676.9, 1197.8, 24.2)
    					if (isinveh) then
    						setTimer(detachElements,3000, 1,getPedOccupiedVehicle(source),elevator)
    					end
    				else
    					outputChatBox( "[BASE 1337]: EL ELEVADOR YA ESTA EN: "..goto,source,255,0,0,true )
    				end
    			end
    		end
    	end
    end
    addCommandHandler("elev", elevator1337 )

    I would like to know if there is a way to avoid the car going through the item and fall, thanks

  16. You could use string.count to check if "amount" contains a negative "-" symbol, and use Split to remove it from the string, 

    EDIT:

    function string.count (text, search)
    	if ( not text or not search ) then return false end
    	
    	return select ( 2, text:gsub ( search, "" ) );
    end
    
    addCommandHandler("pay",
    	function(player, cmd, name, amount)
    		local amount = tonumber(amount)
    		if name and amount then
    			local target = findPlayer(name)
    			local money = getPlayerMoney(target)
          		if (string.count(amount,"-")) then
            		amount = str:gsub('%A',amount)
            	end
    			if money >= amount then
    				takePlayerMoney(player, amount)
    				givePlayerMoney(target, amount)
    				outputChatBox("#FFffFF Átutaltál neki: #c8c8c8" .. getPlayerName(target) .. " #0088ff" .. amount .. " Forintot.", player, 0, 255, 0, true)
    				outputChatBox("#c8c8c8 " .. getPlayerName(player) .. " #FFffFFutalt neked #0088ff" .. amount .. " Forintot.", target, 0, 255, 0, true)
    			else
    				outputChatBox("#FFffFF Nincs elég pénzed.", target, 255, 0, 0, true)
    			end
    		end
    	end
    )

    Try this

     

×
×
  • Create New...