While writing a server browser I discovered that RemoteGame does not not have a port property. So if you do set your server on a non default port, you will not be able to connect to it by using the server list. Which leads to this issue:

Hello. Function in Vehicle class "SetAcceleration" don't work after update. The car stand still and isn't driving, only work steering function and is moving by inertia. I used lua script for create vehicle. Please, help me!
Code of my test script:
function Script:Start()
vehicle = Vehicle:Create(self.entity)
local tiremodel={}
table.insert(tiremodel,4)
for i=0,3 do
tiremodel[i]=self.entity:FindChild("w"..i)
tiremodel[i]:SetShape(nil)
if i < 2 then
vehicle:AddTire(tiremodel[i],true)
else
vehicle:AddTire(tiremodel[i])
end
end
vehicle:AddAxle(0,1)
vehicle:AddAxle(2,3)
if vehicle:Build()==false then
Debug:Error("Failed to build vehicle.")
end
vehicle:SetEngineRunning(true)
vehicle:SetTransmissionMode(true)
vehicle:SetHandBrakes(0)
end
function Script:UpdatePhysics()
local steering=0
if window:KeyDown(Key.A) then steering=steering+30 end
if window:KeyDown(Key.D) then steering=steering-30 end
vehicle:SetSteering(steering)
local gas=0
if window:KeyDown(Key.W) then gas=gas + 0.1 end
if window:KeyDown(Key.S) then gas=gas - 0.1 end
vehicle:SetBrakes(0)
vehicle:SetHandBrakes(0)
vehicle:SetAcceleration(gas)
end

Here is how i made it possible to call C++ from LUA.
I want to build Multiplayer game in Leadwerks. But i couldn't find networking libraries and threading libraries that would make it usable in Lua. So i build a Networking client in C++ with libcurl and libpthread . But i want to still use the Lua scripting on the prefabs since a lot of work is already done for me here. And also programming in Higher level languages is just faster.
I decided to use the libtolua++ libraries, since this is already build into Leadwerks.
I work on Ubuntu 15.04. Here the tolua++ libs are installed with:
sudo apt-get install libtolua++5.1-dev
The tolua++ program needs a pck file which shall contain the c++ like seudo code that is translated into lua classes.
My package:
$#include "shot.h"
class ShotListener {
ShotListener();
~ShotListener();
void shot(Object* oEntity, float damage);
float getHealth(Object* oEntity);
};
I have made two functions. One to emit shots detected on the Entities from the Lua scripting. Another to get the current health status from C++ side.
My actual ShotListener.h class looks like this:
#pragma once
#include "App.h"
#include "Leadwerks.h"
using namespace Leadwerks;
class ShotListener {
private:
public:
ShotListener(void) {
}
~ShotListener(void){}
void shot(Object* oEntity, float damage) {
App *app = App::getInstance();
Entity * entity = (Entity*)oEntity;
app->entityShot(entity, damage);
return;
}
float getHealth(Object* oEntity) {
App *app = App::getInstance();
Entity * entity = (Entity*)oEntity;
float value = app->getEntityHealth(entity);
return value;
}
};
As you can see i changed the default App class into a Singleton so that i can get the App object from the instances of ShotListener that is used from Lua.
Having placed these two files in the same folder i ran the following function from the terminal:
tolua++5.1 -o tolua_shot.cpp -H tolua_shot.h -n Shot shot.pkg
This generated two files tolua_shot.cpp and tolua_shot.h that i included in my C++ project along with the shot.h file.
This way i can do a
self.shotListener = ShotListener:new()
In the Script:Start() function in mu Lua objects
and a
self.shotListener:shot(self.entity, self.hits)
When Hurt is called in the Lua object.
After this i just had to sort out all the Segmentation error bugs because of multithreading.
I forgot to mention that the ShotListener Lua also needs to be initialized in the main.cpp before app->Start() with the following:
if (Interpreter::L==NULL) Interpreter::Reset();
tolua_ShotListener_open(Interpreter::L);

