Skip to content
  • 0 Unread 0
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Donate
Collapse

Plutonium

  1. Home
  2. MW3 Modding Releases & Resources
  3. [Release] Lua Scripting

[Release] Lua Scripting

Scheduled Pinned Locked Moved MW3 Modding Releases & Resources
24 Posts 13 Posters 10.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Rosamaha Rosamaha

    good job! finally see something good for mw3..

    Xerxes Offline
    Xerxes Offline
    Xerxes
    Plutonium Staff
    wrote on last edited by
    #8

    Rosamaha Still won't allow you to set blocked commands on clients 😆

    Rosamaha 1 Reply Last reply
    0
    • Xerxes Xerxes

      Rosamaha Still won't allow you to set blocked commands on clients 😆

      Rosamaha Offline
      Rosamaha Offline
      Rosamaha
      wrote on last edited by
      #9

      Xerxes good that gsc support comes soon ^^ sadly I stopped playing mw3 atm

      1 Reply Last reply
      0
      • mikzy Offline
        mikzy Offline
        mikzy
        Banned
        wrote on last edited by
        #10

        good release 🙂

        1 Reply Last reply
        0
        • fed fed

          Xx_Phoenix_xX i think this is what you mean

          game:onplayerdamage(function(_self, inflictor, attacker, damage, dflags, mod, weapon, point, dir, hitloc)
              if (game:isplayer(attacker) ~= 1 or _self.sessionteam == attacker.sessionteam or _self == attacker) then
                  return
              end
          
              local huddamage = game:newclienthudelem(attacker)
              huddamage.alignx = "center"
              huddamage.horzalign = "center"
              huddamage.x = 10
              huddamage.y = 235
              huddamage.fontscale = 1.6
              huddamage.font = "objective"
              huddamage:setvalue(damage)
          
              if (hitloc == "head") then
                  huddamage.color = vector:new(1, 1, 0.25)
              end
          
              huddamage:moveovertime(1)
              huddamage:fadeovertime(1)
              huddamage.alpha = 0
              huddamage.x = math.random(25, 70)
              huddamage.y = 235 + math.random(25, 70) * (math.random(0, 1) == 1 and -1 or 1)
          
              game:ontimeout(function()
                  huddamage:destroy()
              end, 1000)
          end)
          
          Xx_Phoenix_xX Offline
          Xx_Phoenix_xX Offline
          Xx_Phoenix_xX
          wrote on last edited by
          #11

          fed so how do i implement this on my game?

          1 Reply Last reply
          0
          • fed Offline
            fed Offline
            fed
            wrote on last edited by
            #12

            Put that in a file like Plutonium/storage/iw5/scripts/yourscript/__init__.lua

            Xx_Phoenix_xX 1 Reply Last reply
            0
            • fed fed

              Put that in a file like Plutonium/storage/iw5/scripts/yourscript/__init__.lua

              Xx_Phoenix_xX Offline
              Xx_Phoenix_xX Offline
              Xx_Phoenix_xX
              wrote on last edited by
              #13

              fed does it work on all servers or only my own? btw nice gungame server its lots of fun

              1 Reply Last reply
              0
              • fed fed

                As many of you probably know the current chaiscript scripting is pretty bad and has many limitations. This plugin implements lua scripting in IW5 and fixes all those problems.

                Everything is basically the same as in IW6x (documentation can be found here).

                How

                • Download the latest version from the Releases tab
                • Copy it to %localappdata%/Plutonium/storage/iw5/plugins/
                • Create a __init__.lua file in a folder with a name of your choice in %localappdata%/Plutonium/storage/iw5/scripts/
                • Example %localappdata%/Plutonium/storage/iw5/scripts/myscript/__init__.lua
                • Run the server (preferably with the -no-scripting flag to disable ChaiScript)

                Below are some features that are not available or documented in IW6x

                Chat notifies

                level:onnotify("say", function(player, message)
                    print(player.name .. " said: " .. message)
                end)
                

                or

                level:onnotify("connected", function(player)
                    player:onnotify("say", function(message)
                        print(player.name .. " said: " .. message)
                    end)
                end)
                

                Player damage/killed callbacks

                Callbacks can be added using the game:onplayerkilled or game:onplayerdamage functions:

                Damage can be changed by returning it

                Returning anything other than a number will not do anything (must be an integer)

                game:onplayerdamage(function(_self, inflictor, attacker, damage, dflags, mod, weapon, point, dir, hitloc)
                    damage = 0
                
                    return damage
                end)
                
                game:onplayerkilled(function(_self, inflictor, attacker, damage, mod, weapon, dir, hitloc, timeoffset, deathanimduration)
                    print(attacker.name .. " killed " .. _self.name)
                end)
                

                Arrays

                GSC arrays are supported and can be accessed similarly to gsc:

                local ents = game:getentarray()
                
                for i = 1, #ents do
                    print(ents[i])
                end
                

                To get the array's keys use the getkeys method:

                local keys = player.pers.getkeys()
                
                for i = 1, #keys do
                    print(keys[i])
                end
                

                Structs

                GSC structs are also supported similarly as the arrays.

                To get an entity's struct use the getstruct method:

                local levelstruct = level:getstruct()
                
                levelstruct.inGracePeriod = 10000
                

                Structs in other variables like arrays are automatically converted:

                level:onnotify("connected", function(player)
                    player:onnotify("spawned_player", function()
                        player.pers.killstreaks[1].streakName = "ac130"
                        player.pers.killstreaks[1].available = 1
                    end)
                end)
                

                Note: you cannot create new struct fields but only modify or read existing ones, same thing for arrays

                Functions

                You can call (will not work for every function) functions and methods within the game's gsc scripts using the

                scriptcall(filename, function, ...) method:

                level:onnotify("connected", function(player)
                    player:onnotify("spawned_player", function()
                        local hudelem = player:scriptcall("maps/mp/gametypes/_hud_utils", "createFontString", 1)
                        
                        hudelem:scriptcall("maps/mp/gametypes/_hud_util", "setPoint", "CENTER", nil, 100, 100)
                        hudelem.label = "&Hello world"
                    end)
                end)
                

                Functions in variables such as structs or arrays will be automatically converted to a lua function.

                The first argument must always be the entity to call the function on (level, player...)

                local levelstruct = level:getstruct()
                
                level:onnotify("connected", function(player)
                    player:onnotify("spawned_player", function()
                        levelstruct.killstreakFuncs["ac130"](player)
                    end)
                end)
                
                BO2 Offline
                BO2 Offline
                BO2
                Contributor Banned
                wrote on last edited by
                #14

                fed It doesn't seem to work for me. I did the Damage Counter Script you made in the above comments. But It never worked, I neither know how to run it. (if you have to run it manually) Any Help?

                fed 1 Reply Last reply
                0
                • BO2 BO2

                  fed It doesn't seem to work for me. I did the Damage Counter Script you made in the above comments. But It never worked, I neither know how to run it. (if you have to run it manually) Any Help?

                  fed Offline
                  fed Offline
                  fed
                  wrote on last edited by
                  #15

                  @ScottieC111
                  1 - Copy the plugin to Plutonium/storage/iw5/plugins/
                  2 - Create a file in Plutonium/storage/iw5/scripts/yourscript/__init__.lua and copy the code into it
                  3 - Run the server

                  1 Reply Last reply
                  1
                  • naccib Offline
                    naccib Offline
                    naccib
                    wrote on last edited by
                    #16

                    Looks like a great addition, I'll install Pluto IW5 to try this out.

                    I didn't notice any issues or development plan on GitHub. Looking forward to contributing to it.

                    1 Reply Last reply
                    0
                    • st0rm Offline
                      st0rm Offline
                      st0rm
                      VIP
                      wrote on last edited by
                      #17

                      fed Thank you for adding the lua support. I've been trying to get hasperk and unsetperk to work but it seem it crash the server upon loading the script every time.

                      function onPlayerSpawned( player )
                      	if(player:haspek("specialty_grenadepulldeath")) then
                      		print(player.name .. " is using marty")
                      	end	
                      end
                      
                      function onPlayerConnected( player )
                          local spawnListener = player:onnotify("spawned_player", function() onPlayerSpawned(player) end)
                      end
                      
                      level:onnotify("connected", onPlayerConnected)
                      
                      fed 1 Reply Last reply
                      0
                      • st0rm st0rm

                        fed Thank you for adding the lua support. I've been trying to get hasperk and unsetperk to work but it seem it crash the server upon loading the script every time.

                        function onPlayerSpawned( player )
                        	if(player:haspek("specialty_grenadepulldeath")) then
                        		print(player.name .. " is using marty")
                        	end	
                        end
                        
                        function onPlayerConnected( player )
                            local spawnListener = player:onnotify("spawned_player", function() onPlayerSpawned(player) end)
                        end
                        
                        level:onnotify("connected", onPlayerConnected)
                        
                        fed Offline
                        fed Offline
                        fed
                        wrote on last edited by
                        #18

                        st0rm not sure why it crashes but doing this works fine:

                        function onPlayerSpawned( player )
                            game:ontimeout(function()
                                if(player:hasperk("specialty_grenadepulldeath") == 1) then
                                    print(player.name .. " is using marty")
                                end	
                            end, 0)
                        end
                        
                        function onPlayerConnected( player )
                            local spawnListener = player:onnotify("spawned_player", function() onPlayerSpawned(player) end)
                        end
                        
                        level:onnotify("connected", onPlayerConnected)
                        
                        1 Reply Last reply
                        0
                        • st0rm Offline
                          st0rm Offline
                          st0rm
                          VIP
                          wrote on last edited by
                          #19

                          Thanks Fed. That work just fine. I learnt the hard way the mw3 sets death perks in a really dumb way where there is not way to unset them since they're based on death streaks.

                          Kalitos 1 Reply Last reply
                          0
                          • fed fed

                            As many of you probably know the current chaiscript scripting is pretty bad and has many limitations. This plugin implements lua scripting in IW5 and fixes all those problems.

                            Everything is basically the same as in IW6x (documentation can be found here).

                            How

                            • Download the latest version from the Releases tab
                            • Copy it to %localappdata%/Plutonium/storage/iw5/plugins/
                            • Create a __init__.lua file in a folder with a name of your choice in %localappdata%/Plutonium/storage/iw5/scripts/
                            • Example %localappdata%/Plutonium/storage/iw5/scripts/myscript/__init__.lua
                            • Run the server (preferably with the -no-scripting flag to disable ChaiScript)

                            Below are some features that are not available or documented in IW6x

                            Chat notifies

                            level:onnotify("say", function(player, message)
                                print(player.name .. " said: " .. message)
                            end)
                            

                            or

                            level:onnotify("connected", function(player)
                                player:onnotify("say", function(message)
                                    print(player.name .. " said: " .. message)
                                end)
                            end)
                            

                            Player damage/killed callbacks

                            Callbacks can be added using the game:onplayerkilled or game:onplayerdamage functions:

                            Damage can be changed by returning it

                            Returning anything other than a number will not do anything (must be an integer)

                            game:onplayerdamage(function(_self, inflictor, attacker, damage, dflags, mod, weapon, point, dir, hitloc)
                                damage = 0
                            
                                return damage
                            end)
                            
                            game:onplayerkilled(function(_self, inflictor, attacker, damage, mod, weapon, dir, hitloc, timeoffset, deathanimduration)
                                print(attacker.name .. " killed " .. _self.name)
                            end)
                            

                            Arrays

                            GSC arrays are supported and can be accessed similarly to gsc:

                            local ents = game:getentarray()
                            
                            for i = 1, #ents do
                                print(ents[i])
                            end
                            

                            To get the array's keys use the getkeys method:

                            local keys = player.pers.getkeys()
                            
                            for i = 1, #keys do
                                print(keys[i])
                            end
                            

                            Structs

                            GSC structs are also supported similarly as the arrays.

                            To get an entity's struct use the getstruct method:

                            local levelstruct = level:getstruct()
                            
                            levelstruct.inGracePeriod = 10000
                            

                            Structs in other variables like arrays are automatically converted:

                            level:onnotify("connected", function(player)
                                player:onnotify("spawned_player", function()
                                    player.pers.killstreaks[1].streakName = "ac130"
                                    player.pers.killstreaks[1].available = 1
                                end)
                            end)
                            

                            Note: you cannot create new struct fields but only modify or read existing ones, same thing for arrays

                            Functions

                            You can call (will not work for every function) functions and methods within the game's gsc scripts using the

                            scriptcall(filename, function, ...) method:

                            level:onnotify("connected", function(player)
                                player:onnotify("spawned_player", function()
                                    local hudelem = player:scriptcall("maps/mp/gametypes/_hud_utils", "createFontString", 1)
                                    
                                    hudelem:scriptcall("maps/mp/gametypes/_hud_util", "setPoint", "CENTER", nil, 100, 100)
                                    hudelem.label = "&Hello world"
                                end)
                            end)
                            

                            Functions in variables such as structs or arrays will be automatically converted to a lua function.

                            The first argument must always be the entity to call the function on (level, player...)

                            local levelstruct = level:getstruct()
                            
                            level:onnotify("connected", function(player)
                                player:onnotify("spawned_player", function()
                                    levelstruct.killstreakFuncs["ac130"](player)
                                end)
                            end)
                            
                            Kalitos Offline
                            Kalitos Offline
                            Kalitos
                            wrote on last edited by
                            #20

                            fed I am trying to upload the plugin to the server, but I am getting the following error:

                            a08b266d-a8e6-4b21-9bae-fb25e0c3732c-image.png

                            1 Reply Last reply
                            0
                            • st0rm st0rm

                              Thanks Fed. That work just fine. I learnt the hard way the mw3 sets death perks in a really dumb way where there is not way to unset them since they're based on death streaks.

                              Kalitos Offline
                              Kalitos Offline
                              Kalitos
                              wrote on last edited by
                              #21

                              st0rm And regarding this, I don't know what you want to achieve, but if it works for you, in GSC I use this to deactivate the death streaks

                              onPlayerKilled()
                              {
                                  self endon("disconnect");
                                  level endon("game_ended");
                                  for(;;)
                                  {
                                      self waittill("killed_player");
                                      self.pers["cur_death_streak"] = 0; //Stop deathstreak
                                  }
                              } 
                              
                              1 Reply Last reply
                              0
                              • Kalitos Offline
                                Kalitos Offline
                                Kalitos
                                wrote on last edited by
                                #22

                                I needed Net Framework 3.5. I already solved it.

                                1 Reply Last reply
                                0
                                • fed fed

                                  As many of you probably know the current chaiscript scripting is pretty bad and has many limitations. This plugin implements lua scripting in IW5 and fixes all those problems.

                                  Everything is basically the same as in IW6x (documentation can be found here).

                                  How

                                  • Download the latest version from the Releases tab
                                  • Copy it to %localappdata%/Plutonium/storage/iw5/plugins/
                                  • Create a __init__.lua file in a folder with a name of your choice in %localappdata%/Plutonium/storage/iw5/scripts/
                                  • Example %localappdata%/Plutonium/storage/iw5/scripts/myscript/__init__.lua
                                  • Run the server (preferably with the -no-scripting flag to disable ChaiScript)

                                  Below are some features that are not available or documented in IW6x

                                  Chat notifies

                                  level:onnotify("say", function(player, message)
                                      print(player.name .. " said: " .. message)
                                  end)
                                  

                                  or

                                  level:onnotify("connected", function(player)
                                      player:onnotify("say", function(message)
                                          print(player.name .. " said: " .. message)
                                      end)
                                  end)
                                  

                                  Player damage/killed callbacks

                                  Callbacks can be added using the game:onplayerkilled or game:onplayerdamage functions:

                                  Damage can be changed by returning it

                                  Returning anything other than a number will not do anything (must be an integer)

                                  game:onplayerdamage(function(_self, inflictor, attacker, damage, dflags, mod, weapon, point, dir, hitloc)
                                      damage = 0
                                  
                                      return damage
                                  end)
                                  
                                  game:onplayerkilled(function(_self, inflictor, attacker, damage, mod, weapon, dir, hitloc, timeoffset, deathanimduration)
                                      print(attacker.name .. " killed " .. _self.name)
                                  end)
                                  

                                  Arrays

                                  GSC arrays are supported and can be accessed similarly to gsc:

                                  local ents = game:getentarray()
                                  
                                  for i = 1, #ents do
                                      print(ents[i])
                                  end
                                  

                                  To get the array's keys use the getkeys method:

                                  local keys = player.pers.getkeys()
                                  
                                  for i = 1, #keys do
                                      print(keys[i])
                                  end
                                  

                                  Structs

                                  GSC structs are also supported similarly as the arrays.

                                  To get an entity's struct use the getstruct method:

                                  local levelstruct = level:getstruct()
                                  
                                  levelstruct.inGracePeriod = 10000
                                  

                                  Structs in other variables like arrays are automatically converted:

                                  level:onnotify("connected", function(player)
                                      player:onnotify("spawned_player", function()
                                          player.pers.killstreaks[1].streakName = "ac130"
                                          player.pers.killstreaks[1].available = 1
                                      end)
                                  end)
                                  

                                  Note: you cannot create new struct fields but only modify or read existing ones, same thing for arrays

                                  Functions

                                  You can call (will not work for every function) functions and methods within the game's gsc scripts using the

                                  scriptcall(filename, function, ...) method:

                                  level:onnotify("connected", function(player)
                                      player:onnotify("spawned_player", function()
                                          local hudelem = player:scriptcall("maps/mp/gametypes/_hud_utils", "createFontString", 1)
                                          
                                          hudelem:scriptcall("maps/mp/gametypes/_hud_util", "setPoint", "CENTER", nil, 100, 100)
                                          hudelem.label = "&Hello world"
                                      end)
                                  end)
                                  

                                  Functions in variables such as structs or arrays will be automatically converted to a lua function.

                                  The first argument must always be the entity to call the function on (level, player...)

                                  local levelstruct = level:getstruct()
                                  
                                  level:onnotify("connected", function(player)
                                      player:onnotify("spawned_player", function()
                                          levelstruct.killstreakFuncs["ac130"](player)
                                      end)
                                  end)
                                  
                                  Desempregrado Offline
                                  Desempregrado Offline
                                  Desempregrado
                                  wrote on last edited by
                                  #23

                                  fed I came here today to ask a question about the lua language in Bo2 Plutonium, I wanted to know another method to change or add custom menus in bo2 Plutonium without having to use the plutonium files that is privategamelobby_project.lua ?

                                  I want to load my own lua script into the game, is that possible ? How to do that..?

                                  1 Reply Last reply
                                  0
                                  • Major_Tom Offline
                                    Major_Tom Offline
                                    Major_Tom
                                    wrote on last edited by
                                    #24

                                    Hi
                                    I try to use the 1.8 version when i start the server it crashs without error
                                    i use windows server 2019

                                    1 Reply Last reply
                                    0

                                    Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                                    Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                                    With your input, this post could be even better 💗

                                    Register Login
                                    Reply
                                    • Reply as topic
                                    Log in to reply
                                    • Oldest to Newest
                                    • Newest to Oldest
                                    • Most Votes


                                    • 1
                                    • 2
                                    • Login

                                    • Don't have an account? Register

                                    • Login or register to search.
                                    • First post
                                      Last post
                                    0
                                    • Unread 0
                                    • Recent
                                    • Tags
                                    • Popular
                                    • Users
                                    • Groups
                                    • Donate