Tamkis
Lua Grasshopper
How would one go about using environmental Objects (such as flames, Metal Sonic's energyball, etc) as proper player missiles that don't self-inflict the player using P_SpawnMissile(), and which increment the launching player's score upon collision with an opponent? For some reason, using this function with some objects don't self-inflict the player and do update the score, while others do self-inflict and don't update the score. I have also tried changing the launched object's object flags by desiginating them with a MF_MISSILE flag with no luck.
I am trying to make a lua script that replaces the vanilla ring weapons with other objects. Also, how would one go about decrementing the weapon's counter by only 1 on usage (mine for some reason decrements by 2), and in displaying custom hurt messages?
Attached is my in-progress script. Metal Sonic's energy ball and the Brak Napalm Bomb are not functioning as proper missiles.
Thanks in advance for the advice and bug fixes. I'll credit in the upcoming lua re-submission!
I am trying to make a lua script that replaces the vanilla ring weapons with other objects. Also, how would one go about decrementing the weapon's counter by only 1 on usage (mine for some reason decrements by 2), and in displaying custom hurt messages?
Attached is my in-progress script. Metal Sonic's energy ball and the Brak Napalm Bomb are not functioning as proper missiles.
Code:
//New weapons
//v1.0 By Tamkis
//Replaces current weapons with 6 new ones
//Weapon ammo is removed, and all weapon usage
//decrement weapon count by 2
//Energy Ball and Cannonball launcher are defensive
//weapons, don't change player scores
//Napalm bomb is partially defensive (updates score when physically hit by bomb
//but not by flames
//Updates F1 Multiplayer weapons screen with new weapon info
//Known bugs: Double decremntation of wepaons usage. "Feature" not bug.
//HurtMsgs don't display properly. (Creates "[guy] hit [guy]"]. Just wanted to remove
//old HurtMsgs, so feature not bug
//Remove all ammos
addHook("MapLoad", do
//Hide me mobjinfo stats
local hideme = {
spawnstate = S_INVISIBLE,
flags = MF_NOBLOCKMAP|MF_NOSECTOR
}
//List of standard thrown weapons and pickups to disable
local list = {
MT_BOUNCERING,
MT_RAILRING,
MT_AUTOMATICRING,
MT_EXPLOSIONRING,
MT_SCATTERRING,
MT_GRENADERING
}
for _,i in ipairs(list) // for every mobjtype in the list
for k,v in pairs(hideme)
mobjinfo[i][k] = v // add the properties in hideme to mobjinfo
end
end
end)
addHook("MapChange", do
//Hide me mobjinfo stats
local hideme = {
spawnstate = S_INVISIBLE,
flags = MF_NOBLOCKMAP|MF_NOSECTOR
}
//List of standard thrown weapons and pickups to disable
local list = {
MT_BOUNCERING,
MT_RAILRING,
MT_AUTOMATICRING,
MT_EXPLOSIONRING,
MT_SCATTERRING,
MT_GRENADERING
}
for _,i in ipairs(list) // for every mobjtype in the list
for k,v in pairs(hideme)
mobjinfo[i][k] = v // add the properties in hideme to mobjinfo
end
end
end)
//Perform everyframe
addHook("ThinkFrame", do
//Cycle through all players
for player in players.iterate do
//Check if player is tapping and toggle flags as appropriately, NOT holding
//See http://wiki.srb2.org/wiki/Lua/Custom_player_ability#Triggers_on_button_press
//for more info
//Remove any invice from weps on jump
if (player.cmd.buttons & BT_JUMP)
player.powers[pw_flashing]=0
end
if not (player.cmd.buttons & BT_ATTACK) then //BT_ATTACK=ring launch button
player.tapready = true
player.tapping = false
elseif player.tapready then
player.tapping = true
player.powers[pw_flashing]=0 //Disable any temp invince due to weapons
player.tapready = false
else
player.tapping = false
end
//Laser Turret
//If current weapon is Auto ring and BT_ATTACK is HELD
if (player.currentweapon==WEP_AUTO) and (player.cmd.buttons & BT_ATTACK)
if (player.health>1) //If have enough rings
//Spawn a Turret Laser
P_SpawnPlayerMissile(player.mo, MT_TURRETLASER, MF2_AUTOMATIC)
player.powers[pw_automaticring]=$1-1
end
end
//Cannonball Launcher
//If current weapon is Bounce ring and BT_ATTACK is tapped
if (player.currentweapon==WEP_BOUNCE) and (player.tapping==true)
if (player.health>1) //If have enough rings
player.powers[pw_flashing]=105 //Give 3 secs of invince
//Spawn a Cannonball Launcher, give it a fuse of 30 secs
local mobj //Mobj
mobj=P_SpawnPlayerMissile(player.mo, MT_CANNONLAUNCHER, MF2_BOUNCERING)
mobj.fuse=1050
//Spawn a flame at usage point, give it a fuse of 30 secs
mobj=P_SpawnMobj(player.mo.x, player.mo.y, player.mo.z, MT_FLAME)
mobj.fuse=1050
//Decrement 1 from wep counter every tap. (This usually results in lose of 2 weps
player.powers[pw_bouncering]=$1-1
end
end
//Arrow
//If current weapon is Rail Ring and BT_ATTACK is tapped
if (player.currentweapon==WEP_RAIL) and (player.tapping==true)
if (player.health>1) //If have enough rings
//Spawn an Arrow
P_SpawnPlayerMissile(player.mo, MT_ARROW, MF2_RAILRING)
//Decrement 1 from wep counter every tap. (This usually results in lose of 2 weps
player.powers[pw_railring]=$1-1
end
end
//Large Napalm Bomb
//If current weapon is Grenade and BT_ATTACK is tapped
if (player.currentweapon==WEP_EXPLODE) and (player.tapping==true)
if (player.health>1) //If have enough rings
//Spawn large napalm bomb
P_SpawnPlayerMissile(player.mo, MT_CYBRAKDEMON_NAPALM_BOMB_LARGE, MF2_EXPLOSION)
//Decrement 1 from wep counter every tap. (This usually results in lose of 2 weps
player.powers[pw_explosionring]=$1-1
end
end
//Energy Ball
//If current weapon is Scatter and BT_ATTACK is tapped
if (player.currentweapon==WEP_SCATTER) and (player.tapping==true)
if (player.health>1) //If have enough rings
player.powers[pw_flashing]=25 //Give 0.7 secs of invince
//Spawn Energy ball, give it a fuse of 10 secs
local mobj //Mobj
mobj=P_SpawnPlayerMissile(player.mo, MT_ENERGYBALL, MF2_SCATTER)
mobj.fuse=350
//Decrement 1 from wep counter every tap. (This usually results in lose of 2 weps
player.powers[pw_scatterring]=$1-1
end
end
//Brak Missile
//If current weapon is Grenade, and if tapping
if (player.currentweapon==WEP_GRENADE) and (player.tapping==true)
if (player.health>1) //If have enough rings
//Spawn Brak Missile
P_SpawnPlayerMissile(player.mo, MT_CYBRAKDEMON_MISSILE, MF2_RAILRING)
//Decrement 1 from wep counter every tap. (This usually results in lose of 2 weps
player.powers[pw_grenadering]=$1-1
end
end
end
//Hide me mobjinfo stats
local hideme = {
spawnstate = S_INVISIBLE,
flags = MF_NOBLOCKMAP|MF_NOSECTOR
}
//List of standard thrown weapons and pickups to disable
local list = {
MT_THROWNBOUNCE,
MT_SPARK,
MT_THROWNAUTOMATIC,
MT_THROWNEXPLOSION,
MT_THROWNSCATTER,
MT_THROWNGRENADE,
}
for _,i in ipairs(list) // for every mobjtype in the list
for k,v in pairs(hideme)
mobjinfo[i][k] = v // add the properties in hideme to mobjinfo
end
end
end)
//Fuse handler
addHook("MobjFuse", function(mobj)
//List of custom wepaons that use Fuse
local list =
{
MT_ENERGYBALL,
MT_CANNONLAUNCHER,
MT_CANNONBALL,
MT_FLAME
}
//If mobj is valid and is NOT a player
if (mobj.valid==true) and (mobj.mobjtype!=MT_PLAYER)
for _,i in ipairs(list) // for every mobjtype in the list
//If mobj type is in the list and is NOT a player, remove it
if (mobj.mobjtype==list[i]) and (mobj.mobjtype!=MT_PLAYER)
if (mobj.valid)
P_RemoveMobj(mobj)
end
end
end
end
end)
//Custom Hurt messages.
addHook("HurtMsg", function(player, inflictor, source)
//Parallel arrays
//Custom types of weapons
local Types=
{
MT_ARROW,
MT_CYBRAKDEMON_NAPALM_BOMB_LARGE,
MT_CYBRAKDEMON_MISSILE,
MT_TURRETLASER,
}
//Direct object
local DirectObj=
{
"flung arrow",
"lobbed Napalm bomb",
"launched Brak missile",
"shot laser",
}
//Verb
local verb=
{
"stabbed",
"obliterated",
"decimated",
"fried",
}
//Generate custom message based on wep type and if hurt vs. killed
for _,i in ipairs(Types) // for every mobjtype in the list
if (((inflictor) and (inflictor.type == Types[i])) and ((source) and (source.player))) then
if player.mo.health then
print(("%s's %s %s %s."):format(source.player.name, DirectObj[i], verb[i], player.name))
else
print(("%s's %s defeated %s."):format(source.player.name, DirectObj[i], player.name))
end
return true
end
end
end)
Thanks in advance for the advice and bug fixes. I'll credit in the upcoming lua re-submission!