During development of Leadwerks Game Engine, there was some debate on whether we should allow multiple scripts per entity or just associate a single script with an entity. My first iteration of the scripting system actually used multiple scripts, but after using it to develop the Darkness Awaits example I saw a lot of problems with this. Each script used a different classname to store its variables and functions in, so you ended up with code like this:
function Script:HurtEnemy(amount)
if self.enemy ~= nil then
if self.enemy.healthmanager ~= nil then
if type(self.enemy.healthmanager.TakeDamage)=="function" then
self.enemy.healthmanager.TakeDamage(amount)
end
end
end
end
I felt this hurt script interoperability because you had to have a bunch of prefixes like healthmanager, ammomanager, etc. I settled on using a single script, which I still feel was the better choice between these two options:
function Script:HurtEnemy(amount)
if self.enemy ~= nil then
if type(self.enemy.TakeDamage)=="function" then
self.enemy.TakeDamage(amount)
end
end
end
Scripting in Turbo Game Engine is a bit different. First of all, all values and functions are attached to the entity itself, so there is no "script" table. When you access the "self" variable in a script function you are using the entity object itself. Here is a simple script that makes an entity spin around its Y axis:
function Entity:Update()
self:Turn(0,0.1,0)
end
Through some magic that is only possible due to the extreme flexibility of Lua, I have managed to devise a system for multiple script attachments that makes sense. There is no "component" or "script" objects itself, adding a script to an entity just executes some code that attached values and functions to an entity. Adding a script to an entity can be done in C++ as follows:
model->AttachScript("Scripts/Objects/spin.lua");
Or in Lua itself:
model:AttachScript("Scripts/Objects/spin.lua");
Note there is no concept of "removing" a script, because a script just executes a bit of code that adds values and functions to the entity.
Let's say we have two scripts named "makeHealth100 and "makeHealth75".
MakeHealth100.lua
Entity.health=100
MakeHealth75.lua
Entity.health=75
Now if you were to run the code below, which attaches the two scripts, the health value would first be set to 100, and then the second script would set the same value to 75, resulting in the number 75 being printed out:
model->AttachScript("Scripts/Objects/MakeHealth100.lua");
model->AttachScript("Scripts/Objects/MakeHealth75.lua");
Print(entity->GetNumber("health"));
Simple enough, right? The key point here is that with multiple scripts, variables are shared between scripts. If one scripts sets a variable to a value that conflicts with another script, the two scripts won't work as expected. However, it also means that two scripts can easily share values to work together and create new functionality, like this health regeneration script that could be added to work with any other scripts that treat the value "health" as a number.
HealthRegen.lua
Entity.healthregendelay = 1000
function Entity:Start()
self.healthregenupdatetime = CurrentTime()
end
function Entity:Update()
if self.health > 0 then
if CurrentTime() - self.healthregenupdatetime > self.healthregendelay then
self.health = self.health + 1
self.health = Min(self.health,100)
end
end
end
What about functions? Won't adding a script to an entity overwrite any functions it already has attached to it? If I treated functions the same way, then each entity could only have one function for each name, and there would be very little point in having multiple scripts! That's why I implemented a special system that copies any added functions into an internal table. If two functions with the same name are declared in two different scripts, they will both be copied into an internal table and executed. For example, you can add both scripts below to an entity to make it both spin and make the color pulse:
Spin.lua
function Entity:Update()
self:Turn(0,0.1,0)
end
Pulse.lua
function Entity:Update()
local i = Sin(CurrentTime()) * 0.5 + 0.5
self:SetColor(i,i,i)
end
When the engine calls the Update() function, both copies of the function will be called, in the order they were added.
But wait, there's more.
The engine will add each function into an internal table, but it also creates a dummy function that iterates through the table and executes each copy of the function. This means when you call functions in Lua, the same multi-execution feature will be available. Let's consider a theoretical bullet script that causes damage when the bullet collides with something:
function Entity:Collision(entity,position,normal,speed)
if type(entity.TakeDamage) == "function" then
entity:TakeDamage(20)
end
end
If you have two (or more) different TakeDamage functions on different scripts attached to that entity, all of them would get called, in order.
What if a function returns a value, like below?:
function Entity:Update()
if self.target ~= nil then
if self.target:GetHealth() <= 0 then
self.target = nil --stop chasing if dead
end
end
end
If multiple functions are attached that return values, then all the return values are returned.
To grab multiple returned values, you can set up multiple variables like this:
function foo()
return 1,2,3
end
a, b, c = foo()
print(a) --1
print(b) --2
print(c) --3
But a more practical usage would be to create a table from the returned values like so:
function foo()
return 1,2,3
end
t = { foo() }
print(t[1]) --1
print(t[2]) --2
print(t[3]) --3
How could this be used? Let's say you had a script that was used to visually debug AI scripts. It did this by checking to see what an entity's target enemy was, by calling a GetTarget() function, and then creating a sprite and aligning it to make a line going from the AI entity to its target it was attacking:
function Entity:UpdateDisplay()
local target = self:GetTarget()
self.sprite = CreateSprite()
local p1 = self.entity:GetPosition()
local p2 = target:GetPosition()
self.sprite:SetPosition((p1 + p2) * 0.5)
self.sprite:AlignToVector(p2 - p1)
self.sprite:SetSize(0.1,(p2-p1):Length())
end
Now let's imagine we had a tank with a main gun as well as an anti-aircraft gun that would ward off attacks from above, like this beauty I found on Turbosquid:
Let's imagine we have two different scripts we attach to the tank. One handles AI for driving and shooting the main turret, while the other just manages the little machine gun. Both the scripts have a GetTarget() function, as the tank may be attacking two different enemies at once.
We can easily modify our AI debugging script to handle multiple returned values as follows:
function Entity:UpdateDisplay()
local targets = { self:GetTarget() } --all returned values get put into a table
for n,target in ipairs(targets) do
local sprite = CreateSprite()
self.sprites.insert(sprite)
local p1 = self.entity:GetPosition()
local p2 = target:GetPosition()
sprite:SetPosition((p1 + p2) * 0.5)
sprite:AlignToVector(p2 - p1)
sprite:SetSize(0.1,(p2-p1):Length())
end
end
However, any scripts that are not set up to account for multiple returned values from a function will simply use the first returned value, and proceed as normal.
This system supports both easy mix and match behavior with multiple scripts, but keeps the script code simple and easy to use. Scripts have easy interoperability by default, but if you want to make your function and variable names unique to the script it is easy to do so.
Let me know if you have any other ideas for scripting in Turbo Game Engine.

