• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Trigger] Realistic Fire Guns System

Status
Not open for further replies.
Level 17
Joined
Aug 19, 2007
Messages
1,380
Hi, I'm making a third-person map where you don't use your mouse. I want it that, when you press a key (like"F") that you fire with your gun (you've different guns through the map but can only use/have 1 gun at the time in your inventory and the must be in your first inventory slot otherwise the hero wouldn't pick it up). I want it that, you press (e.g.) "F" and that the trigger(s)/system checks which gun you have and that fires a bullet (or several if you've equiped a machine-type gun, like a SMG) which goes in a straight line (if it's possible, I prefer that it stops when coming against the ground), so not a dummy unit with permanent immolation that walks away from you (because there are hills in my map). And one more thing, your unit can change it's vision angle of attack, so I want it that you can fire in the air and so it would be based of the angle of attack of the camera. Is this possible to make (even if it costs me much time)? If you've a tutorial for me, I would gladly accept that also.
 
Level 3
Joined
Aug 19, 2007
Messages
24
Easily doable, but you need to familiarize yourself with 3-d coordinates first. I think the most useful interpretation if you are using a 1st-person perspective is spherical, however you are also varying your unit's position over time. Math is your friend if you are making first-person stuff. See these links for some information:
Spherical Coordinates Parametric Equation

Essentially you will be making a dummy unit that represents the bullet. You will then have your trigger set the unit's X, Y, and Z positions according to the formula of a parametric 3-d line through space. Your trigger will be checking in a sphere around the dummy to see if it collides with any units. You can also have it check to see if the flying height of a unit is below a threshold (I usually use a flying height of 1 as the threshold for ground collisions) before it hits the dirt.

Note: there is no direct function to determine a unit's Z position in the game. Do not use GetLocationZ directly - it will cause desyncs! I'll include a couple functions:

JASS:
function GetLocationZFixed takes real x, real y returns real
    local location loc = Location(0,0) //This location should have the same Z for everyone
    local real wr
    call MoveLocation(loc, x, y) //Will get the same Z for everyone, oddly enough
    set wr = GetLocationZ(loc)
    call RemoveLocation(loc)
    set loc = null
    return wr
endfunction

function GetUnitZ takes unit u returns real
    //return terrain height + unit's flying height
    return GetLocationZFixed(GetUnitX(u), GetUnitY(u)) + GetUnitFlyHeight(u)
endfunction

For abilities to use, you will obviously want to pick one that doesn't require a target. If you want your guns to fire instantly, use one that doesn't interrupt orders, like Berserk (and remove the buff that goes with it when you trigger the part where it fires your gun).
 
Level 17
Joined
Aug 19, 2007
Messages
1,380
Hi, could guys help me with a trigger? In the attachachment you'll find the map, it's still in early stages so nothing extraordinary. I've problem with trigger that lets the bullet move (note that I've haven't made this trigger myself, I've transfered them with all the units and varibles ect but before I could activate the trigger WE said that I must remove some custom scripts (you know the custom script error). So I copied the orginal one and removed those 6 scripts and nothing more, and I can activate it. But it doesn't do anything now, could help me how to solve this problem?
 

Attachments

  • The Outcast.w3x
    2 MB · Views: 64
Level 22
Joined
Dec 31, 2006
Messages
2,216
You may find the header in the trigger editor above the folders(categories), which have the same name as the map + .w3x/w3m. Click on it and you will see a script on the right side. Copy that and put it in your own header.
 
Level 8
Joined
Jun 20, 2004
Messages
229
hm, if you still have trouble you can always use my system that uses right triangles to detect a body collision as well as a bullets trajectory.

its an actual first person shooter but the bullet detection is in the map, i havent worked on it in quite a while though. it detects head, chest, legs, barrels, and trees.

Sharpshooter Online v1.20b - The Hive Workshop - A Warcraft III Modding Site

or this one as well, but that is a pretty old one i made, i guess not as old as the very first sniper scope i made but it has a pretty basic shoot as well.

http://www.hiveworkshop.com/forums/resource.php?t=80859&prev=u=xXx-Tricky-xXx
 
Level 17
Joined
Aug 19, 2007
Messages
1,380
The_Reborn_Devil; I get an error in WE when I c&p the header script and saved the map (WE crashed). I think the problem is that I haven't copied everything (only the things I need with variables and triggers). Do you know which piece of the header script I need for these triggers:
Initialization (not all of it, only that which has a relation with triggers under)
Grav
Shoot
Bullet Move
LeaveMap


Thanks :thumbs_up:.
 
Level 22
Joined
Dec 31, 2006
Messages
2,216
You'll need this script if you don't want to remove stuff from the triggers:

JASS:
function H2I takes handle h returns integer
    return h
    return 0
endfunction

function Cache takes nothing returns gamecache
    if udg_Cache == null then
        set udg_Cache = InitGameCache("Cache.w3v")
        return udg_Cache
    endif
        return udg_Cache
endfunction

function StoreHandleInHandle takes handle stored,handle storer,string category returns nothing
    call StoreInteger(Cache() , I2S(H2I(storer)) , category , H2I(stored))
endfunction

