Jump to content

Protagonist95

Members
  • Posts

    53
  • Joined

  • Last visited

Posts posted by Protagonist95

  1. 1 hour ago, NeXuS™ said:
    
    mytable = {}
    
    function insertGangTable()
    	local connection = dbConnect( "sqlite", "data.db" )
    	local gang_list = dbQuery( connection, "SELECT id,name FROM gang_list" )
    	local gang_list_result = dbPoll(gang_list, -1)
    
    	if gang_list_result then
    		for _,row in ipairs( gang_list_result ) do
    			mytable[row["id"]] = row["name"] --- { [id] = "name" }
    		end
    	end
    end
    

     

    Thakns m8

  2. Can you give me a hint how do i insert values into table?

    Heres the code i wrote

    mytable = {}
    
    function insertGangTable()
    local connection = dbConnect( "sqlite", "data.db" )
    local gang_list = dbQuery( connection, "SELECT id,name FROM gang_list" )
    local gang_list_result = dbPoll(gang_list, -1)
    
    if gang_list_result then
    	for _,row in ipairs( gang_list_result ) do
    		for _,value in pairs( row ) do
    			table.insert(mytable,...) --- { [id] = "name" }
    		end
    	end
    end
    end

     

  3. How can i pass serverside table to client?

    --Serverside
    function selectMembersList ( playerSource )
      local connection = dbConnect( "sqlite", "data.db" )
     	local qh = dbQuery( connection, "SELECT member_login FROM gang_members WHERE gang_id = ?",selectGangIDBySerial(getPlayerSerial(playerSource)))
      	local result = dbPoll ( qh, -1 )
    
      	local group_members = {}
    
    	  for _, row in ipairs ( result ) do
    	  	local player = getPlayerFromSerial(row["member_login"])
            	table.insert(group_members,getPlayerSerial(player))
          end
    	 return group_members	--table is ok at this point
    end
    addEvent( "selectMembersListEvent", true )
    addEventHandler( "selectMembersListEvent", resourceRoot, selectMembersList )
    
    
    --Clientside
    
    function addGroupMembers()
    group_members = triggerServerEvent("selectMembersListEvent",resourceRoot,getLocalPlayer())
    
    	for _,value in ipairs(group_members) do -- table expected,got boolean
    		outputChatBox(value)
    	end
    end
    addEventHandler( "onClientResourceStart",resourceRoot,addGroupMembers)

     

  4. 33 minutes ago, TheMOG said:

    The problem is with the math i think, cuz no debugerror

    function hoursToDays(commandName, hour)
    local conv_hour = tonumber(hour)
    local day = math.floor(hour / 24)
    outputChatBox("Days: " .. tostring(day) .. " Hours: " .. tostring(conv_hour - (day * 24)))
    end
    addCommandHandler ( "tm", hoursToDays )

     

  5. Hello.Does anybody know how to make doublesided marker (talking about checkpoint one,not cylinder) or just recommend the way to create a really large one(size > 300 units) that will not fade away after walking some distance?

  6. 6 minutes ago, tosfera said:

    That's not working, might want to attach an ID to the object/colshape and do the part where you delete everything on the server. This does mean that only 1 player can get the actual object from that colshape. If you want every client to be able to do so.. you should create the colshapes and objects on the client's side. ^_^

    Ok il try

  7. 6 minutes ago, tosfera said:

    Are the objects created on the client's side or server sided? Maybe, just maybe, we're not allowed to delete server sided objects in our client.

    I was just thinking about it,and yes.I spawn objects on server side and try to delete them on client side.

  8. 4 minutes ago, tosfera said:

    You want to remove the attached element and the colshape? You could try something like this then:

    
    function destroyObject ( theElement, matchingDimension )
        if ( theElement == getLocalPlayer() ) then
            local tmpObject = getElementAttachedTo ( source );
            if ( tmpObject ) then
                -- detach everything from both elements
                detachElements ( tmpObject );
                detachElements ( source );
    
                -- destroy both elements
                destroyElement ( tmpObject );
                destroyElement ( source );
            end
        end
    end
    addEventHandler ( "onClientColShapeHit", getRootElement(), destroyObject );
    

     

    Okay,the detach part is successful,but the destroy isn't.Still dont know why...

    Any ideas?

  9. 30 minutes ago, tosfera said:

    You're unable to reposition an element when it's attached. If you're attaching an object to another element, or any element to another element. it becomes a child element from the attached to element. Which means; if the parent (the attached to element) gets removed, they get detatched. If you're trying to destroy the element you're attaching, you should first make it an element of it's own again. Else the parent will have trouble seeking it's child.

    The attachment functions in MTA have a higher priority than any destroy function on the attached element.

    Okay,but in my situation i would like to remove both.Btw not working.:D

  10. 39 minutes ago, tosfera said:

    There is a way to make it cleaner, that is for sure. Try something like this;

    
    local tmpColshape = nil;
    addEventHandler ( "onClientColShapeHit", getRootElement(),
        function ( theElement )
            if ( theElement == getlocalPlayer() ) then
                tmpColshape = source;
                addEventHandler ( "onClientKey", getRootElement(), setItemData );
            end
        end
    );
    
    addEventHandler ( "onClientColShapeLeave", getRootElement(),
        function ( theElement )
            if ( theElement == getlocalPlayer() ) then
                tmpColshape = nil;
                removeEventHandler ( "onClientKey", getRootElement(), setItemData );
            end
        end
    );
    
    function setItemData ( button, pressed )
        if ( button == "mouse3" and pressed ) then
            local tmpObject = getElementAttachtedTo ( tmpColshape );
            setElementData ( getLocalPlayer(), "item", getElementData ( tmpObject, "item" ) );
            removeEventHandler ( "onClientKey", getRootElement(), setItemData );
        end
    end
    

    Maybe it's also smart to see if the colshape has an object attached to it in the onClientColShapeHit already. To avoid warnings and such.

    Not working.Error in getLocalPlayer lines -- attempt to call global

  11. 24 minutes ago, tosfera said:

    First of all, you're not even checking if you got an object. Does your console say something about it?

    Second of all, always detach an object before trying to destroy it. It's not going to work without.

    
    function destroyObject ( theElement, matchingDimension )
        if ( theElement == getLocalPlayer() ) then
            local tmpObject = getElementAttachedTo ( source );
            if ( tmpObject ) then
                detachElements ( tmpObject, source );
                destroyElement ( tmpObject );
            end
        end
    end
    addEventHandler ( "onClientColShapeHit", getRootElement(), destroyObject );
    

     

    Why do you need to detach elements?
     

  12. Is it possible to make this code simplyer?

    function onClientColHit(theElement, matchingDimension)
    	local col = source
    	if ( theElement == getLocalPlayer()) then -- if player hit colshape
    		addEventHandler( "onClientKey", getRootElement(), function(button,press)
    			if (button == "mouse3") then
    				setElementData(getLocalPlayer(),"item",getElementData(getElementAttachedTo(col),"item")) -- set elementData of and object in colshape
    			end
    			end)
    	end
    end
    addEventHandler("onClientColShapeHit",getRootElement(),onClientColHit)

     

  13. cache = false

    20 minutes ago, xRGamingx said:

    Hello friends, I have my server, and I want to do something,

     

    ejmp:

    If a player steals my script, and I want that script to not work on your server, I want the script to work only on my server

    how do I do that?

     

    I say this because I used some compiled script from a server and at the initial script on my server the script stops only

    cache = false?

  14. What may be the problem?

    function destroyObject( theElement, matchingDimension )
    	local object = getElementAttachedTo(source) -- object attached to colshape
    	if (theElement == getLocalPlayer()) then -- if player hits colshape
    		destroyElement(object) -- destroy object within colshape
    	end
    end
    addEventHandler("onClientColShapeHit",getRootElement(),destroyObject)

     

  15. 2 minutes ago, iPrestege said:

    Try to put a string in the 100 part so it should looks like '100' .

    I see your point,but thing is not in the numbers or strings.Lets assume that i would deal with large table which includes {1337,"something",true} or something like that.That wont solve the problem.

  16. 2 minutes ago, MR.S3D said:
    
    Parameters = {
    {1337,"data","data"}, -- works
    
    {1338,"data1","data1"}, -- works
    
    {1339,"data2",100} -- doesn't work,duno why
    
    }
    
    objects = {
    	{1337,23.15625,-5.677734375,3},
    	{1338,19.15625,-5.677734375,3},
    	{1339,15.15625,-5.677734375,3}
    }
    
    
    function spawnLoot() 
    	for i,k in ipairs(objects) do
    		local obj
    		local col
    		local id = k[1]
    		obj = createObject(k[1],k[2],k[3],k[4])
    		col = createColCuboid(k[2],k[3],k[4],1.6,1.6,1.6)
    		if(obj) then -- if it exists then
    			setElementData(col,"col",true)
    			setElementData(obj,"loot",true)
    			attachElements(col,obj,-0.7,-0.7,-0.5)
    			setElementCollisionsEnabled(obj,false)
    		end 
    		for index,key in ipairs(Parameters) do 
    			if id == key[1] then
    				setElementData(obj,key[2],key[3])
    				outputChatBox("ID added")
    				break
    			end
    		end		
    	end
    end
    addEventHandler ( "onResourceStart", getResourceRootElement(), spawnLoot)
    
    function onColEnter ( thePlayer )
    	if (isElement(thePlayer) and getElementType(thePlayer) == "player") then
    		local item = getElementsWithinColShape (source, "object")
    		if isElementWithinColShape (thePlayer,source) and getElementData(source,"col") == true then
    			setElementData(thePlayer,"inLoot",true)
    			outputChatBox('Enter ColShape')			
    			for i,k in ipairs(item) do 
    				local data 
    				for index,key in ipairs(Parameters) do
    					data = getElementData(k,tostring(key[3]))
    					if data ~= false then
    						outputChatBox(tostring( data ))
    					end
    				end
    			end
    		end
    	end	
    end
    addEventHandler ("onColShapeHit",resourceRoot, onColEnter)
    
    function onColLeave ( thePlayer )
    	if (isElement(thePlayer) and getElementType(thePlayer) == "player") then
            if getElementsWithinColShape ( source, "player" ) then
            	setElementData(thePlayer,"inLoot",false)
    			outputChatBox('Leave ColShape')
            end
    	end	
    end
    addEventHandler ("onColShapeLeave", resourceRoot, onColLeave)
    
    
      
    

     

    Not working :D

  17. 6 minutes ago, MR.S3D said:
    
    Parameters = {
    {1337,"data","data"}, -- works
    
    {1338,"data1","data1"}, -- works
    
    {1339,"data2",100} -- doesn't work,duno why
    
    }
    
    objects = {
    	{1337,23.15625,-5.677734375,3},
    	{1338,19.15625,-5.677734375,3},
    	{1339,15.15625,-5.677734375,3}
    }
    
    
    function spawnLoot() 
    	for i,k in ipairs(objects) do
    		local obj
    		local col
    		local id = k[1]
    		obj = createObject(k[1],k[2],k[3],k[4])
    		col = createColCuboid(k[2],k[3],k[4],1.6,1.6,1.6)
    		if(obj) then -- if it exists then
    			setElementData(col,"col",true)
    			setElementData(obj,"loot",true)
    			attachElements(col,obj,-0.7,-0.7,-0.5)
    			setElementCollisionsEnabled(obj,false)
    		end 
    		for index,key in ipairs(Parameters) do 
    			if id == key[1] then
    				setElementData(obj,key[2],key[3])
    				outputChatBox("ID added")
    				break
    			end
    		end		
    	end
    end
    addEventHandler ( "onResourceStart", getResourceRootElement(), spawnLoot)
    

     

    Not working.Heres whole script if it somehow helps you

    objects = {
    	{1337,23.15625,-5.677734375,3},
    	{1338,19.15625,-5.677734375,3},
    	{1339,15.15625,-5.677734375,3}
    }
    
    Parameters = {
    	{1337,"data","data"},
    	{1338,"data1","data1"},
    	{1339,"data2",100}
    }
    
    function spawnLoot() 
    	for i,k in ipairs(objects) do
    		local obj
    		local col
    		local id = k[1]
    		obj = createObject(k[1],k[2],k[3],k[4])
    		col = createColCuboid(k[2],k[3],k[4],1.6,1.6,1.6)
    		if(obj) then -- if it exists then
    			setElementData(col,"col",true)
    			setElementData(obj,"loot",true)
    			attachElements(col,obj,-0.7,-0.7,-0.5)
    			setElementCollisionsEnabled(obj,false)
    		end 
    		for index,key in ipairs(Parameters) do 
    			if id == key[1] then
    				setElementData(obj,key[2],key[3])
    				outputChatBox("ID added")
    				break
    			end
    		end		
    	end
    end
    addEventHandler ( "onResourceStart", getResourceRootElement(), spawnLoot)
    
    function onColEnter ( thePlayer )
    	local item = getElementsWithinColShape (source, "object")
    	if isElementWithinColShape (thePlayer,source) and getElementData(source,"col") ~= false then
    	setElementData(thePlayer,"inLoot",true)
    		for i,k in ipairs(item) do 
    			for index,key in ipairs(Parameters) do
    				if getElementData(k,key[3]) ~= false then
    				outputChatBox(tostring(getElementData(k,key[3])))
    			end
    			end
    		end
        end
    end
    addEventHandler ("onColShapeHit",getResourceRootElement(), onColEnter)
    
    function onColLeave ( thePlayer )
            if getElementsWithinColShape ( source, "player" ) then
            	setElementData(thePlayer,"inLoot",false)
            end
    end
    addEventHandler ("onColShapeLeave", getRootElement(), onColLeave)
    

     

×
×
  • Create New...