Introduction:
Having trouble communicating between scripts? Tired of creating references to make scripts globally work together? Then Eventor, which is part of the Phodex Framework, is what you have searched for. Add it to your project for FREE and unleash the power of Lua, with this poweful code design pattern!
How It Works:
With Eventor, different sources can subscribe to an event. Whenever the event gets called, all subscribers get notified and a function, you can define, gets called. This is very helpful in many cases. You could for example create an event which gets called every time an enemy starts combat, to notify surrounding allies to help him. You can send his position as an argument, so only allies within range will get active.
Key Features:
About The Phodex Framework:
The Phodex Framework is a set of helpful tools and systems created to make working with Leadwerks more powerful and easier to handle. The Phodex Framework was also used to develop "Bladequest: The First Chapter", which I recently released on Steam. I thought now that my systems have proven to work, it is time to share them with you. I will release more parts of the Phodex Framework in the future so stay tuned!
________________________________________________________________________________________________________________________________________________
Follow my blog so stay up to date!
For questions directly write me here or at contact.phodex@gmail.com!

Heyas,
Should Script:Collision be able to detect if something has spawned inside of a defined trigger area?
I'm using a rectangular CSG with CollisionType:Trigger to define an a trigger area. I want to detect when another CSG (Collisiontype: Prop) spawns inside the trigger area but seems to fail in that regard. Does the spawning CSG need speed (momentum) to be detected?
Thanks in advance!

Hello every one !
So today i am making my third person code.
In my code i need to compare the name of child i want and the name of each children(GetChildren())
but i have got this error. when i try to compare their name.
CODE:
function Script:GetChildByName(nameRequest)
for i = 0 , self.entity:CountChildren() -1 do
local ent = self.entity:GetChild(i)
local entName = ent:GetKeyValue("name")
if entName == nameRequest then
System:Print(nameRequest + " has been found !")
return ent
end
end
return nil
end

Hey everyone, i'm really new at this so please be understanding. I'm trying to write a Script to open a Door with a floorswitch. The idea is to drop a box and activate the switch. I'm using the prefab boxes and the SlidingDoor.Lua. I saw this video below but the problem is that the script works only if you put the value name in the Script
function Script:Collision (entity, position, normal, speed)
if (entity: GetKeyValue ("name") == "crate_small") then
self.component: CallOutputs ("Open")
end
end
but what i want is to be able to assign or to change the object-door-opener from the Script tab, by creating a Script Entry, I just don't know how cause i'm really new at this. Thanks for your help.

Hello every one !
Today i wanted to add c++ code to object but looks to accept only lua script 🤷‍♂️
It is possible to add c++ into this box
Or we just use c++ into app.cpp (add class but every thing is connected to the app file) ?

