Jump to content

createColSphere


Recommended Posts

Всем привет!Сегодня хотел сделать одну вещь , но у меня ничего не получилось (надо сделать так , чтоб персонаж подходил к объекту и появляется какой-нибудь действие).Объекты создаются через сервер и при помощи createColSphere , сохраняются в массив.У каждого объекта своё действие как такое реализовать ?

Link to comment
function f1() end 
function f2() end 
  
local t = {  
  [1] = { col = createColSphere( ... ), funct = f1 }; 
  [2] = { col = createColSphere( ... ), funct = f2 }; 
  } 
  
for _, data in pairs( t ) do 
  addEventHandler( 'onColShapeHit', data.col, data.funct ) 
end 
  

Спасибо , а как сделать чтоб ColSphere динамично создавались ?

Link to comment
function f1() end 
function f2() end 
  
local t = { 
  [1] = { col = createColSphere( ... ), funct = f1 }; 
  [2] = { col = createColSphere( ... ), funct = f2 }; 
  } 
  
function foo() 
  -- ... 
  addEventHandler( 'onColShapeHit', t[1].col, t[1].funct ) 
  -- ... 
end 

Или так...

  
CColShape = {} 
CColShape.__index = CColShape 
  
function CColShape:new( fX, fY, fZ, fR, fFunction ) 
  local o = { col = createColSphere( fX, fY, fZ, fR ), funct = fFunction } 
  return setmetatable( o, self ) 
end 
  
function CColShape:setActive( state ) 
  if state then 
     addEventHandler( 'onColShapeHit', self.col, self.funct ) 
  else 
     removeEventHandler( 'onColShapeHit', self.col, self.funct ) 
  end 
end 
  
function CColShape:destroy( ) 
  destroyElement( self.col ) 
  self = nil 
end 
  
function f1() end 
function f2() end 
  
local cols = { 
  city = CColShape:new( 100, 20, 50, 10, f1 ) 
  bank  = CColShape:new( 50, 45, 80, 5, f2 ) 
  } 
  
function foo() 
  -- ... 
   cols.bank:setActive( true ) 
  -- .. 
end 
  

Link to comment
function f1() end 
function f2() end 
  
local t = { 
  [1] = { col = createColSphere( ... ), funct = f1 }; 
  [2] = { col = createColSphere( ... ), funct = f2 }; 
  } 
  
function foo() 
  -- ... 
  addEventHandler( 'onColShapeHit', t[1].col, t[1].funct ) 
  -- ... 
end 

Или так...

  
CColShape = {} 
CColShape.__index = CColShape 
  
function CColShape:new( fX, fY, fZ, fR, fFunction ) 
  local o = { col = createColSphere( fX, fY, fZ, fR ), funct = fFunction } 
  return setmetatable( o, self ) 
end 
  
function CColShape:setActive( state ) 
  if state then 
     addEventHandler( 'onColShapeHit', self.col, self.funct ) 
  else 
     removeEventHandler( 'onColShapeHit', self.col, self.funct ) 
  end 
end 
  
function CColShape:destroy( ) 
  destroyElement( self.col ) 
  self = nil 
end 
  
function f1() end 
function f2() end 
  
local cols = { 
  city = CColShape:new( 100, 20, 50, 10, f1 ) 
  bank  = CColShape:new( 50, 45, 80, 5, f2 ) 
  } 
  
function foo() 
  -- ... 
   cols.bank:setActive( true ) 
  -- .. 
end 
  

Спасибо

Link to comment

Странно , отдельно работает , а вот когда пытаюсь ввести в скрипт не получается.Вот скрипт:

Клиент

function guiNoteMenu() 
    if(guiGetVisible (winNote) == true) then 
        guiSetVisible ( winNote, false ) 
        showCursor(false) 
        notePage = guiGridListGetSelectedItem(noteList) 
        saveGridText() 
        guiSetInputEnabled(false) 
    else 
        local x, y = guiGetScreenSize() 
        winNote = guiCreateWindow (x / 2 - 450, y / 2 - 350, 620, 520, "Тетрадь", false) 
            guiWindowSetSizable(winNote,false) 
        noteMemo = guiCreateMemo ( 0.03, 0.05, 0.75, 0.85, "", true, winNote ) 
        setGridText() 
        noteList = guiCreateGridList ( 0.79, 0.05, 0.18, 0.85, true, winNote ) 
            noteColumn = guiGridListAddColumn ( noteList, "Страницы", 0.90 ) 
            guiGridListSetSortingEnabled ( noteList, false ) 
            pageMemo() 
            addEventHandler ( "onClientGUIClick", noteList, setGridText) 
        button = {} 
        button.Save = guiCreateButton ( 0.80, 0.92, 0.15, 0.06, "Сохранить", true, winNote) 
            addEventHandler ( "onClientGUIClick", button.Save, saveGridText) 
            addEventHandler ( "onClientGUIClick", button.Save, saveFile) 
        button.Delete = guiCreateButton (0.03, 0.92 , 0.15, 0.06 , "Вырвать", true,winNote) 
            addEventHandler ( "onClientGUIClick", button.Delete, message) 
        guiSetVisible ( winNote, true ) 
        guiGridListSetSelectedItem(noteList,notePage,noteColumn) 
        showCursor(true) 
        guiSetInputEnabled(true) 
    end 
end 
  
