Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Help with Scripting for SMOD?  (Read 1392 times)

0 Members and 1 Guest are viewing this topic.

Offline Chr0n0Tr!gg3r

  • *
  • *
  • +2% chance to make useful post
  • Chr0n0Tr!gg3r has no influence.
Help with Scripting for SMOD?
« on: August 25, 2016, 07:55:01 AM »
So in my ventures into hopefully developing a cool mod I've run into a few issues and am wondering if it's possible through scripting to fix them.

1. Excluding NPC's based on their given entity name on the map from the npc_replace_model.
So one problem I found in SMOD is caused by random models, I'm actually working on a mod that adds a ton of variation to the original game and when I tried to do this for the citizens in Trainstation_01 it caused many glitches including stopping the player from proceeding through the level. Many sequences and triggers are broken because the female models don't have the animations they are supposed to and vice versa for the male models on female sequences such as the woman at the gate, all of this throws the map into a loop.
Basically I am wondering if there is a way to make a script that runs when the map starts and if any NPC names from inside the map are on the list it excludes the particular NPC from having their model be randomly changed. It would amazing if there was a way to make it so the model can still randomly change but it can't switch between male and female models that way all the sequences work yet the models can at least be swapped without breaking the map but if that's too hard to script then the first basic option of an exclusion list would work just as well.

Edit: Apparently when the model switches for the citizens you sometimes get the male and female sounds mixed up, maybe this script can make it so male models switch with male models and female models with female models.



2. Making a custom sound folder per .mdl.
If possible this script would check which random models are used at the start of the map and will use sounds made for that mdl file. Basically you'd list the mdl file and then type out a directory from inside the mod that that particular mdl will use to play it's sounds.
So for instance:
"customzombie.mdl"
"/sounds/Zombies/customzombie" and the script will always point any relevant sound files for that mdl to the directory.



3. Giving certain .mdls certain weapons.
I know that there is already a script that makes it so NPC weapons are randomized but what about a script where you can list .mdl's and assign them certain weapons that will always spawn on the map if the .mdl is detected. Say for instance I have a custom metrocop model and I want him to have an AR2 instead of the pistol or grease gun, in the script I'd type the mdl and what weapon I want to give the npc. Once I list his mdl and chose the weapon, when the map starts and it sees his model in-game he will spawn with the AR2 every time. It would be great to have perimeters such as chance of having X weapon and things like that but again if the basic is possible it will work perfectly fine.


If anyone has these scripts and would be willing to help me out I'd appreciate it and credit would be given for helping me out, if someone is willing to help me make one that would also be great! Keep in mind I'm not the best at scripting, in fact, I don't even know if any of the above is possible but if it is I'd appreciate the help!

Thanks guys, happy Snooching!
« Last Edit: August 25, 2016, 09:48:44 AM by Chr0n0Tr!gg3r »

Offline Counter-Life™

  • *
  • *
  • +17% chance to make useful post
  • Counter-Life™ is a rising star!Counter-Life™ is a rising star!Counter-Life™ is a rising star!Counter-Life™ is a rising star!Counter-Life™ is a rising star!Counter-Life™ is a rising star!
    • Youtube Channel
Re: Help with Scripting for SMOD?
« Reply #1 on: August 28, 2016, 11:43:03 AM »
1. Sadly not possible. Your best bet is to exclude the trainstation maps from the model randomizer script. You COULD also try to replace npc_citizen with another entity that uses citizen AI (such as npc_f_kleiner or npc_f_combine) and see how that plays out. 

2. I don't think that's possible.

3. Same, I don't think that's possible. SMOD only allows to give different entity types different weapons.

SMOD is a pretty old mod, and has it's limitations. You'll have to work with what you got: if you want an additional Combine soldier type, you can also spawn "monster_human_grunt", which was the entity name for the HECU Grunts in HL1. They will behave like normal Combine soldiers, but are it's own entity, allowing you to give them their own model/weapons via the scripts. You can also use entites like np_f_monk, replace their model and give them custom sounds.

Offline sirmasters

  • *
  • +5% chance to make useful post
  • sirmasters barely matters.sirmasters barely matters.
    • My Twitter (My Forums are inactive at the moment)
