Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bullet Code?
A.M Team Offline
Banned

Posts: 811
Threads: 63
Joined: Sep 2014
#1
Bullet Code?

Would you be able to get the stun rod tool to shoot out bullets that when hitting a specific object it can create a piece of code for the object and bullet (ex: Play a death animation and the bullet getting destroyed)?

Over the last week, me, Abion and Romulator have been trying to get the stun rod to shoot projectiles to the point of madness. We tried a number of systems which have been unsuccessful for the following reasons:

My way:
[Image: hvTYLeI.png]
- Can shoot enemies through walls
- Does produce effects (like bullet holes)
- We don't know if we can add areas to a HUD object yet

Abion's way:
PHP Code: (Select All)
// On gun firing
Map_GetEntity("dummy_entity").cLux_GetPlayer().GetCamera().GetPosition(); 

iLuxEntity @bullet Entity_CreateAtEntity("new_entity_name""entity_file_name""dummy_entity_name");
cVector3f forward Player_GetCamera().GetForward();
bullet.GetMainBody().SetLinearVelocity(cVector3f(forward.bulletSpeedforward.bulletSpeedforward.bulletSpeed));
Entity_AddCollideCallback("new_entity_name""monster_*""bullet_OnCollide"); 
- Too complex
- Hard to code
- Too easy to mess up code

Any suggestions on different ways on solving this issue? This post is sort of a last resort at the moment.
06-01-2016, 11:40 PM
Find
Abion47 Offline
Senior Member

Posts: 369
Threads: 22
Joined: Oct 2015
Reputation: 46
#2
RE: Bullet Code?

Try this in the OnAction function of the map script:

void OnAction(int alAction, bool abPressed)
{
    if (alAction == eAction_Interact && abPressed)
    {
        // Check to see if player is holding a gun object. This value
        // would be updated when the player picks up, draws, or
        // holsters the gun in the corresponding callbacks for those events
        if (mbHoldingGun)
        {
            // "Fire" a bullet in the direction the player is looking with a max range of mfGunRange
            cLuxClosestEntityData pData;
            if (cLux_GetClosestEntity(mpCamera.GetPosition(), mpCamera.GetForward(), mfGunRange, 0, true, pData))
            {
                tString sEntityName = pData.mpEntity.GetName();
                
                // Handle gunshot on entity with the name stored in sEntityName
            }
        }
    }
}

Rather than fire an actual object (i.e. my previous suggestion), this should simplify the solution by just doing a simple ray trace to see which entity would be in the way of the gun.
(This post was last modified: 06-02-2016, 05:54 AM by Abion47.)
06-02-2016, 05:52 AM
Find
A.M Team Offline
Banned

Posts: 811
Threads: 63
Joined: Sep 2014
#3
RE: Bullet Code?

How would you declare mpCamera, mfGunRange and mbHoldingGun respectively (bool, const tString, const int, const float)?
06-02-2016, 07:56 AM
Find
Abion47 Offline
Senior Member

Posts: 369
Threads: 22
Joined: Oct 2015
Reputation: 46
#4
RE: Bullet Code?

mpCamera => cCamera @mpCamera = cLux_GetPlayer().GetCamera();
mfGunRange => float mfGunRange = whatever_gun_range_float_value_you_want;
mbHoldingGun => bool mbHoldingGun = false;
(This post was last modified: 06-02-2016, 08:57 AM by Abion47.)
06-02-2016, 08:50 AM
Find
A.M Team Offline
Banned

Posts: 811
Threads: 63
Joined: Sep 2014
#5
RE: Bullet Code?

Good news, the unaltered script with the declarations loads without errors! But when I test it I don't see any effects in Dev Mode. You said the script scans the entity the ray trace hits, correct? Is there an option in the Debug Toolbar that lets me see the line or when it identifies an area?
(This post was last modified: 06-02-2016, 12:16 PM by A.M Team.)
06-02-2016, 12:16 PM
Find




Users browsing this thread: 1 Guest(s)