function message() 
    if( guiGetVisible (winNote) == true) then 
        if( guiGetVisible (winMessage) == false) then 
            local x,y = guiGetPosition(winNote,false) 
            winMessage = guiCreateWindow(x,y+200,600,100,"Вы уверены ?",false) 
                local buttons = {} 
                buttons.Yes = guiCreateButton(0.10,0.50,0.30,0.30,"Да",true,winMessage) 
                    addEventHandler ( "onClientGUIClick", buttons.Yes, giveServerFile) 
                buttons.No = guiCreateButton(0.60,0.50,0.30,0.30,"Нет",true,winMessage) 
                    addEventHandler ("onClientGUIClick", buttons.No, closeMessage) 
        else 
            guiSetVisible ( winMessage, false ) 
        end 
    end 
    function closeMessage() 
        guiSetVisible(winMessage,false) 
    end 
end 
notePageList = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18} 
function pageMemo() 
    if ( noteColumn ) then 
        for i=1,18 do  
            row = guiGridListAddRow ( noteList ) 
            guiGridListSetItemText ( noteList, row, noteColumn, "Страница "..i, false, false ) 
        end 
    end 
     
end 
function setGridText() 
    for i=0,18 do  
        if(guiGridListGetSelectedItem(noteList) == i) then 
            guiSetText(noteMemo,notePageList[i+1]) 
        end 
    end 
end 
function saveGridText() 
    for i=0,18 do  
        if(guiGridListGetSelectedItem(noteList) == i) then 
            notePageList[i+1] = guiGetText(noteMemo) 
        end 
    end 
end 
function saveFile() 
    for i=0,18 do 
        local newFile = fileCreate(getPlayerName(getLocalPlayer())..i..".txt")                 
        if (newFile) then                                        
            fileWrite(newFile, notePageList[i+1])         
            fileClose(newFile)                                
        end 
    end 
end 
addEventHandler( "onClientResourceStop", getRootElement(), saveFile ) 
function loadFile() 
    for i=0,18 do 
        local buffer = {} 
        local newFile = fileOpen(getPlayerName(getLocalPlayer())..i..".txt",true) 
        if (newFile) then 
            buffer[i] = fileRead(newFile,1000)   
            notePageList[i+1] = buffer[i]       
            fileClose(newFile)                                
        end 
    end 
end 
addEventHandler( "onClientResourceStart", getRootElement(),loadFile) 
function giveServerFile() 
    local px, py, pz = getElementPosition ( getLocalPlayer ( ) ) 
    triggerServerEvent ( "saveNameFile", localPlayer,guiGetText(noteMemo),px, py, pz) 
    guiSetText(noteMemo,"") 
    saveGridText() 
    guiSetVisible ( winMessage, false ) 
end 
function guiNoteRead() 
    if(guiGetVisible (winReader) == true) then 
        guiSetVisible ( winReader, false ) 
        showCursor(false) 
    else 
        local x, y = guiGetScreenSize() 
        winReader = guiCreateWindow (x / 2 - 350, y / 2 - 250, 620, 520, "Чтение", false) 
            guiWindowSetSizable(winReader,false) 
            guiSetVisible ( winReader, true ) 
        readMemo = guiCreateMemo ( 0.03, 0.03, 0.94, 0.95, "", true, winReader ) 
        local buttonclose = guiCreateButton(0.80,0.90,0.20,0.10,"Закрыть",true,readMemo) 
            addEventHandler ("onClientGUIClick", buttonclose,closeReader) 
        showCursor(true) 
    end 
end 
function closeReader() 
    guiSetVisible ( winReader, false ) 
    showCursor(false) 
end 
function getServerFile(buffer) 
    guiNoteRead() 
    guiSetText(readMemo,buffer) 
end 
addEvent( "onGetServerFile", true ) 
addEventHandler( "onGetServerFile", getRootElement(), getServerFile ) 
bindKey("f3","down",guiNoteMenu) 

Сервер:

id = 0 
pickid = {} 
objid = {} 
function noteSave(memFile,x,y,z) 
    local check = fileExists(id..".txt") 
        if check then  
            --outputChatBox("Такой файл существует!",player) 
            id = id + 1 
            local newFile = fileCreate(id..".txt") 
            if (newFile) then 
                fileWrite(newFile, memFile ) 
                fileClose(newFile) 
            end 
        else 
            --outputChatBox("Такого файла не существует!",player) 
            id = 0 
            local newFile = fileCreate(id..".txt") 
            if (newFile) then 
                fileWrite(newFile, memFile ) 
                fileClose(newFile) 
            end 
        end 
end 
addEvent( "saveNameFile", true ) 
addEventHandler( "saveNameFile", root, noteSave ) 
function  pageGiveClient(pageid) 
    local newFile = fileOpen(pageid..".txt") 
    if(newFile) then 
        local buffer = fileRead(newFile, 100) 
        triggerClientEvent ( "onGetServerFile", getRootElement(), buffer ) 
        fileClose(newFile) 
    end 
end 
--addCommandHandler ( "pagive", pageGiveClient ) 
function deleteServerPages() 
    for i=0,id do 
        local newFile = fileDelete(i..".txt") 
        --outputChatBox("Файлы с id = "..i.." успешно удалены") 
    end 
end 
addEventHandler ( "onResourceStop", root, deleteServerPages) 
  
  
  

Надо сделать так чтоб при соприкосновений colShpere появился pageGiveClient.

Link to comment

Я выложил чистую версию без колшейпа , когда я добавлял его сюда , ну не как не работала. Сначала я создавал через массивы , потом вашим способом не как не получалось :(

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