Re: Help with Scripting for SMOD?
« Reply #2 on: August 29, 2016, 05:44:10 AM »
1. Sadly not possible. Your best bet is to exclude the trainstation maps from the model randomizer script. You COULD also try to replace npc_citizen with another entity that uses citizen AI (such as npc_f_kleiner or npc_f_combine) and see how that plays out. 

2. I don't think that's possible.

3. Same, I don't think that's possible. SMOD only allows to give different entity types different weapons.

SMOD is a pretty old mod, and has it's limitations. You'll have to work with what you got: if you want an additional Combine soldier type, you can also spawn "monster_human_grunt", which was the entity name for the HECU Grunts in HL1. They will behave like normal Combine soldiers, but are it's own entity, allowing you to give them their own model/weapons via the scripts. You can also use entites like np_f_monk, replace their model and give them custom sounds.

Actully, #1 and #3 can be done using the SMOD Lua system (which is seldom used for some odd reason),
Code: [Select]
NPC_CITIZEN_EXCLUDE = {
"penismcfly"
}

NPC_CITIZEN_REPLACEMENT = {
"models/super_citizen.mdl",
"models/super_evil_citizen.mdl",
"models/naked_breen.mdl"
}

NPC_COMBINE_EXCLUDE = {
"combine_firespitter"
}

NPC_COMBINE_REPLACEMENT = {
"models/evil_naked_breen.mdl",
"models/super_evil_naked_breen.mdl"
}