The Leadwerks 5 API uses C++11 smart pointers for all complex objects the user interacts with. This design replaces the manual reference counting in Leadwerks 4 so that there is no Release() or AddRef() method anymore. To delete an object you just set all variables that reference that object to nullptr:
auto model = CreateBox();
model = nullptr; //poof!
In Lua this works the same way, with some caveats:
local window = CreateWindow()
local context = CreateContext(window)
local world = CreateWorld()
local camera = CreateCamera(world)
camera:SetPosition(0,0,-5)
local model = CreateBox()
while true do
if window:KeyHit(KEY_SPACE) then
model = nil
end
world:Render()
end
In the above example you would expect the box to disappear immediately, right? But it doesn't actually work that way. Lua uses garbage collection, and unless you are constantly calling the garbage collector each frame the model will not be immediately collected. One way to fix this is to manually call the garbage collector immediately after setting a variable to nil:
if window:KeyHit(KEY_SPACE) then
model = nil
collectgarbage()
end
However, this is not something I recommend doing. Instead, a change in the way we think about these things is needed. If we hide an entity and then set our variable to nil we can just defer the garbage collection until enough memory is accrued to trigger it:
if window:KeyHit(KEY_SPACE) then
model:Hide()-- out of sight, out of mind
model = nil
end
I am presently investigating the sol2 library for exposing the C++ API to Lua. Exposing a new class to Lua is pretty straightforward:
lua.new_usertype<World>("World", "Render", &World::Render, "Update", &World::Update);
lua.set_function("CreateWorld",CreateWorld);
However, there are some issues like downcasting shared pointers. Currently, this code will not work with sol2:
local a = CreateBox()
local b = CreateBox()
a:SetParent(b)-- Entity:SetParent() expects an Entity, not a Model, even though the Model class is derived from Entity
There is also no support for default argument values like the last argument has in this function:
Entity::SetPosition(const float x,const float y,const float z,const bool global=false)
This can be accomplished with overloads, but it would require A LOT of extra function definitions to mimic all the default arguments we use in Leadwerks.
I am talking to the developer now about these issues and we'll see what happens.

The Open Leadwerks Examples and Demo's (OLED) project is a community tutorial project for the Leadwerks Game Engine. The public repository contains all source code, materials, textures, models and sounds that are used and/or created in accompanying video tutorials.
The repository also contains a wiki that keeps track of all the tutorials. There won't be a single script out there that does not have a good tutorial available for it.
Tutorials
The tutorials that will be recorded are divided in to the following categories:
Editor usage
Lua scripting
Asset importing
Youtube playlists
Video tutorials will be posted on a regular basis right after I am done editing. There is no fixed date for new tutorials. Sometimes there will be severall a week, other times a week or 2 passes without any updates.
:
Repository
The repository will exclude the default assets that come with a blank Leadwerks project. https://bitbucket.org/Aggror/projectoled
Wiki
The wiki contains a list of categories and recorded tutorials.
https://bitbucket.org/Aggror/projectoled/wiki

When considering the script system in Leadwerks 5, I looked at alternatives including Squirrel, which is used by Valve in many games, but these gave me a deeper appreciation for the simplicity of Lua. There are only a handful of rules you need to learn to use the language, it’s fun to use, yet somehow it does everything you could ever need.
These were three big issues I had to solve. First, the Leadwerks 5 API makes extensive use of smart pointers, which our binding library tolua++ does not support. Second, I wanted better auto completion and a better user experience in the IDE in general. Third, if an external IDE is going to be used it needs to be able to interface with the Leadwerks debugging system.
To support smart pointers, I found a new library called sol2 that does everything we need. @Rick and I discussed the idea at great length and I am happy to say we’ve come up with a design that is simple to use and quite a bit easier than Leadwerks 4.x even. The binding code is nowhere near done but at this point I can see that everything will work.
@AggrorJorn suggested using Visual Studio Code as our official script IDE in Leadwerks 5, and after investigating I think it’s a great idea. The auto completion is quite good and the IDE feels more natural then anything I could come up with using a custom text editor made with Scintilla. In fact eliminating the built-in script editor in Leadwerks 5 relieves me of a lot of uncertainty and potential issues when this is written.
Finally, VS Code has support for custom debuggers. I wrote an example command line debugger for Leadwerks and I will use this to show another programmer how to interface with Leadwerks. (I don’t plan on writing the debugger myself.)
With your feedback and ideas are shaping up to make Leadwerks 5 a huge leap forward over our previous designs. The improved simplicity of the new script system is a big cognitive relief. Having fewer things to worry about makes life better in a subtle but definite way.
There’s something else that consumes a lot of mental attention. Social media and the internet have grown and changed over the years and become more efficient at consuming our attention. (Many features of this site are designed the same way.)
The scary thing is that normal non-technical people seem to be more vulnerable than nerds. We’ll fire up the Witcher and play for an hour, but regular people are checking their phones 24/7 for feedback and validation. It’s much much worse than any accusation we got as kids of being “Nintendo zombies” because we spent an afternoon playing games instead of staring passively at broadcast TV. People who play games generally don’t care about posting photographs of their food or collecting followers.
Somewhere along the line the internet went from being a weird thing on your computer to the collective consciousness of humanity. Reality is online and the physical world around us is just a mirage, one possible instance of a million possible individual experiences. Maybe it was around the time they started using AI to optimize clickbait that things got out of hand.
Although my career and the way I live my life are only possible through the internet, I am old enough to remember life before the web, and in many ways it was better. Things were more focused. Even the early web before clickbait ads and online echo chambers was pretty nice. You could go to a record store and hang out talking to people about new music. Printed paper magazines were a thing.
I already removed the link to our Google+ page in the website footer and no one noticed. I think about deleting our Facebook and twitter accounts, or at least not linking to them on our site. Why must every website pay homage to these monopolies? What are they doing for me, besides a limited flow of hits that pale in comparison to what my own email list brings in? I have written about this before but now that it is fashionable to criticize social media I might act on it. I don’t know, we’ll see.
Please like, share, and retweet.

