ID:2409931
 
Code:
/obj/item/weapon/gun/projectile/automatic/dc15s
name = "DC-15S Blaster Carbine"
desc = "The DC-15S Blaster Carbine is a lightweight and rapid firing SMG, for when you REALLY need someone dead. Uses plasma cartridges"
icon_state = "c20r"
item_state = "c20r"
w_class = 3
force = 10
caliber = "10mm" // this needs to stay at an already implemented caliber at the moment
origin_tech = list(TECH_COMBAT = 5, TECH_MATERIAL = 2, TECH_ILLEGAL = 8)
slot_flags = SLOT_BELT|SLOT_BACK
fire_sound = 'sound/starwars/weapons/blasterplaceholder.ogg'
load_method = MAGAZINE
handle_casings = null // we dont want bullet casings dropping since they are plasma cartridges.




allowed_magazines = list(/obj/item/ammo_magazine/plasmacartridge,/obj/item/ammo_magazine/plasmastuncartridge)
sel_mode = 1
//auto_eject = 1
//auto_eject_sound = 'sound/weapons/smg_empty_alarm.ogg'




firemodes = list(

list(mode_name="semiauto", burst=1, fire_delay=0, move_delay=null, burst_accuracy=null, dispersion=null),
list(mode_name="3-round bursts",burst=3, fire_delay=null, move_delay=2, burst_accuracy=list(1,0,0), dispersion=list(0, 10, 15)),
list(mode_name="short bursts",burst=5, fire_delay=null, move_delay=3, burst_accuracy=list(1,0,,-1,-1), dispersion=list(5, 10, 15, 20)),
list(mode_name="stun",fire_sound = 'sound/weapons/rifleshot.ogg', burst=1,fire_delay=null, move_delay=3, burst_accuracy=list(1,0,,-1,-1), dispersion=list(5, 10, 15, 20)) // it sets to stun, and works properly, however implementing the ammo type doesnt work but sound can work


/obj/item/ammo_casing/blasterbolt
desc = "A blaster bolt casing."
caliber = "10mm"
projectile_type = /obj/item/projectile/energy/flash/blasterboltblue
icon_state = "rifle-casing"
spent_icon = "rifle-casing-spent"

/obj/item/ammo_magazine/plasmacartridge
name = "plasma cartridge"
icon_state = "12mm"
origin_tech = list(TECH_COMBAT = 2)
mag_type = MAGAZINE
caliber = "10mm"
matter = list(DEFAULT_WALL_MATERIAL = 1500)
ammo_type = /obj/item/ammo_casing/blasterbolt
max_ammo = 20
multiple_sprites = 1


/obj/item/ammo_casing/blasterboltstun
desc = "A stun blaster bolt casing."
caliber = "10mm"
projectile_type = /obj/item/projectile/energy/flash/blasterboltstun
icon_state = "rifle-casing"
spent_icon = "rifle-casing-spent"
/obj/item/ammo_magazine/plasmastuncartridge
name = "plasma stun cartridge"
icon_state = "12mm"
origin_tech = list(TECH_COMBAT = 2)
mag_type = MAGAZINE
caliber = "10mm"
matter = list(DEFAULT_WALL_MATERIAL = 1500)
ammo_type = /obj/item/ammo_casing/blasterboltstun
max_ammo = 20
multiple_sprites = 1





Problem description:
I'm looking to access the projectile from the ammo from the magazine /obj/item/ammo_magazine/plasmacartridge to change it when the firemode is set to stun and to set it to the stun magazines(/obj/item/ammo_magazine/plasmastuncartridge) projectile.
Is it possible?
yeah it is possible, you just have to create a new obj and set the var to this obj
Okay, so the way that I understood it to be is this,
// i set the variable to the newly created object here
var/obj/item/ammo_magazine/plasmacartridge/universal = new/obj/item/ammo_magazine/plasmacartridge


/obj/item/weapon/gun/projectile/automatic/dc15s
name = "DC-15S Blaster Carbine"
desc = "The DC-15S Blaster Carbine is a lightweight and rapid firing SMG, for when you REALLY need someone dead. Uses plasma cartridges"
icon_state = "c20r"
item_state = "c20r"
w_class = 3
force = 10
caliber = "10mm" // this needs to stay at an already implemented caliber at the moment
origin_tech = list(TECH_COMBAT = 5, TECH_MATERIAL = 2, TECH_ILLEGAL = 8)
slot_flags = SLOT_BELT|SLOT_BACK
fire_sound = 'sound/starwars/weapons/blasterplaceholder.ogg'
load_method = MAGAZINE
handle_casings = null // we dont want bullet casings dropping since they are plasma cartridges.




allowed_magazines = list(/obj/item/ammo_magazine/plasmacartridge/O)
sel_mode = 1
//auto_eject = 1
//auto_eject_sound = 'sound/weapons/smg_empty_alarm.ogg'









firemodes = list(


list(mode_name="semiauto", burst=1, fire_delay=0, move_delay=null, burst_accuracy=null, dispersion=null),
list(mode_name="3-round bursts",burst=3, fire_delay=null, move_delay=2, burst_accuracy=list(1,0,0), dispersion=list(0, 10, 15)),
list(mode_name="short bursts",burst=5, fire_delay=null, move_delay=3, burst_accuracy=list(1,0,,-1,-1), dispersion=list(5, 10, 15, 20)),
list(mode_name="stun",fire_sound = 'sound/weapons/rifleshot.ogg',universal.ammo_type = /obj/item/ammo_casing/blasterboltstun, burst=1,fire_delay=null, move_delay=3, burst_accuracy=list(1,0,,-1,-1), dispersion=list(5, 10, 15, 20)) // i set the variable universal.ammo_type to what i want
)


/obj/item/projectile/energy/flash/blasterboltblue
name = "blaster bolt"
icon = 'icons/starwars/effects/projectiles/blasterbolts.dmi'
icon_state = "blasterboltblue"
damage = 20
damage_type = BURN
brightness = 7
light_duration = 2
light_range = 2
light_color = "#0099ff"
agony = 10

/obj/item/projectile/energy/flash/blasterboltstun
name = "blaster bolt stun"
icon = 'icons/starwars/effects/projectiles/blasterbolts.dmi'
icon_state = "blasterboltstun"
damage = 0
nodamage = 1
damage_type = BURN
agony = 10
range = 15 //if the shell hasn't hit anything after travelling this far it just explodes.
light_color = "#0099ff"
flash_range = 0
brightness = 7
light_duration = 2
light_range = 2


/obj/item/projectile/energy/flash/blasterboltstun/on_impact(var/atom/A)
var/turf/T = flash_range? src.loc : get_turf(A)
if(!istype(T)) return

//blind adjacent people
for (var/mob/living/carbon/M in viewers(T, flash_range))
if(M.eyecheck() < FLASH_PROTECTION_MODERATE)
flick("e_flash", M.flash)

//snap pop
playsound(src, 'sound/effects/snap.ogg', 50, 1)
src.visible_message("<span class='warning'>\The [src] explodes in a bright flash!</span>")

new /obj/effect/decal/cleanable/ash(src.loc) //always use src.loc so that ash doesn't end up inside windows
single_spark(T)
new /obj/effect/effect/smoke/illumination(T, brightness=max(flash_range*2, brightness), lifetime=light_duration)


/obj/item/projectile/energy/flash/blasterboltblue/on_impact(var/atom/A)
var/turf/T = flash_range? src.loc : get_turf(A)
if(!istype(T)) return

//blind adjacent people
for (var/mob/living/carbon/M in viewers(T, flash_range))
if(M.eyecheck() < FLASH_PROTECTION_MODERATE)
flick("e_flash", M.flash)

//snap pop
playsound(src, 'sound/effects/snap.ogg', 50, 1)
src.visible_message("<span class='warning'>\The [src] explodes in a bright flash!</span>")

new /obj/effect/decal/cleanable/ash(src.loc) //always use src.loc so that ash doesn't end up inside windows
single_spark(T)
new /obj/effect/effect/smoke/illumination(T, brightness=max(flash_range*2, brightness), lifetime=light_duration)




/obj/item/ammo_casing/blasterbolt
desc = "A blaster bolt casing."
caliber = "10mm"
projectile_type = /obj/item/projectile/energy/flash/blasterboltblue
icon_state = "rifle-casing"
spent_icon = "rifle-casing-spent"

/obj/item/ammo_casing/blasterboltstun
desc = "A stun blaster bolt casing."
caliber = "10mm"
projectile_type = /obj/item/projectile/energy/flash/blasterboltstun
icon_state = "rifle-casing"
spent_icon = "rifle-casing-spent"




/obj/item/ammo_magazine/plasmacartridge
name = "plasma cartridge"
icon_state = "12mm"
origin_tech = list(TECH_COMBAT = 2)
mag_type = MAGAZINE
caliber = "10mm"
matter = list(DEFAULT_WALL_MATERIAL = 1500)
ammo_type = /obj/item/ammo_casing/blasterbolt
max_ammo = 20
multiple_sprites = 1

/obj/item/ammo_magazine/plasmastuncartridge
name = "plasma stun cartridge"
icon_state = "12mm"
origin_tech = list(TECH_COMBAT = 2)
mag_type = MAGAZINE
caliber = "10mm"
matter = list(DEFAULT_WALL_MATERIAL = 1500)
ammo_type = /obj/item/ammo_casing/blasterboltstun
max_ammo = 20
multiple_sprites = 1

/obj/item/ammo_magazine/plasmacartridge/universal
name = "plasma cartridge"
icon_state = "12mm"
origin_tech = list(TECH_COMBAT = 2)
mag_type = MAGAZINE
caliber = "10mm"
matter = list(DEFAULT_WALL_MATERIAL = 1500)
ammo_type = /obj/item/ammo_casing/blasterbolt
max_ammo = 20
multiple_sprites = 1



/obj/item/ammo_magazine/plasmacartridge/empty
initial_ammo = 0
/obj/item/ammo_magazine/plasmastuncartridge/empty
initial_ammo = 0
/obj/item/ammo_magazine/plasmacartridgeuniversal/empty
initial_ammo = 0


But now im getting a "expected a constant expression" Error where I put universal.ammo_type
You'd have to set that variable inside of a proc (like New()), since universal is an initialized object, universal.ammo_type is only something that can be known at runtime.

You can only set values at compile-time to something known at compile-time (constant expressions).
Oh okay, that makes sense, but how would I call a proc from the firemode stun?
list(mode_name="stun",fire_sound = 'sound/weapons/rifleshot.ogg', burst=1,fire_delay=null, move_delay=3,    burst_accuracy=list(1,0,,-1,-1), dispersion=list(5, 10, 15, 20))
Sorry, I'm still new at coding in dreammaker haha
You'd likely need to find where the mode changes or is utilized and set/use the value there.

I don't know anything about SS13's stuff in that regard though.