Seite 1 von 5 12345 LetzteLetzte
Ergebnis 1 bis 10 von 41

Thema: Entity Spawnen aber wie? :D

  1. #1

    Standard Entity Spawnen aber wie? :D

    Hallo,
    Ich möchte mit Derma ein kleines Menü erstellen und dort soll man Tische und Stühle spawnen können!
    Da hätten wir eine Furniture_Spawn.lua
    Code:
    local DermaPanel = vgui.Create( "DFrame" ) 
      DermaPanel:SetPos( 50,150 ) 
      DermaPanel:SetSize( 700, 500 )
      DermaPanel:SetTitle( "Spawn Furnitures" )
      DermaPanel:SetVisible( true )
      DermaPanel:SetDraggable( true )
      DermaPanel:ShowCloseButton( true )
      DermaPanel:MakePopup()
    
    local DermaButton = vgui.Create( "DButton" )
      DermaButton:SetParent( DermaPanel )
      DermaButton:SetText( "Table" )
      DermaButton:SetPos( 25, 50 )
      DermaButton:SetSize( 150, 50 )
      DermaButton.DoClick = function () 
     SpawnTable()
    end
    und die cl_init.lua
    Code:
    include ("cl_hud.lua")
    include ("Furniture_spawn.lua")
    
    function SpawnTable()
      local table = ents.Create("prop_physics")
        table:SetModel("models/props_c17/FurnitureTable002a.mdl")
        table:SetPos(tr.HitPos)
        table:Spawn()
    end
    InGame geht direkt das Menü auf (ändere ich noch) und es kommt ein Panel mit einem Button namens "Table", bis dorthin keine errors!
    Wenn ich auf den Button klicke spawnt bei den cooridnaten ~(0 0 64) ein Tisch durch den man durchlaufen kann und nicht zerstören.
    Folgendes steht in der Console:
    Zitat Zitat von Console
    SantoRP/gamemode/cl_init.lua:8: attempt to index global 'tr' (a nil value)
    Was habe ich übersehn, bzw. vergessen oder geht es auch leichter?
    Thanks schonmal...
    mfG Santo

  2. #2
    Andrey
    Avatar von Andrey

    Standard AW: Entity Spawnen aber wie? :D

    Zitat Zitat von Santo Beitrag anzeigen
    Code:
        table:SetPos(tr.HitPos)
    Er weiß nicht was "tr" ist.

    Ich kenn mich leider nicht besonders mit Lua aus, aber du musst tr schon Definieren.

  3. #3

    Standard AW: Entity Spawnen aber wie? :D

    Genau. Guckst du am besten hier:
    http://wiki.garrysmod.com/wiki/?title=Util.TraceLine

  4. #4

    Standard AW: Entity Spawnen aber wie? :D

    Code:
    include ("cl_hud.lua")
    include ("Furniture_spawn.lua")
    
    local tr = self.Owner:GetEyeTrace()
    
    function SpawnTable()
      local table = ents.Create("prop_physics")
        table:SetModel("models/props_c17/FurnitureTable002a.mdl")
        table:SetPos(tr.HitPos)
        table:Spawn()
    end
    Füg mal die Zeile ein.
    Website: monky-town.de

    WildStar
    Server: Kazor
    Seite: Verbannte
    Char: Monkii (Arkanschütze)

  5. #5

    Standard AW: Entity Spawnen aber wie? :D

    Das ist der Spawncode eines normalen Entity.
    Lua Code:
    1. function ENT:SpawnFunction( ply, tr )
    2.     if ( !tr.Hit ) then return end    
    3.     local SpawnPos = tr.HitPos + tr.HitNormal * 16 
    4.     local ent = ents.Create( "gravtogglecontroller" )
    5.         ent:SetPos( SpawnPos )
    6.         ent:Spawn()
    7.         ent:Activate()   
    8.     return ent   
    9. end

    awesome thing is made by Araxiel-Sama

  6. #6

    Standard AW: Entity Spawnen aber wie? :D

    Aber nur wenn du ein SENT erstellst!

    -----

    Desweiteren solltest du das Prop auf der Server Seite erstellen.

    Mach einfach folgendes bei der DoClick Funktion:

    Lua Code:
    1. DermaButton.DoClick = function ()
    2.     local tr = LocalPlayer():GetEyeTrace()
    3.  
    4.     local myprop = ents.Create( "prop_physics" )
    5.         myprop:SetModel( "models/props_c17/FurnitureTable002a.mdl" )
    6.         myprop:SetPos( tr.HitPos )
    7.         myprop:Spawn()
    8. end


    Das sollte funktionieren.

  7. #7

    Standard AW: Entity Spawnen aber wie? :D

    Also muss ich das derma in cl_init und die function in init stecken oder wie?

  8. #8

    Standard AW: Entity Spawnen aber wie? :D

    Wahrscheinlich.
    cl_init ist darstellung/grafik, init das script

    awesome thing is made by Araxiel-Sama

  9. #9

    Standard AW: Entity Spawnen aber wie? :D

    Zitat Zitat von WeltEnSTurm Beitrag anzeigen
    Wahrscheinlich.
    cl_init ist darstellung/grafik, init das script
    Das stimmt nur bedingt.
    In der cl_init.lua sind die Sachen für den Client (Derma, HUD usw) und in der init.lua sind Sachen für den Server (Entities Spawnen usw)

  10. #10

    Standard AW: Entity Spawnen aber wie? :D

    Zitat Zitat von Console
    SantoRP\gamemode\init.lua:1: attempt to index global 'self' (a nil value)

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •