Jump to content

RoboMat's Modding Tutorials (Updated 12/11/2013)


RoboMat

Recommended Posts

ty kind sir that explained some:)

probably know how to do the stuff i want to work now:)

 

Float stands for floating point numbers, but technically speaking, there is no such thing as floats in lua. In java you have different variables that represent different number types. For example a byte type in java will only take numbers from -128 to 127 whereas an int can take numbers from -2,147,483,648 to 2,147,483,647. The difference is of course that a byte will take less memory and should be used if you know that there won't be any larger nummers. Theoretically it should speed up some processes, but in most if not all cases the performance increase should be negligable.

 

Lua doesn't care if you have an integer or an float it treats all numbers the same. Moreover lua doesn't care which type a variable is. A variable can be all kinds of stuff. Functions for example are also variables of type function - that's why you sometimes see declarations as:

Package.functionName = function(param1, param2)...end

Which I find pretty ugly personally (though it's just a question about coding style). What should you learn? That lua doesn't care about the type of the number, but java does.

 

As far as I can tell, most of the time when PZ wants a float it wants a real number from 0 to 1 so you can pass it 0,233332 for example. If it takes an int and you pass it a float it should be rounded to an int automatically on conversion.

 

Hope that was understandable.

If anything is incorrect, feel free to correct me people.

 

 

Maybe I'm gonna put that into the tutorial.

Link to comment
Share on other sites

  • 2 weeks later...

 

ty kind sir that explained some:)

probably know how to do the stuff i want to work now:)

 

Float stands for floating point numbers, but technically speaking, there is no such thing as floats in lua. In java you have different variables that represent different number types. For example a byte type in java will only take numbers from -128 to 127 whereas an int can take numbers from -2,147,483,648 to 2,147,483,647. The difference is of course that a byte will take less memory and should be used if you know that there won't be any larger nummers. Theoretically it should speed up some processes, but in most if not all cases the performance increase should be negligable.

 

Lua doesn't care if you have an integer or an float it treats all numbers the same. Moreover lua doesn't care which type a variable is. A variable can be all kinds of stuff. Functions for example are also variables of type function - that's why you sometimes see declarations as:

Package.functionName = function(param1, param2)...end

