+ Reply to Thread
Results 1 to 6 of 6

Thread: E2 - CJ's functions

  1. #1
    Lurker [FX]CJ[CrS] is on a distinguished road [FX]CJ[CrS]'s Avatar
    Join Date
    Jul 2008
    Posts
    28

    Default E2 - CJ's functions UPDATE

    hey
    im a beginner of LUA and i will show you my first "working" scripts

    PHP Code:
    registerFunction("extinguish""e:n"" ", function(selfargs)
        
    local op1op2 args[2], args[3]
        
    local rv1rv2 op1[1](selfop1),op2[1](selfop2)
        if(!
    validEntity(rv1)) then return 0 end
        
    if(!isOwner(selfrv1)) then return end
        
    if rv2 then rv1:Extinguish(); end
    end
    )

    registerFunction("sequence""e:s"" ", function(selfargs)
        
    local op1op2 args[2],args[3]
        
    local rv1rv2 op1[1](selfop1),op2[1](selfop2)
        if(!
    validEntity(rv1)) then return 0 end
        
    if(!isOwner(selfrv1)) then return end
        local sequence 
    rv1:LookupSequencerv2 )
        
    rv1:SetSequence(sequence
    end)

    registerFunction("setHealth""e:n"" ", function(selfargs)
        
    local op1op2 args[2],args[3]
        
    local rv1rv2 op1[1](selfop1),op2[1](selfop2)
        if(!
    validEntity(rv1)) then return 0 end
        
    if(!isOwner(selfrv1)) then return end
        rv1
    :SetHealthrv2 )
    end)

    registerFunction("npcSetEnemy""e:e"" ", function(selfargs)
        
    local op1op2 args[2],args[3]
        
    local rv1rv2 op1[1](selfop1),op2[1](selfop2)
        if(!
    validEntity(rv1)) then return 0 end
        
    if(!isOwner(selfrv1)) then return end
        rv1
    :SetEnemyrv2 )
    end)

    /* NEW functions */
    registerFunction("takeDamage""e:ne"" ", function(selfargs)
        
    local op1op2op3 args[2],args[3],args[4]
        
    local rv1rv2rv3 op1[1](selfop1),op2[1](selfop2),op3[1](selfop3)
        if(!
    isOwner(selfrv1)) then return end
        
    if(!validEntity(rv1)) then return 0 end
        rv1
    :TakeDamagerv2rv3 )
    end)

    registerFunction("createEffect""svv"" ", function(selfargs)
        
    local op1op2op3 args[2],args[3],args[4]
        
    local rv1rv2rv3 op1[1](selfop1),op2[1](selfop2),op3[1](selfop3)
        
    local effectdata EffectData()
        
    local vPoint Vector(rv2[1],rv2[2],rv2[3])
        
    local vPointUp Vector(rv3[1],rv3[2],rv3[3])
        if (
    rv1 == "Explosion"then return 0 end
        
    if (rv1 == "dof_node"then return 0 end
        effectdata
    :SetOriginvPointUp 
        
    effectdata:SetStartvPoint )
        
    effectdata:SetScale)
        
    util.Effectrv1effectdata 
    end
    extinguish -> unignite a prop
    sequence -> set a animation (string) of the input entity
    setHealth -> set the health of the entity
    npcSetEnemy -> set the enemy (entity2) of the NPC (entity1)
    E:takeDamage(N,E) entity 1"E" take "N" damage from "E"
    createEffect(S,v,v) -> creates a effect (effects -> Util.Effect - GMod Wiki) (Explosion and dof_node effect are restricted!) Vector1 ist the aimpos from the effect and vector2 is the position of the effect

    ->
    Code:
    Entity:extinguish(1) # number are 0 or 1
    Entity:sequence("idle")
    Entity:setHealth(100)
    Entity:npcSetEnemy(Entity2) # e("npc_alyx") ?!
    E:takeDamage(N,E)
    createEffect(S,v,v)
    

    all functions are tested

    BUGS: the npcSetEnemy function dosnt work correctly and takeDamage returns a "script error" if the entity dead or removed )


    /EDIT: UPDATE!!!! createEffect with Position system added
    have fun
    Last edited by [FX]CJ[CrS]; 05-16-2009 at 03:14 AM. Reason: update

  2. #2
    Bug Buster

    TomyLobo has a spectacular aura about TomyLobo has a spectacular aura about TomyLobo's Avatar
    Join Date
    Feb 2009
    Posts
    2,786

    Default Re: E2 - CJ's functions

    if rv2 then rv1:Extinguish(); end <-- doesnt work

    in lua, _everything_ but nil and false is evaluated as false
    that means both 0 and 1 are true
    use this:
    if rv2 and rv2 ~= 0 then rv1:Extinguish() end

    this way it should work as expected
    although i dont know why there is this argument anyway... if you dont want to extinguish, why are you calling this function at all?

    This way it'd make much more sense:
    Code:
    registerFunction("extinguish", "e:", "", function(self, args)
        local op1 = args[2]
        local rv1 = op1[1](self, op1)
        if(!validEntity(rv1)) then return end
        if(!isOwner(self, rv1)) then return end
        rv1:Extinguish()
    end)
    
    Last edited by TomyLobo; 04-22-2009 at 02:16 PM. Reason: it reeeaaally doesnt matter, but i forgot to remvoe the arguments :)
    "It's easy to win forgiveness for being wrong; being right is what gets you into real trouble." - Bjarne Stroustrup

    Lífið læðist lúmskt áfram

  3. #3
    hat full of head

    Azrael is a glorious beacon of light Azrael is a glorious beacon of light Azrael is a glorious beacon of light Azrael is a glorious beacon of light Azrael is a glorious beacon of light Azrael's Avatar
    Join Date
    Aug 2007
    Posts
    1,947

    Default Re: E2 - CJ's functions

    I'm not entirely sure about that, TomyLobo. Sure, '0 or 5' will give you 0 whereas 'nil or 5' gives 5, but I'm pretty sure that 'if false' will not execute the code inside its code block.

    But TomyLobo has a point -- why the argument to the function?

  4. #4
    Bug Buster

    TomyLobo has a spectacular aura about TomyLobo has a spectacular aura about TomyLobo's Avatar
    Join Date
    Feb 2009
    Posts
    2,786

    Default Re: E2 - CJ's functions

    'if 0' WILL execute the block of code.
    'if 1' WILL execute the block of code.
    'if true' WILL execute the block of code.
    'if false' will NOT execute the block of code.
    'if nil' will NOT execute the block of code.
    everything else WILL execute the block of code.

    that's how it's written and that's how it shall be done
    "It's easy to win forgiveness for being wrong; being right is what gets you into real trouble." - Bjarne Stroustrup

    Lífið læðist lúmskt áfram

  5. #5
    Lurker jonney934 is on a distinguished road jonney934's Avatar
    Join Date
    Feb 2008
    Posts
    38

    Default Re: E2 - CJ's functions

    Well, this seems to me pretty simple to add functions to E2, I guess now that he made an extinguish then there has to be an ignite.

    Code:
    registerFunction("ignite", "e:", "", function(self, args)
        local op1, op2 = args[2], args[3]
        local rv1, rv2 = op1[1](self, op1),op2[1](self, op2)
        if(!validEntity(rv1)) then return end
        if(!isOwner(self, rv1)) then return end
        rv1:Ignite()
    end)
    
    Would that work?

    When you're trying to restart a server, you don't need more than 10 V2 rockets. All you need is someone to join.

  6. #6
    Lurker [FX]CJ[CrS] is on a distinguished road [FX]CJ[CrS]'s Avatar
    Join Date
    Jul 2008
    Posts
    28

    Default Re: E2 - CJ's functions

    Quote Originally Posted by jonney934 View Post
    Well, this seems to me pretty simple to add functions to E2, I guess now that he made an extinguish then there has to be an ignite.

    Code:
    registerFunction("ignite", "e:", "", function(self, args)
        local op1, op2 = args[2], args[3]
        local rv1, rv2 = op1[1](self, op1),op2[1](self, op2)
        if(!validEntity(rv1)) then return end
        if(!isOwner(self, rv1)) then return end
        rv1:Ignite()
    end)
    
    Would that work?
    no
    that work


    Code:
    registerFunction("ignite", "e:", "", function(self, args)
        local op1 = args[2]]
        local rv1 = op1[1](self, op1)
        if(!validEntity(rv1)) then return end
        if(!isOwner(self, rv1)) then return end
        rv1:Ignite()
    end)
    
    or

    Code:
    registerFunction("ignite", "e:n", "", function(self, args)
        local op1, op2 = args[2], args[3]
        local rv1, rv2 = op1[1](self, op1),op2[1](self, op2)
        if(!validEntity(rv1)) then return end
        if(!isOwner(self, rv1)) then return end
        if rv2 > 0 then rv1:Ignite() end
    end)
    
    UPDATE: look post 1
    Last edited by [FX]CJ[CrS]; 04-22-2009 at 03:21 PM.

+ Reply to Thread

Similar Threads

  1. E2 seat functions!
    By Azrael in forum Wiremod Lua Coding
    Replies: 18
    Last Post: 05-08-2009, 11:14 PM
  2. [E2] HUD-drawing functions
    By SatansSimon in forum Wiremod Lua Coding
    Replies: 23
    Last Post: 03-22-2009, 02:15 PM
  3. E-2 some functions.
    By Whodunnit in forum Ideas & Suggestions
    Replies: 12
    Last Post: 03-11-2009, 04:31 AM
  4. E2: Few new functions
    By d3cr1pt0r in forum Wiremod Lua Coding
    Replies: 24
    Last Post: 02-22-2009, 09:17 PM
  5. Need ADVANCED help with functions!
    By scasbyte in forum Wiremod General Chat
    Replies: 4
    Last Post: 07-28-2007, 09:02 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
proceed-collector
proceed-collector
proceed-collector
proceed-collector
linguistic-parrots
linguistic-parrots
linguistic-parrots
linguistic-parrots