Hi Leadwerkers :),
I am wondering for quiet a while now, if and how the two things, I will explain in a second, are possible.
First can I grab the "self" value of an function caller WITHOUT using arguments? I would expect this to work with the lua debug.getinfo() functionality? Maybe I better explain it with pseudo code:
--Script 1:
function Script:Test()
Script2:CallingThis()
end
--Script 2:
function Script:CallingThis()
--get self of caller
end
Btw I have no idea how you offically call a "caller" maybe its calle? I dont know
Second how to grab an arguments root variable. What I am already aware of is accessing variables like this self["myVariable"] so I could send self as argument 1 and "myVariable" as string in argument 2, but I am looking for a way to prevent this to optimize the code and lower the error rate. Again some pseudo code:
--Script 1:
Script.myVariable = 10
function Script:Test()
Script2:CallingWithArgument(self.myVariable)
end
--Script 2:
function Script:CallingThis(argument)
--if I do anything with the variable argument here it only changes the local "argument" variable of course
--this is stupid but I guess it will explain what I mean:
local rootVariable = argument:GetRoot()
rootVariable = 20 --> myVariable is changed to 20 within the Script 1
end
You would do me a great favor if you would give me some input on this. I would be able to improve my code even more
Thanks in advance for answering and have a nice day

I have been working on a menubar widget and it came out pretty nicely.
I thought i would release it either for people to have an example of what would be possible with the widget's flexibility
or just for people to use it.
For now it only works in C++ since it makes use of CallFunction().
MenubarElement.lua
!! Make sure when you create the widget you create it last so it will render on top !!
It allows horizontal rules and submenus.
How to use: (C++)
Create the widget and fill the menu
float scale = gui->GetScale();
mnuBarItem = Widget::Create("Name", 2 * scale, 2 * scale, 60 * scale, 26 * scale, gui->GetBase(), "Scripts/GUI/MenubarElement.lua");
mnuBarItem->SetObject("backgroundcolor", new Vec4(0.7, 0.7, 0.7, 1.0));
mnuBarItem->AddItem("Temp0");
mnuBarItem->AddItem("Temp1");
mnuBarItem->AddItem("@-");//create a horizontal rule(menu seperator)
mnuBarItem->AddItem("&Submenu");//this will hold the submenu created next
//create a submenu from the last added item in the list
mnuBarItem->CallFunction("C_CreateSubMenuFromLastItem");
mnuBarItem->CallFunction("C_AddItemToLastSubMenu", "Sub0_A");
mnuBarItem->CallFunction("C_AddItemToLastSubMenu", "Sub0_B");
mnuBarItem->CallFunction("C_AddItemToLastSubMenu", "Sub0_C");
//
mnuAccount->AddItem("Temp2");
Catching widget events
ProcessEvent(Event event)
{
if (event.id == Event::WidgetAction)
{
if (event.source == mnuBarItem)
{
if (event.data == 0)
{
//
}
else if (event.data == 1)
{
//
}
//(event.data == 2) horizontal rule
//
else if (event.data == 3)//submenu
{
int item = event.position.x;//submenu itemidx
if (item == 0)
{
//
}
else if (item == 1)
{
//
}
else if (item == 2)
{
//
}
}
else if (event.data == 4)
{
//
}
}
}
}
Also it needs a call to update somewhere in your loop.
Which is just used to update some delay timing.
mnuBarItem->CallFunction("C_Update");