function StoreBooleanInHandle takes boolean stored,handle storer,string category returns nothing
    call StoreBoolean(Cache() , I2S(H2I(storer)) , category , stored)
endfunction

function GetUnit takes handle storer,string category returns unit
    return GetStoredInteger(Cache() , I2S(H2I(storer)) , category)
    return null
endfunction

function GetTrigger takes handle storer,string category returns trigger
    return GetStoredInteger(Cache() , I2S(H2I(storer)) , category)
    return null
endfunction

function GetBoolean takes handle storer,string category returns boolean
    return GetStoredBoolean(Cache() , I2S(H2I(storer)) , category)
endfunction

function Flush takes handle storer returns nothing
    call FlushStoredMission(Cache() , I2S(H2I(storer)))
endfunction
//===========Storing stuff===========

function CinematicFilterGenericForPlayer takes player whichPlayer,real duration,blendmode bmode,string tex,real red0,real green0,real blue0,real trans0,real red1,real green1,real blue1,real trans1 returns nothing
    if ( GetLocalPlayer() == whichPlayer ) then
        call SetCineFilterTexture(tex)
        call SetCineFilterBlendMode(bmode)
        call SetCineFilterTexMapFlags(TEXMAP_FLAG_NONE)
        call SetCineFilterStartUV(0 , 0 , 1 , 1)
        call SetCineFilterEndUV(0 , 0 , 1 , 1)
        call SetCineFilterStartColor(PercentTo255(red0) , PercentTo255(green0) , PercentTo255(blue0) , PercentTo255(100 - trans0))
        call SetCineFilterEndColor(PercentTo255(red1) , PercentTo255(green1) , PercentTo255(blue1) , PercentTo255(100 - trans1))
        call SetCineFilterDuration(duration)
        call DisplayCineFilter(true)
    endif
endfunction

function Remove_child takes nothing returns nothing
    local timer t= GetExpiredTimer()
    local unit u= GetUnit(t , "u")
    call RemoveUnit(u)
    set u = null
    call Flush(t)
    call PauseTimer(t)
    call DestroyTimer(t)
endfunction

function RemoveUnitTimed takes unit u,real time returns nothing
    local timer t= CreateTimer()
    call StoreHandleInHandle(u , t , "u")
    call TimerStart(t , time , false , function Remove_child)
    set t = null
endfunction

function Headshot takes nothing returns nothing
    local sound s= gg_snd_Headshot
    call StartSound(s)
    set s = null
endfunction


//===========Movement stuff===========
function Movement_Conditions takes nothing returns boolean
    local integer oid= GetIssuedOrderId()
    local unit u= GetTriggerUnit()
    local boolean b= GetBoolean(u , "m")
    if b == true then
        set u = null
        return ( oid == 851971 or oid == 851986 or oid == 851983 or oid == 851990 )
    endif
        set u = null
        return false
endfunction

function Stop_Movement_Child takes nothing returns nothing
    local timer t= GetExpiredTimer()
    local unit u= GetUnit(t , "u")
    call IssueImmediateOrder(u , "stop")
    call Flush(t)
    call DestroyTimer(t)
    set u = null
endfunction

function Stop_Movement takes nothing returns nothing
    local unit u= GetTriggerUnit()
    local timer t= CreateTimer()
    call StoreHandleInHandle(u , t , "u")
    call TimerStart(t , 0. , false , function Stop_Movement_Child)
    set u = null
    set t = null
endfunction

function Enable_Movement takes unit u returns nothing
    local trigger t= GetTrigger(u , "mt")
    if t == null then
    else
        call StoreBooleanInHandle(false , u , "m")
    endif
    set t = null
endfunction

function Disable_Movement takes unit u returns nothing
    local trigger t= GetTrigger(u , "mt")
    if t == null then
    else
        call StoreBooleanInHandle(true , u , "m")
    endif
    set t = null
endfunction

function Toogle_Movement takes unit u returns nothing
    local trigger t= CreateTrigger()

    call TriggerAddCondition(t , Condition(function Movement_Conditions))
    call TriggerAddAction(t , function Stop_Movement)
    call TriggerRegisterUnitEvent(t , u , EVENT_UNIT_ISSUED_POINT_ORDER)
    call StoreHandleInHandle(t , u , "mt")

    set t = null
endfunction
Everything below this line: //===========Movement stuff=========== is used to prevent movement while having the scope on.

Everything above this line: //===========Storing stuff=========== is used by multiple things.

The function "CinematicFilterGenericForPlayer " is used by the scope.
The function "Headshot" is used to create the headshot sound.
The functions "RemoveUnitTimed" and "Remove_child" is used to remove a unit after a specified time.
 
Level 17
Joined
Aug 19, 2007
Messages
1,380
I know that where I can find it, but when I copy WE will crash when I save it. This is because only need a piece of your map (not everything, I don't need everything and it saves space this way). WE crashes because the header contains things about triggers and variables i don't copied because I don't need them.
 
Level 22
Joined
Dec 31, 2006
Messages
2,216
Which ability isn't working?
NOTE: My world editor is a little fucked up right now so I can't open the map.
Could you show me the trigger which doesn't work properly?
 
Status
Not open for further replies.
Top