NPC_CLASSNAME_WEAPON = {
["combine_firespitter"] = {"weapon_shotgun"},
["penismcfly"] = {"weapon_custom1"}

}
NPC_DEFAULT_WEAPONS = {
["npc_citizen"] = {
"weapon_shotgun",
"weapon_smg1"
},
["npc_combine_s"] = {
"weapon_custom12"
}

}
function ModelRandomise(targetclassname, excludelist, modelreplacements)
local pEnt = nil
if(type(modelreplacements) == "string")then
modelreplacements = {modelreplacements}
end
while(true) do --Could freeze the game if you don't eventully put a break
pEnt = HL2.FindEntityByClassname( pEnt, targetclassname )
if(pEnt == nil)then
break --We found no citizen npcs, end loop
end
local isOnExclusionList = false
for k, v in pairs(excludelist)do
if(string.find(pEnt, v) != nil)then --This NPC is on the exclusion list, don't randomise their model!
isOnExclusionList = true
break
end
end
if(not isOnExclusionList)then
HL2.SetModel(pEnt, modelreplacements[math.random(0, #modelreplacements)])
end
end
end

function Game_Init()
ModelRandomise("npc_citizen", NPC_CITIZEN_EXCLUDE, NPC_CITIZEN_REPLACEMENT)
ModelRandomise("npc_combine_s", NPC_COMBINE_EXCLUDE, NPC_COMBINE_REPLACEMENT)
WeaponRandomise(NPC_CLASSNAME_WEAPON, NPC_DEFAULT_WEAPONS)
end


function WeaponRandomise(replacementlist, npcdefaults)
local pEnt = nil

--Anything past this is uncertain
for classnpc, tableweapons in pairs(npcdefaults)do
while(true) do --Could freeze the game if you don't eventully put a break
pEnt = HL2.FindEntityByClassname( pEnt, classnpc )
if(pEnt == nil)then
break --We found no citizen npcs, end loop
end
local hopefullythispartworks = HL2.GetEntInfo(pEnt)
HL2.EntFire( hopefullythispartworks.Name, nil, "GiveWeapon", npcdefaults[math.random(0, #npcdefaults)], 0.1 )
end
end
--Uncertainity end

--Give certain weapons to certain npcs
for k, v in pairs(replacementlist)do
pEnt = HL2.FindEntityByName(nil, k )
if(pEnt != nil)then
HL2.EntFire( k, nil, "GiveWeapon", v, 0.1 )
end
end
pEnt = nil

end

Then you would call the function Game_Init via mapadd's init label using
Code: [Select]
"lua"
{
"callfunc" "Game_Init"
}

However, Counter-Life is correct about #2 though as for I know.

EDIT: Turns out while debugging the code with Chrono, that the above lua code does not work as SMOD uses LUA 5.0 and not 5.1+, which I was used to. As such, the above code does not work at the moment, but the adjusted version I gave to Chrono directly does.
« Last Edit: August 30, 2016, 08:13:19 AM by sirmasters »
._. I love coffee.

Offline Chr0n0Tr!gg3r

  • *
  • *
  • +2% chance to make useful post
  • Chr0n0Tr!gg3r has no influence.
Re: Help with Scripting for SMOD?
« Reply #3 on: August 29, 2016, 02:32:09 PM »
1. Sadly not possible. Your best bet is to exclude the trainstation maps from the model randomizer script. You COULD also try to replace npc_citizen with another entity that uses citizen AI (such as npc_f_kleiner or npc_f_combine) and see how that plays out. 

2. I don't think that's possible.

3. Same, I don't think that's possible. SMOD only allows to give different entity types different weapons.

SMOD is a pretty old mod, and has it's limitations. You'll have to work with what you got: if you want an additional Combine soldier type, you can also spawn "monster_human_grunt", which was the entity name for the HECU Grunts in HL1. They will behave like normal Combine soldiers, but are it's own entity, allowing you to give them their own model/weapons via the scripts. You can also use entites like np_f_monk, replace their model and give them custom sounds.

Actully, #1 and #3 can be done using the SMOD Lua system (which is seldom used for some odd reason),
Code: [Select]
NPC_CITIZEN_EXCLUDE = {
"penismcfly"
}

NPC_CITIZEN_REPLACEMENT = {
"models/super_citizen.mdl",
"models/super_evil_citizen.mdl",
"models/naked_breen.mdl"
}

NPC_COMBINE_EXCLUDE = {
"combine_firespitter"
}

NPC_COMBINE_REPLACEMENT = {
"models/evil_naked_breen.mdl",
"models/super_evil_naked_breen.mdl"
}

NPC_CLASSNAME_WEAPON = {
["combine_firespitter"] = {"weapon_shotgun"},
["penismcfly"] = {"weapon_custom1"}

}
NPC_DEFAULT_WEAPONS = {
["npc_citizen"] = {
"weapon_shotgun",
"weapon_smg1"
},
["npc_combine_s"] = {
"weapon_custom12"
}

}
function ModelRandomise(targetclassname, excludelist, modelreplacements)
local pEnt = nil
if(type(modelreplacements) == "string")then
modelreplacements = {modelreplacements}
end
while(true) do --Could freeze the game if you don't eventully put a break
pEnt = HL2.FindEntityByClassname( pEnt, targetclassname )
if(pEnt == nil)then
break --We found no citizen npcs, end loop
end
local isOnExclusionList = false
for k, v in pairs(excludelist)do
if(string.find(pEnt, v) != nil)then --This NPC is on the exclusion list, don't randomise their model!
isOnExclusionList = true
break
end
end
if(not isOnExclusionList)then
HL2.SetModel(pEnt, modelreplacements[math.random(0, #modelreplacements)])
end
end
end

function Game_Init()
ModelRandomise("npc_citizen", NPC_CITIZEN_EXCLUDE, NPC_CITIZEN_REPLACEMENT)
ModelRandomise("npc_combine_s", NPC_COMBINE_EXCLUDE, NPC_COMBINE_REPLACEMENT)
WeaponRandomise(NPC_CLASSNAME_WEAPON, NPC_DEFAULT_WEAPONS)
end


function WeaponRandomise(replacementlist, npcdefaults)
local pEnt = nil

--Anything past this is uncertain
for classnpc, tableweapons in pairs(npcdefaults)do
while(true) do --Could freeze the game if you don't eventully put a break
pEnt = HL2.FindEntityByClassname( pEnt, classnpc )
if(pEnt == nil)then
break --We found no citizen npcs, end loop
end
local hopefullythispartworks = HL2.GetEntInfo(pEnt)
HL2.EntFire( hopefullythispartworks.Name, nil, "GiveWeapon", npcdefaults[math.random(0, #npcdefaults)], 0.1 )
end
end
--Uncertainity end

--Give certain weapons to certain npcs
for k, v in pairs(replacementlist)do
pEnt = HL2.FindEntityByName(nil, k )
if(pEnt != nil)then
HL2.EntFire( k, nil, "GiveWeapon", v, 0.1 )
end
end
pEnt = nil

end

Then you would call the function Game_Init via mapadd's init label using
Code: [Select]
"lua"
{
"callfunc" "Game_Init"
}

However, Counter-Life is correct about #2 though as for I know.

Gigantic thanks for posting this however I have no idea where to put it or how to activate it in-game, have any pointers?

Offline Counter-Life™

  • *
  • *
  • +17% chance to make useful post
  • Counter-Life™ is a rising star!Counter-Life™ is a rising star!Counter-Life™ is a rising star!Counter-Life™ is a rising star!Counter-Life™ is a rising star!Counter-Life™ is a rising star!
    • Youtube Channel
Re: Help with Scripting for SMOD?
« Reply #4 on: August 29, 2016, 06:45:49 PM »
Wow, lua is more powerful than I thought. This is great stuff!

Offline Chr0n0Tr!gg3r

  • *
  • *
  • +2% chance to make useful post
  • Chr0n0Tr!gg3r has no influence.
Re: Help with Scripting for SMOD?
« Reply #5 on: August 29, 2016, 07:46:51 PM »
Wow, lua is more powerful than I thought. This is great stuff!
How do I implement the script, I'm guessing you have a better idea of it than I do.

Offline sirmasters

  • *
  • +5% chance to make useful post
  • sirmasters barely matters.sirmasters barely matters.
    • My Twitter (My Forums are inactive at the moment)
Re: Help with Scripting for SMOD?
« Reply #6 on: August 29, 2016, 11:24:04 PM »
Wow, lua is more powerful than I thought. This is great stuff!
How do I implement the script, I'm guessing you have a better idea of it than I do.

Create a file "<mapname>.lua" and past the first block of code. The second block is the regular mapadd label trigger needed to call the lua function. Also, disable default model randomization as the lua system handles it.
._. I love coffee.

Offline Chr0n0Tr!gg3r

  • *
  • *
  • +2% chance to make useful post
  • Chr0n0Tr!gg3r has no influence.
Re: Help with Scripting for SMOD?
« Reply #7 on: August 29, 2016, 11:40:40 PM »
Wow, lua is more powerful than I thought. This is great stuff!
How do I implement the script, I'm guessing you have a better idea of it than I do.

Create a file "<mapname>.lua" and past the first block of code. The second block is the regular mapadd label trigger needed to call the lua function. Also, disable default model randomization as the lua system handles it.
And I'm guessing "Penismcfly" is the name of the citizen in the map and the "NPC_MODEL_REPLACEMENT" are the models that it randomly chooses for that specific NPC alone? If I need to differentiate between male and female citizens do I need to copy the "NPC EXCLUDE" and "NPC REPLACEMENT" below the first set and only name off female NPC's? Will npc_replace_model still work in this case meaning this will only be needed for changing the models of specific NPC's?

Could you possibly explain this in a little more in detail so I know full well how to use this and what it does exactly?

Thanks Masters!

Offline sirmasters

  • *
  • +5% chance to make useful post
  • sirmasters barely matters.sirmasters barely matters.
    • My Twitter (My Forums are inactive at the moment)
Re: Help with Scripting for SMOD?
« Reply #8 on: August 30, 2016, 02:47:04 AM »
Wow, lua is more powerful than I thought. This is great stuff!
How do I implement the script, I'm guessing you have a better idea of it than I do.

Create a file "<mapname>.lua" and past the first block of code. The second block is the regular mapadd label trigger needed to call the lua function. Also, disable default model randomization as the lua system handles it.
And I'm guessing "Penismcfly" is the name of the citizen in the map and the "NPC_MODEL_REPLACEMENT" are the models that it randomly chooses for that specific NPC alone? If I need to differentiate between male and female citizens do I need to copy the "NPC EXCLUDE" and "NPC REPLACEMENT" below the first set and only name off female NPC's? Will npc_replace_model still work in this case meaning this will only be needed for changing the models of specific NPC's?

Could you possibly explain this in a little more in detail so I know full well how to use this and what it does exactly?

Thanks Masters!

Actually "NPC_MODEL_REPLACEMENT" is for npcs that are not on the exclusion list, the "penismcfly" npc would have their model kept the same (as made in hammer) without being randomized, while anyone else not on the list would have their randomized as it replaces the default SMOD random model system. Honestly, learning actual scripting and know SMOD's lua commands would help you a LOT. If you add me on steam so I can send you my TS ip, I can explain better how my script works via voice chat.
._. I love coffee.

Offline Chr0n0Tr!gg3r

  • *
  • *
  • +2% chance to make useful post
  • Chr0n0Tr!gg3r has no influence.
Re: Help with Scripting for SMOD?
« Reply #9 on: August 30, 2016, 03:02:01 AM »
Wow, lua is more powerful than I thought. This is great stuff!
How do I implement the script, I'm guessing you have a better idea of it than I do.

Create a file "<mapname>.lua" and past the first block of code. The second block is the regular mapadd label trigger needed to call the lua function. Also, disable default model randomization as the lua system handles it.
And I'm guessing "Penismcfly" is the name of the citizen in the map and the "NPC_MODEL_REPLACEMENT" are the models that it randomly chooses for that specific NPC alone? If I need to differentiate between male and female citizens do I need to copy the "NPC EXCLUDE" and "NPC REPLACEMENT" below the first set and only name off female NPC's? Will npc_replace_model still work in this case meaning this will only be needed for changing the models of specific NPC's?

Could you possibly explain this in a little more in detail so I know full well how to use this and what it does exactly?

Thanks Masters!

Actually "NPC_MODEL_REPLACEMENT" is for npcs that are not on the exclusion list, the "penismcfly" npc would have their model kept the same (as made in hammer) without being randomized, while anyone else not on the list would have their randomized as it replaces the default SMOD random model system. Honestly, learning actual scripting and know SMOD's lua commands would help you a LOT. If you add me on steam so I can send you my TS ip, I can explain better how my script works via voice chat.

That would be great if we could sit down and figure this out and possibly create a better version that hopefully can satisfy most of the things I need done, mind telling me your steam name?

Offline sirmasters

  • *
  • +5% chance to make useful post
  • sirmasters barely matters.sirmasters barely matters.
    • My Twitter (My Forums are inactive at the moment)
Re: Help with Scripting for SMOD?
« Reply #10 on: August 30, 2016, 03:59:36 AM »
Wow, lua is more powerful than I thought. This is great stuff!
How do I implement the script, I'm guessing you have a better idea of it than I do.

Create a file "<mapname>.lua" and past the first block of code. The second block is the regular mapadd label trigger needed to call the lua function. Also, disable default model randomization as the lua system handles it.
And I'm guessing "Penismcfly" is the name of the citizen in the map and the "NPC_MODEL_REPLACEMENT" are the models that it randomly chooses for that specific NPC alone? If I need to differentiate between male and female citizens do I need to copy the "NPC EXCLUDE" and "NPC REPLACEMENT" below the first set and only name off female NPC's? Will npc_replace_model still work in this case meaning this will only be needed for changing the models of specific NPC's?

Could you possibly explain this in a little more in detail so I know full well how to use this and what it does exactly?

Thanks Masters!

Actually "NPC_MODEL_REPLACEMENT" is for npcs that are not on the exclusion list, the "penismcfly" npc would have their model kept the same (as made in hammer) without being randomized, while anyone else not on the list would have their randomized as it replaces the default SMOD random model system. Honestly, learning actual scripting and know SMOD's lua commands would help you a LOT. If you add me on steam so I can send you my TS ip, I can explain better how my script works via voice chat.

That would be great if we could sit down and figure this out and possibly create a better version that hopefully can satisfy most of the things I need done, mind telling me your steam name?

Click the steam icon on the left where all those tiny icon are. or click here http://steamcommunity.com/id/SirMasters
._. I love coffee.

Offline rozh001

  • *
  • +1% chance to make useful post
  • rozh001 has no influence.
Re: Help with Scripting for SMOD?
« Reply #11 on: August 30, 2016, 06:14:40 AM »
haha, i'm already hyped for this new smod

Offline Chr0n0Tr!gg3r

  • *
  • *
  • +2% chance to make useful post
  • Chr0n0Tr!gg3r has no influence.
Re: Help with Scripting for SMOD?
« Reply #12 on: August 30, 2016, 09:31:09 AM »
Thanks to SirMasters he was able to get exactly what I needed done for both the random models problem and the random weapons, I've tested the models in-game and they work however I have yet to test the random weapons so that comes tomorrow.

I've got another problem now, The map I've been working on for the mod will not load in SMOD without crashing so now I have a new error to fix. Either way big thanks to SirMasters and hopefully by Wednesday I'll have a video showcasing the first map of the mod.