Which I find pretty ugly personally (though it's just a question about coding style). What should you learn? That lua doesn't care about the type of the number, but java does.

 

As far as I can tell, most of the time when PZ wants a float it wants a real number from 0 to 1 so you can pass it 0,233332 for example. If it takes an int and you pass it a float it should be rounded to an int automatically on conversion.

 

Hope that was understandable.

If anything is incorrect, feel free to correct me people.

 

 

Maybe I'm gonna put that into the tutorial.

 

 

More specifically, EVERY number in Kahlua is a double. Bar none. :D Even ints. But yeah, there's a part between lua and java where it converts those doubles into floats, ints, shorts, whatever the function its trying to call needs.

 

(speider: double is like a float but with 'double' the size of a float, so a higher / lower number is possible)

Link to comment
Share on other sites

All you ever really NEED to know is if the java says one of the following:

 

float

double

long

int

short

 

you can just mentally substitute that with 'number'.

 

That's all you NEED to know. A useful addition is that:

 

float

double

 
0.3443 is possible. Each of these represents a number that can be 1, 2, 3, 4 or any point in between them. 1.3, 2.54345, 4.565634 etc. A character can't just stand on one tile or another, he can stand on the edge of a tile, or 1/4 down it and 1/7 across it. A character in the middle of tile 130, 212 is at 130.5, 212.5 (0.5 of the way through, or 50%) where a character stood on the point between 4 tiles is at 130, 212 (or the very top left of a tile). A character could be 25.543534% hungry, or 13.453534% damp, so again these are 'float' kinda values.
 

long

int

short

 
0.3443 is not possible, since decimal places do not exist. It's like counting on fingers, you count 1, 2, 3, 4 and nothing exists between those values. Integer values (int, long, short) are useful for counting and stuff. You have 10 zombies, or 24 zombies. You never have 12.43 zombies.
 
So passing 123.456 into a java function that wanted an int, it would become 123 and would just chop off the decimal places. It won't round up. Even 12.999999 would become 12. If you try to get tile 213.432, 312.423 it will not return a mythical tile inbetween two tiles. It'll trim off the decimal places and assume you want tile 213, 312.
 
Last thing you maybe need to know is that integers are important, and since lua does not have them sometimes you have to force the issue. If you divide a group of 11 zombies into 2, you don't want 5.5 zombies in each group, you can do this in lua by doing....
 
totalGroupSize = 11 eachGroupIdealSize = totalGroupSize / 2 -- this is now 5.5groupASize = math.floor(eachGroupIdealSize) -- floor makes 5.5 into 5, cuts of decimal place like intgroupBSize = totalGroupSize - groupASize -- now group A is 5 and group B is 6, instead of them being 5.5 each.
Link to comment
Share on other sites

The only fault I find in your explanation, lemmy, is that math.floor (as you described in your GroupSize example) most likely doesn't truncate (or rather cut off the decimal places).

In most languages, the floor function returns the largest integer that is smaller (or equal) than the given number.

So although math.floor(5.5) gives you 5, math.floor(-5.5) would give you -6. (you learn that one the hard way usually, most people do assume it truncates)

 

I'm assuming that the floor function works this way in Lua, though without looking it up myself I can't confirm it.

Link to comment
Share on other sites

  • 4 weeks later...
  • 4 weeks later...
  • 2 weeks later...

UPDATED:

Added section that explains how to create new professions ... it is not completely done and some parts might be rough around the edges, but sometimes it is harder to write these things than they sound in my head (especially in a -to me- foreign language).

I think I might need to update the section about the modloader stuff too. Will do so post-steam release.

Link to comment
Share on other sites

Great work man,always when I'm stuck with something i found answer in one of yours guides or mods :) 

 

Also to custom colors of clothes as it was hard to get at first:

topCol = {                r = 0.1,                g = 0.1,                b = 0.1,            },

i read one thread about this and best answer by RobertJohnson was: For the color, it's from 0 to 1, just like 0 to 255, so if I want to do 120 in R, I just need to do 120/255 = 0.47, and if you want to know the color we used, just multiply the numbers by 255  :)

 

So you can use this simulator http://www.colorschemer.com/online.html to generate your color and then /255 all values

Link to comment
Share on other sites

  • 3 weeks later...

I tried copying this code word for word and it didn't work. I think it was a problem with the coordinates.

 

This is what I came up with:

 

local function initTraits()
TraitFactory.addTrait("rm_Undesireable", "Undesireable", 0, "Allows you to cheat. Shame on you!", true);
end
 
local function initProfessions()
local cheater = ProfessionFactory.addProfession("cheater", "Cheater", "rm_Cheater");
 
cheater:addFreeTrait("rm_Undesireable");
cheater:addFreeTrait("NightOwl");
 
local cheater2 = ProfessionFactory.addProfession("cheater2", "Cheater 2", "rm_Cheater");
 
cheater2:addFreeTrait("rm_Undesireable");
cheater2:addFreeTrait("NightOwl");
end
 
local function initSpawnPoints()
local spawn1;
spawn1 = {
{
worldX = 35,
worldY = 31,
posX = 112,
posY = 16,
},
}
spawn2 = {
{
worldX = 35,
worldY = 34,
posX = 127,
posY = 223,
},
}
 
BaseGameCharacterDetails.spawnPoint.MuldraughKY.cheater = spawn1;
 
spawn1 = {
{
worldX = 35,
worldY = 31,
posX = 112,
posY = 16,
},
}
 
BaseGameCharacterDetails.spawnPoint.MuldraughKY.cheater2 = spawn2;
 
spawn2 = {
{
worldX = 35,
worldY = 34,
posX = 127,
posY = 223,
},
}
end
 
local function initClothing()
local clothes = {
male = {
topPal = "Shirt_White",
top = "Shirt",
bottomPal = "Trousers_White",
bottom = "Trousers",
topCol = {
r = 0.1,
g = 0.1,
b = 0.1,
},
bottomCol = {
r = 0.1,
g = 0.1,
b = 0.1,
},
},
female = {
topPal = "Shirt_White",
top = "Shirt",
bottomPal = "Trousers_White",
bottom = "Trousers",
topCol = {
r = 0.1,
g = 0.1,
b = 0.1,
},
bottomCol = {
r = 0.1,
g = 0.1,
b = 0.1,
},
},
}
ProfessionClothing.cheater = clothes
ProfessionClothing.cheater2 = clothes;
end
 
Events.OnGameBoot.Add(initTraits);
Events.OnGameBoot.Add(initProfessions);
Events.OnGameBoot.Add(initSpawnPoints);
Events.OnGameBoot.Add(initClothing);

 

That has been working for me for debugging purposes.

 

The first Profession spawns you in the warehouse, the second near the police station.

Link to comment
Share on other sites

  • 2 weeks later...

I tried copying this code word for word and it didn't work. I think it was a problem with the coordinates.

 

This is what I came up with:

 

local function initTraits()
TraitFactory.addTrait("rm_Undesireable", "Undesireable", 0, "Allows you to cheat. Shame on you!", true);
end
 
local function initProfessions()
local cheater = ProfessionFactory.addProfession("cheater", "Cheater", "rm_Cheater");
 
cheater:addFreeTrait("rm_Undesireable");
cheater:addFreeTrait("NightOwl");
 
local cheater2 = ProfessionFactory.addProfession("cheater2", "Cheater 2", "rm_Cheater");
 
cheater2:addFreeTrait("rm_Undesireable");
cheater2:addFreeTrait("NightOwl");
end
 
local function initSpawnPoints()
local spawn1;
spawn1 = {
{
worldX = 35,
worldY = 31,
posX = 112,
posY = 16,
},
}
spawn2 = {
{
worldX = 35,
worldY = 34,
posX = 127,
posY = 223,
},
}
 
BaseGameCharacterDetails.spawnPoint.MuldraughKY.cheater = spawn1;
 
spawn1 = {
{
worldX = 35,
worldY = 31,
posX = 112,
posY = 16,
},
}
 
BaseGameCharacterDetails.spawnPoint.MuldraughKY.cheater2 = spawn2;
 
spawn2 = {
{
worldX = 35,
worldY = 34,
posX = 127,
posY = 223,
},
}
end
 
local function initClothing()
local clothes = {
male = {
topPal = "Shirt_White",
top = "Shirt",
bottomPal = "Trousers_White",
bottom = "Trousers",
topCol = {
r = 0.1,
g = 0.1,
b = 0.1,
},
bottomCol = {
r = 0.1,
g = 0.1,
b = 0.1,
},
},
female = {
topPal = "Shirt_White",
top = "Shirt",
bottomPal = "Trousers_White",
bottom = "Trousers",
topCol = {
r = 0.1,
g = 0.1,
b = 0.1,
},
bottomCol = {
r = 0.1,
g = 0.1,
b = 0.1,
},
},
}
ProfessionClothing.cheater = clothes
ProfessionClothing.cheater2 = clothes;
end
 
Events.OnGameBoot.Add(initTraits);
Events.OnGameBoot.Add(initProfessions);
Events.OnGameBoot.Add(initSpawnPoints);
Events.OnGameBoot.Add(initClothing);

 

That has been working for me for debugging purposes.

 

The first Profession spawns you in the warehouse, the second near the police station.

 

Thanks. I think the code in the tutorial still uses the old code for profession spawns which got changed recently. I'll update it soonish ;)

The apostrophe in the word "can't" causes the remainder of the code to appear commented out in the code shown after:

"The complete file should look like this:"

 

Blame the IPB folks for not finding lua-code-comments :D

Link to comment
Share on other sites

I have troubles with custom spawn points. I wrote down coordinates with http://pz-mods.net/other/CoordinateViewer/ but it spawn player in cell  +1x or +1y or both or none.I have no idea why,because some spawn points works  and all are empty tiles in buildings

 

local function initSpawnPoints()    local spawn    spawn = {       {worldX = 35,worldY = 32,posX = 201,posY = 223},---spawn at {worldX = 36,worldY = 33,posX = 201,posY = 223}       {worldX =35,worldY =31,posX =112,posY =9},---             spawn good       {worldX = 38,worldY = 36,posX = 16,posY = 190},---spawn at {worldX = 38,worldY = 37,posX = 16,posY = 190}       {worldX = 37,worldY = 32,posX = 175,posY = 134},---spawn at{worldX = 38,worldY = 32,posX = 175,posY = 134},       {worldX = 36,worldY = 33,posX = 289,posY =116 },---spawn at {worldX = 37,worldY = 33,posX = 16,posY = 190}       {worldX =35 ,worldY =33 ,posX =146 ,posY =229 },---spawn at {worldX =35 ,worldY =34 ,posX =146 ,posY =229 }    }    BaseGameCharacterDetails.spawnPoint.MuldraughKY.Handyman = spawn 
Link to comment
Share on other sites

I want  to make spawn point with coordinates

 

 worldX = 35,worldY = 32,posX = 201,posY = 223

 

but when i set it as spawnpoint,player is spawned on location

 

 {worldX = 36,worldY = 33,posX = 201,posY = 223}

 

what is in next cell x+1 and y+1.

 

Also others coordinates i tried spawn player in next cell x+1 or y+1.I tried 6 diffrent coordinates and only one spawn player in right cell.See code i posted above, in every line there are coordinates i want and then coordinates where player is actualy spawned

 

 

EDIT so Coordinate Viewer gives me values : {worldX = 36,worldY = 33,posX = 289,posY =116 }

 

i set spawnpoint in lua to cell under it :             {worldX = 35,worldY = 33,posX = 289,posY =116 }

 

it spawn me on right spot but Viewer say its    {worldX = 36,worldY = 33,posX = 289,posY =116 }

 

Maybe rounding problem in Coordinate viewer? You know sometimes it work good,sometimes change cell x, sometimes cell y , or both. 

 

Edit 2 its problem with rounding cells inCoordinate Viewer :

Absulte:

X: 10 789

Y: 10 016

 

Relative:

CellX: 36    !! its 35,9

CellY: 33

X: 289

Y: 116

Edited by Ramibuk
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...