Hi
I am heavily working on my own user interface system at them moment and I wonder if there is a easy way to resize a loaded font. Example pseudo code for the functionality I am searching for:
--Pseudo Code
self.font = Font:Load("Arial", 6, Font.Smooth) --Load Font
self.font:SetSize(10) --Change size during runtime
I have a solution for this by preloading the font in all sizes and then change the rendered font. But this isn't memory efficient, or are Fonts so small that it makes no diffrence, either way it does create a lot of code Thanks for ideas in advance
Markus from Phodex

Hi Leadwerks fellows
I think some of you may run into the same problem once in a while. The problem is the following. My AI wants to grab an item, but if, for whatever reason, this item gets released, while the AI is moving towards the item, the game just crashes, with no error. The same happens if I grab an item as a player and release the entity in my function, I fixed this by releasing the entity some time later in the loop. And yes I am testing my variables if they are nil, so I guess this could not be the problem... I think this has to do with the order how the loops are iterated through and I kind of understand the problem, but how to overcome this. Any safe solutions on how to release an entity, which is used somewhere else in the code? Thanks for reading so far and thanks for your help in advance!
Markus from Phodex Games

Hi ,
Currently I'm planning the next level for Behind Enemy Lines. Since the player has to do part of the level with a sniper rifle, a little preliminary work had to be done. So, Here's my way to tackle this topic with the Addon "FPS Weapon Pack":
The tutorial from tipforeveryone was very helpful to me. You can find it here
https://www.leadwerks.com/community/blogs/entry/1775-realistic-sniper-rifle-scope-in-lua/
i downloaded a Scope frome here :http://www.cadnav.com/3d-models/model-36647.html
and put it as a child to the "vwep m4" and saved it as a prefab "vwep m4_sniper"
it should be look like this
Now you have to ajust the scope
But for the scope script to work, an empty script must be inserted in the following places. Thanks to Macklebee for this hint!
Now you have to change 2 scripts
1. fpsgun.lua
2. fpsplayer.lua
1. fpsgun.lua
this script i saved under "FPSGun_Sniper.lua"
then this video helps a lot :https://www.youtube.com/watch?time_continue=628&v=3OqwQSP-2FU
thanks to BluHornet
place this in your fpsgun_sniper.lua
Script.offsetNor=Vec3(0,0,0)
Script.offsetADS=Vec3(0,0,0)--Vec3 "Offset ADS"
the next line put after the function Script:Start()
self.offsetNor = self.offset
self.hasZoom=true
self.hasZoom=true (or false) has been inserted because the ironsight will be active in every weapon, but at Grenade or something else i did not want this.
Since I have difficulty with the sway of the weapon and I have no solution for it currently, I commented under function Script: Draw () the following lines out:
--self.swayspeed = Math:Curve(speed,self.swayspeed,20)
--self.swayspeed = math.max(0.5,self.swayspeed)
--self.amplitude = math.max(2,Math:Curve(speed,self.amplitude,20))
now its time to change the fpsplayer.lua
2. fpsplayer.lua
this line put in at the beginning
Script.ADSmode=false
next place the following lines under the function Script:UpdateWorld()
if self.weapons[self.currentweaponindex]~=nil and self.weapons[self.currentweaponindex].hasZoom then
if self.ADSmode == false then
self.camera:SetFOV(70)
self.weapons[self.currentweaponindex ].offset = self.weapons[self.currentweaponindex ].offsetNor
end
if self.ADSmode == true then
self.camera:SetFOV(20)
self.weapons[self.currentweaponindex ].offset = self.weapons[self.currentweaponindex ].offsetADS
end
end
and this also in this function (i put this after a lince called "--fire weapon"
if window:MouseHit(2) then
if self.weapons[self.currentweaponindex]~= nil then
if self.ADSmode == false then
self.ADSmode=true
else
self.ADSmode=false
end
if self.sound.pickupweapon~=nil then self.sound.pickupweapon:Play() end
end
end
if you do not want the ironsight by jump, reload, or carry an item, then paste those lines at the right places
self.ADSmode=false
Since the original crosshair disturbs me in the ironsight, I have inserted "and self.ADSmode==false then" in the function Script:PostRender(context) it should looks like this
if self.health>0 then
if self.canUse==true and self.carryingEntity == nil then
local pickUpX = math.floor((context:GetWidth() - self.image.hand:GetWidth()))/2
local pickUpY = math.floor((context:GetHeight() - self.image.hand:GetHeight()))/2
context:SetBlendMode(Blend.Alpha)
context:DrawImage(self.image.hand, pickUpX, pickUpY)
else
if self.carryingEntity==nil then
if self.weapons[self.currentweaponindex]~=nil then
if self.image.crosshair and self.ADSmode==false then
local crossHairX = math.floor((context:GetWidth() - self.image.crosshair:GetWidth()))/2
local crossHairY = math.floor((context:GetHeight() - self.image.crosshair:GetHeight()))/2
context:SetBlendMode(Blend.Alpha)
context:DrawImage(self.image.crosshair, crossHairX, crossHairY)
end
end
end
end
What follows now are the individual settings for each weapon to get an Ironsight.
M4 Sniper:
in the script:
the sniper M4 looks now like this
the m4 without scope
in the script:
it should look like this
the shotgun
in the script
the shotgun look like this
the pistol
in the script
the pistol look now like this
So, that was my solution. But if you have even better settings, feel free to write in this blog. I hope that this blog helped a bit. Especially to save time to find the settings for the Ironsight.
Have fun.
Greetings burgelkat

I'm continuing development of my RTS camera script. Which is a modification of the default spectator script.
After fixing "middle mouse button for rotating the camera" problem. Many thanks to Macklebee.
I have run into another problem.
If you attach the following script to a camera in your scene. Moving the mouse to the top/bottom of the scene will move you forwards/backwards. Move the mouse left/right will move you left/right. Scrolling the mouse wheel will raise/lower the camera height. Holding the middle button and moving the mouse left/right will rotate the camera in that direction.
The problem I have is that after you rotate the camera. Moving the mouse to the top of the scene results in the camera moving in the north direction of the map and not the forward facing direction of the camera. I think my problem is to do with the "move" variable in the Update Physics function.
I've tried changing line 88 to
local desiredvelocity = Vec3(strafe,0,move) + Transform:Vector(0,ascension,o,nil,self.entity)
ie I've moved the "move" variable from the Transform to the Vec3 factor. This fixes the rotation problem but now when you move the mouse to the top of the screen the camera moves forward but also loses height.
Script.movespeed=5.0--float "Move speed"
Script.movementsmoothing = 0.3--float "Move smoothness"
Script.radius = 0.5--float "Radius"
Script.lookspeed = 0.1--float "Look speed"
Script.looksmoothing = 0.5--float "Look smoothness"
Script.MousBoarder = 50 --float "Mouse Boarder"
Script.camerarotation = 0,0,45 --Vec3 "Camera Rotation"
function Script:Start()
local window = Window:GetCurrent()
self.mousepos = window:GetMousePosition()
window:ShowMouse()
self.camerarotation = self.entity:GetRotation()
if (self.entity:GetMass()==0) then
self.entity:SetMass(10)
end
self.entity:SetGravityMode(false)
if type(self.entity.SetElasticity)=="SetBuoyancyMode" then
self.entity:SetBuoyancyMode(false)
end
self.entity:SetCollisionType(Collision.Projectile)
if self.entity:GetShape()==nil then
local shape = Shape:Sphere(0,0,0, 0,0,0, self.radius*2,self.radius*2,self.radius*2)
self.entity:SetShape(shape)
shape:Release()
end
self.entity:SetFriction(0,0)
if type(self.entity.SetElasticity)=="function" then
self.entity:SetElasticity(0)
end
self.entity:SetSweptCollisionMode(true)
self.listener = Listener:Create(self.entity)
self.entity:SetBuoyancyMode(false)
end
--Collision filter so the spectator doesn't knock things over
function Script:Overlap(entity)
if entity:GetMass()==0 then
return Collision.Collide
else
return Collision.None
end
end
function Script:UpdateWorld()
local window = Window:GetCurrent()
local cx = Math:Round(context:GetWidth()/2)
local cy = Math:Round(context:GetHeight()/2)
local mpos = window:GetMousePosition()
local mhit = window:MouseDown(Key.MButton)
window:ShowMouse()
--window:SetMousePosition(cx,cy)
local centerpos = window:GetMousePosition()
if self.started then
mpos = mpos * self.looksmoothing + self.mousepos * (1-self.looksmoothing)
local dx = (mpos.x - centerpos.x) * self.lookspeed
local dy = (mpos.y - centerpos.y) * self.lookspeed
--self.camerarotation.x = self.camerarotation.x + dy
if mhit then
self.camerarotation.y = self.camerarotation.y + dx
end
self.mousepos = mpos
else
--self.mousepos = Vec3(centerpos.x,centerpos.y,0)
self.started=true
end
end
function Script:UpdatePhysics()
local move=0
local strafe=0
local ascension=0
local window = Window:GetCurrent()
local mpos = window:GetMousePosition()
local sx = context:GetWidth()
local sy = context:GetHeight()
if mpos.y < self.MousBoarder then move = move + self.movespeed end
if mpos.y > sy - self.MousBoarder then move = move - self.movespeed end
if mpos.x < self.MousBoarder then strafe = strafe - self.movespeed end
if mpos.x > sx - self.MousBoarder then strafe = strafe + self.movespeed end
if mpos.z < 0 then ascension = ascension - self.movespeed/2 end
if mpos.z > 0 then ascension = ascension + self.movespeed/2 end
local currentvelocity = self.entity:GetVelocity(false)
local desiredvelocity = Vec3(strafe,0,0) + Transform:Vector(0,ascension,move,nil,self.entity)
local velocity = currentvelocity * self.movementsmoothing + desiredvelocity * (1.0-self.movementsmoothing)
self.entity:AddForce((desiredvelocity - currentvelocity) * self.entity:GetMass() / self.movementsmoothing,false)
self.entity:PhysicsSetRotation(self.camerarotation.x,self.camerarotation.y,self.camerarotation.z)
end

Hi,
I was lately thinking about converting all my code from Lua to C++. Without knowing the size of my project, do you estaminate this is something taking very long, like more then 2 months, or is this something you could do within a week (I maybe have about 60-80 scripts) if you are working hard on it?
Furthermore do you see any advantages in doing this (or better said is it worth the time) and I am not talking about speed, I much more mean the libraries that C++ offers and the more precice debugging. Thanks for your ideas and Merry Christmas.

Hey, I am currently working on my AI, and I wonder what would be a good way, to make my NPC hold a specific distance to the player. In my case I need it for my AI behavior when it is using range weapons. I think a nice idea is to let the AI find a random point, which keeps a few conditions like, 10 units away from player, not outside of the map, not inside another object. But how to realise that. I would be very thankful if you can give me ideas, examples, descriptions etc.

Restarted my networking framework yet again. This time I gave it a new name 'Hexe'. The old name was 'Overwatch'. It was named long before the Overwatch game came out. It was based off the Half-Life Overwatch. It oversaw the players, ai spawning, contained a secondary path-finding system, but had no networking as it was not native to the LUA side of Leadwerks. 'Hexe' is German for 'witch'. I don't really know why I chose the name but I have the feeling I will be able to put it to good use. Maybe I'll even mix in some Anglish into it.
This restart occurred because the framework became too cumbersome. I had the entity synchronization working correctly, but it did not differentiate between player and an object in the world. That wasn't really that bad, what made messed it up was that a lobby system and teams were needed and there was no space to squeeze any other components into the mix.
This rewrite will focus on the player/client and foremost. The components that are currently being written or are complete are:
The server browser.
This was a side project created out of necessity. I did not want to have to hard code the ip every time.
Anytime I wanted to test multiple clients I had to change the code depending on which computer was running the server.
PITFALL: Since Leadwerks does not expose the servers local ip address via code, you will need to get it manually from you computer, or use some creative workarounds
Network Manager
Hexe is split up between a server class and a client class. Both classes use a network manager class that can automatically handle hosting or connecting to a server. The network manager currently handles the handshake and the beginnings of the lobby system.
When a client joins it initiates and handles the handshake between the server and client. It also raises events so the server or client can react accordingly if need be. After the handshake is completed, the network manager starts the lobby system
The connection handshake.
This is was saved from the last version. It makes sure the server and client are using the same protocol version. It will then register the client on the server and give it an incremental number (similar to the source engine) that allows the client state to be manipulated
The Lobbying system:
This is completely new. After the handshake is complete, it will send a command launching the lobbying system. The network manager only makes sure that a client is in the servers lobby and nothing more. The client and server manually handle the team creation and player switching on their own.
Teams are not part of the network manager because it would require large amounts of rewrites depending on the type of game being created.
When the lobbying system is complete the client input will be added. So far things are going well and maybe soon I wont be staring at console output for feedback.