+ Reply to Thread
Page 2 of 2 FirstFirst 12
Results 11 to 18 of 18

Thread: Interact with Entities using an Expression Gate (Like pressing E)

  1. #11
    Wire Sofaking Rybec's Avatar
    Join Date
    Apr 2008
    Location
    Denver
    Posts
    648

    Default Re: Interact with Entities using an Expression Gate (Like pressing E)

    If you give it some sort of prop protection, it kind of defeats the purpose. You wouldn't be able to hit map buttons, because you don't own them.
    Perhaps, as a limiting factor, give it some sort of timer? You can only use the function, say, three/four times per second?
    That, or add some sort of distance restraint, so it can only use entities within a certain distance of either the chip, or a prop you own?
    E:use() - Simulates a "use" on E if E is within 500 units of the expression gate.
    E:use(E2) - Simulates a "use" on E if E is within 500 units of E2. E2 must be owned by the chip's owner in order to work.
    Returns 1 if successful, 0 if not?

    This could be gotten around by applyforcing a prop next to the buttons you wanna hit, but that can be done with the current user too.

  2. #12
    Wire Amateur Matthias's Avatar
    Join Date
    Jul 2008
    Posts
    51

    Default Re: Interact with Entities using an Expression Gate (Like pressing E)

    That Prop Protection isn't really sensefull is true.

    The Range-Thing:
    I'm very new to LUA-Programming (but not to programming...), and i dont know, how i can access the entity of the expression gate, that is calling the function...
    Than It would be able to check, if it is in range.


    The time-limit:
    Is - i think - harder to implement, because you need to store, when it was last called.

    I also thought about giving the function a "cost" (whatever it is) or delay depending on the range of the targetting entity.

    Also:
    we have to think about, if it isnt allready limited by itself, because the gate needs to have the entity.
    (Dont know, if the find-functions are limited)

  3. #13
    Wire Amateur Matthias's Avatar
    Join Date
    Jul 2008
    Posts
    51

    Default Re: Interact with Entities using an Expression Gate (Like pressing E)

    So i added the Restriction in Range(500) and the ability to provide another Entity, which might be more near to the targetentity.
    Also I changed the Player-Entity, that is supplied with the "Use" to be the Owner of the Expression Gate Calling the function.

    Moar suggestions? Is it "Ok" like that?
    Code:
    local function use_entity_from_e2(self,this,otherent)
    	local ent = self.entity
    	if  not this then 
    		return 0 
    	end
    	if  not this:IsValid() then 
    		return 0 
    	end
    	if (this.IsWorld()) then 
    		return 0
    	end	
    	if otherent then
    		if not otherent:IsValid() then 
    			return 0 
    		end
    		if otherent:IsWorld() then
    			return 0
    		end
    		if not (E2Lib.getOwner(self,otherent)==self.entity:GetPlayer()) then
    			return 0
    		end	
    		ent=otherent
    	end
    	-- range calculation stolen from vector.lua
    	local rv1, rv2 = ent:GetPos(), this:GetPos()
    	local rvd1, rvd2, rvd3 = rv1[1] - rv2[1], rv1[2] - rv2[2], rv1[3] - rv2[3]
    	local range = ((rvd1 * rvd1 + rvd2 * rvd2 + rvd3 * rvd3) ^ 0.5)
    	if(range > 500) then
    		return 0
    	end
    	if this.Use and this.GetPlayer then
    		hook.Call("PlayerUse") -- because sk89q said so
    		this:Use(self.entity:GetPlayer())
    		return 1
    	end
    end
    e2function normal entity:use()
    	return use_entity_from_e2(self,this)
    end
    e2function normal entity:use(entity otherent)
    	return use_entity_from_e2(self,this,otherent)
    end
    Last edited by Matthias; 07-21-2010 at 12:51 PM.

  4. #14
    Wirererer sk89q's Avatar
    Join Date
    Sep 2009
    Posts
    270

    Default Re: Interact with Entities using an Expression Gate (Like pressing E)

    hook.Call() this before letting people use entities:
    Gamemode.PlayerUse - GMod Wiki
    Tabbed Prop Spawn Menu
    My Website, KAF's Anime Music



    Build: F6 quick save, PewPew, interactive tutorial system, custom tools
    Wire: UWSVN, High Speed Snapshot Viewer, EGPv3, bunch of Wiremod fixes
    E2: Prop Core, Constraint Core, Entity Core, holoModelAny(), applyPlayerForce(), etc.
    We have modified and rewritten a number of our addons.

  5. #15
    Wire Amateur Matthias's Avatar
    Join Date
    Jul 2008
    Posts
    51

    Default Re: Interact with Entities using an Expression Gate (Like pressing E)

    Do you want me to check for the returnvalue of Gamemod.PlayerUse or do you want me to call the hook?

    Btw: are there any small chances, that this will go to public branch?

  6. #16
    Wirererer sk89q's Avatar
    Join Date
    Sep 2009
    Posts
    270

    Default Re: Interact with Entities using an Expression Gate (Like pressing E)

    Call the hook and check its value to see if the player should be able to use that entity.
    Tabbed Prop Spawn Menu
    My Website, KAF's Anime Music



    Build: F6 quick save, PewPew, interactive tutorial system, custom tools
    Wire: UWSVN, High Speed Snapshot Viewer, EGPv3, bunch of Wiremod fixes
    E2: Prop Core, Constraint Core, Entity Core, holoModelAny(), applyPlayerForce(), etc.
    We have modified and rewritten a number of our addons.

  7. #17
    Wire Amateur Matthias's Avatar
    Join Date
    Jul 2008
    Posts
    51

    Default Re: Interact with Entities using an Expression Gate (Like pressing E)

    Hi,

    Calling The Hook is easy:
    Code:
    hook.Call("PlayerUse")
    But how to check its value?
    This is only returning several nil's.

    (Sorry for not answering so long - was not at home)

    Greetings

    EDIT: Edited the code above
    Last edited by Matthias; 07-23-2010 at 02:06 PM.

  8. #18
    Wire Amateur Matthias's Avatar
    Join Date
    Jul 2008
    Posts
    51

    Default Re: Interact with Entities using an Expression Gate (Like pressing E)

    Code:
    local function use_entity_from_e2(self,this,otherent)
    	local ent = self.entity
    	if  not this then -- called on an nil-entity: return 0
    		return 0 
    	end
    	if  not this:IsValid() then --called on an nonvalid-entity: return 0
    		return 0 
    	end
    	if (this.IsWorld()) then --called on world: return 0
    		return 0
    	end	
    	if(this:IsPlayer( )) then --yuu cant use a player - huh? (this is also catched by this.Use ...)
    		return 0
    	end
    	if otherent then -- if otherent is provided and not nil
    		if not otherent:IsValid() then 
    			return 0 
    		end
    		if otherent:IsWorld() then
    			return 0
    		end
    		if not (E2Lib.getOwner(self,otherent)==self.entity:GetPlayer()) then
    			return 0
    		end	
    		ent=otherent --use otherent to check range
    	end
    	-- range calculation stolen from vector.lua
    	local rv1, rv2 = ent:GetPos(), this:GetPos()
    	local rvd1, rvd2, rvd3 = rv1[1] - rv2[1], rv1[2] - rv2[2], rv1[3] - rv2[3]
    	local range = ((rvd1 * rvd1 + rvd2 * rvd2 + rvd3 * rvd3) ^ 0.5)
    	if(range > 500) then
    		return 0
    	end
    	if this.Use and this.GetPlayer then
    		hook.Call("PlayerUse") -- because sk89q said so
    		this:Use(self.entity:GetPlayer())
    		return 1
    	end
    	return 0
    end
    e2function normal entity:use()
    	return use_entity_from_e2(self,this)
    end
    e2function normal entity:use(entity otherent)
    	return use_entity_from_e2(self,this,otherent)
    end
    Well... i have added some comments and a check for isPlayer().
    Think its ready now.

    Would be great, if it would go to public branch - or give arguments, why it shouldn't

+ Reply to Thread
Page 2 of 2 FirstFirst 12

Tags for this Thread

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