WB Script - Quarchodron - 19.10.2015
Code: local LIMIT_VOBS = 8;
class WorldBuildner
{
constructor()
{
draw_WB = createDraw("World Buildner", "FONT_OLD_20_WHITE_HI.TGA", 6150, 800, 255, 255, 255);
draw_Collision = createDraw("Collision : YES", "FONT_OLD_10_WHITE_HI.TGA", 6150, 1100, 255, 255, 255);
draw_Position = createDraw("0 : 0 : 0", "FONT_OLD_10_WHITE_HI.TGA", 6150, 1300, 255, 255, 255);
draw_Rotation = createDraw("0 : 0 : 0", "FONT_OLD_10_WHITE_HI.TGA", 6150, 1500, 255, 255, 255);
draw_VobName = createDraw("No name", "FONT_OLD_10_WHITE_HI.TGA", 6150, 1700, 255, 255, 255);
draw_Height = createDraw("By Quarchodron", "FONT_OLD_10_WHITE_HI.TGA", 6150, 2100, 255, 255, 255);
draw_Lock = createDraw("Not closed", "FONT_OLD_10_WHITE_HI.TGA", 6150, 1900, 255, 255, 255);
texture_Look = createTexture(6000, 500, 1800, 2300, "FOCUS_HIGHLIGHT.TGA"),
setTimer(function(build)
{
if(build.wb_start == true)
{
local position = getVobPosition(build.vob);
local close = isVobLocked(build.vob);
local name = getInstance(build.vobid);
local colli = "YES";
if(close == false){close = "NO"}else{close = "YES"}
if(build.collision == false){colli = "NO"}else{colli = "YES"}
setDrawText(build.draw_Collision, format("Collision : %s", colli));
setDrawText(build.draw_Position, format("X %i Y %i Z %i", position.x,position.y,position.z));
setDrawText(build.draw_Rotation, format("X %i Y %i Z %i", build.Rotation.x,build.Rotation.y,build.Rotation.z));
setDrawText(build.draw_VobName, format("Nazwa : %s | %i |", name, build.vobid));
setDrawText(build.draw_Lock, format("Close : %s", close));
}
}, 700, true, this);
}
// START BUILD
function start()
{
if (wb_start == false)
{
setDrawVisible(draw_WB, true);
setDrawVisible(draw_Collision, true);
setDrawVisible(draw_Position, true);
setDrawVisible(draw_Rotation, true);
setDrawVisible(draw_VobName, true);
setDrawVisible(draw_Height, true);
setDrawVisible(draw_Lock, true);
setTextureVisible(texture_Look, true);
wb_start = true;
Rotation.x = 0;
Rotation.y = 0;
Rotation.z = 0;
currentid = 1;
vobid = 0;
local playpos = getPosition();
vob = createVob(getInstance(vobid), playpos.x+100, playpos.y, playpos.z, 0, 0, 0);
setCameraBehindVob(vob);
setVobCollision(vob, collision)
anyMapLoaded = true;
}
}
// CREATE NEW VOB
function create_NewVob()
{
local position = getVobPosition(vob);
local close = isVobLocked(vob);
local name = getInstance(vobid);
local colli = "YES";
if(close == false){close = "NO"}else{close = "YES"}
if(collision == false){colli = "NO"}else{colli = "YES"}
local pack = currentid + " " + name + " " + position.x + " " + position.y + " " + position.z + " " + Rotation.x + " " + Rotation.y + " " + Rotation.z + " " + colli + " " + close;
buildings[currentid] <- pack;
destroyVob(vob);
lastvob = createVob(name, position.x, position.y, position.z, Rotation.x, Rotation.y, Rotation.z);
setVobCollision(lastvob, collision)
currentid = currentid + 1;
vob = createVob(name, position.x+100, position.y, position.z, Rotation.x, Rotation.y, Rotation.z);
setCameraBehindVob(vob);
}
// END BUILD
function end()
{
if (wb_start == true)
{
setDrawVisible(draw_WB, false);
setDrawVisible(draw_Collision, false);
setDrawVisible(draw_Position, false);
setDrawVisible(draw_Rotation, false);
setDrawVisible(draw_VobName, false);
setDrawVisible(draw_Height, false);
setDrawVisible(draw_Lock, false);
setTextureVisible(texture_Look, false);
lastvob = null;
destroyVob(vob)
vob = null;
Rotation.x = 0;
Rotation.y = 0;
Rotation.z = 0;
vobid = 0;
setDefaultCamera();
wb_start = false;
}
}
function destroyVob_LastVob()
{
if(lastvob != null){
currentid = currentid -1;
destroyVob(lastvob);
buildings.rawdelete(currentid)}
}
// KEYS
function Keys_operation(key)
{
switch (key)
{
case KEY_W:
change_Position(5);
return 1;
case KEY_S:
change_Position(6);
return 1;
case KEY_Q:
change_Position(3);
return 1;
case KEY_E:
change_Position(4);
return 1;
case KEY_A:
change_Position(2);
return 1;
case KEY_D:
change_Position(1);
return 1;
case KEY_NUMPAD2:
change_Rotation(4);
return 1;
case KEY_NUMPAD8:
change_Rotation(3);
return 1;
case KEY_NUMPAD1:
change_Rotation(1);
return 1;
case KEY_NUMPAD3:
change_Rotation(2);
return 1;
case KEY_NUMPAD4:
change_Rotation(5);
return 1;
case KEY_NUMPAD6:
change_Rotation(6);
return 1;
case KEY_RETURN:
create_NewVob();
return 1;
case KEY_DELETE:
destroyVob_LastVob();
return 1;
case KEY_RIGHT:
if(vobid < LIMIT_VOBS)
{
vobid = vobid + 1;
local playpos = getVobPosition(vob);
destroyVob(vob);
vob = createVob(getInstance(vobid), playpos.x, playpos.y, playpos.z, Rotation.x, Rotation.y, Rotation.z);
}
return 1;
case KEY_LEFT:
if(vobid > 0)
{
vobid = vobid - 1;
local playpos = getVobPosition(vob);
destroyVob(vob);
vob = createVob(getInstance(vobid), playpos.x, playpos.y, playpos.z, Rotation.x, Rotation.y, Rotation.z);
}
return 1;
}
}
function change_Position(id)
{
if (wb_start == true)
{
switch (id)
{
case 1:
local position = getVobPosition(vob);
setVobPosition(vob,position.x + 10, position.y, position.z);
break;
case 2:
local position = getVobPosition(vob);
setVobPosition(vob,position.x - 10, position.y, position.z);
break;
case 3:
local position = getVobPosition(vob);
setVobPosition(vob,position.x, position.y + 10, position.z);
break;
case 4:
local position = getVobPosition(vob);
setVobPosition(vob,position.x, position.y - 10, position.z);
break;
case 5:
local position = getVobPosition(vob);
setVobPosition(vob,position.x, position.y, position.z + 10);
break;
case 6:
local position = getVobPosition(vob);
setVobPosition(vob,position.x, position.y, position.z - 10);
break;
}
}
}
function change_Rotation(id)
{
if (wb_start == true)
{
switch (id)
{
case 1:
if(Rotation.x + 5 < 181){
Rotation.x = Rotation.x + 5;}
break;
case 2:
if(Rotation.x - 5 > -1){
Rotation.x = Rotation.x - 5;}
break;
case 3:
if(Rotation.y + 5 < 181){
Rotation.y = Rotation.y + 5;}
break;
case 4:
if(Rotation.y - 5 > -1){
Rotation.y = Rotation.y - 5;}
break;
case 5:
if(Rotation.z + 5 < 181){
Rotation.z = Rotation.z + 5;}
break;
case 6:
if(Rotation.z - 5 > -1){
Rotation.z = Rotation.z - 5;}
break;
}
setVobRotation(vob,Rotation.x, Rotation.y, Rotation.z);
}
}
//CONSTRUCTION
wb_start = false;
vob = null;
lastvob = null;
buildings = {};
currentid = 0;
collision = true;
Rotation = { x = 0, y = 0, z = 0};
mapName = "Mapa Quara"
vobid = -1;
anyMapLoaded = false;
//DRAWS
draw_Collision = null;
draw_WB = null;
draw_Position = null;
draw_Rotation = null;
draw_VobName = null;
draw_Lock = null;
draw_Height = null;
texture_Look = null;
};
worldBuilder <- WorldBuildner();
addEvent("onKey", function(key, letter)
{
if (worldBuilder.wb_start == true && !isChatInputOpen()){worldBuilder.Keys_operation(key);}
if (key == KEY_F10)
{
if (worldBuilder.wb_start == true){
worldBuilder.end();
print("koniec");
}else if (!isChatInputOpen()){
print("Buduje ziomku z Quarem")
worldBuilder.start();}
}
});
//EXAMPLES ... CHANGE IT QUICKLY :) MAY BE BUGS
addEvent("onCommand", function(command, params)
{
switch (command)
{
case "mapname":
worldBuilder.mapName = params.tostring();
return 1;
case "save":
local file = fileOpen(worldBuilder.mapName, "w");
foreach(i, val in worldBuilder.buildings) {
fileWrite(file, val);
}
print("Zapisano")
fileClose(file);
return 1;
case "load":
if(worldBuilder.anyMapLoaded == false){
worldBuilder.currentid = 1;
local argsa = sscanf("s", params);
local file = fileOpen(argsa, "r+");
if(file){
local buffer = "";
while(fileRead(file, buffer))
{
local args = sscanf("dsddddddss", buffer);
local pack = args[0] + " " + args[1] + " " + args[2] + " " + args[3] + " " + args[4] + " " + args[5] + " " + args[6] +" " + args[7]+ " " + args[8]+ " " + args[9];
worldBuilder.buildings[worldBuilder.currentid] <- pack;
worldBuilder.currentid = worldBuilder.currentid + 1;
local vos = createVob(args[1], args[2], args[3],args[4], args[5], args[6], args[7]);
setVobCollision(vos, translateToBoolean(args[8]))
setVobLocked(vos, translateToBoolean(args[9]))
}
print("Załadowano")
worldBuilder.anyMapLoaded = true;
fileClose(file);
}
}
return 1;
case "collision":
local args = sscanf("d", params);
if(args)
{
print("Zmieniono")
if(args[0] == 0){worldBuilder.collision = false;}else{worldBuilder.collision = true;}
if(worldBuilder.wb_start == true){setVobCollision(worldBuilder.vob, worldBuilder.collision)}
}
else{
addMessage(255, 0, 0, "Użyj: /collision <1> <0>");}
return 1;
case "lock":
local args = sscanf("d", params);
if(args)
{
print("Zmieniono")
local lock = false;
if(args[0] == 1){lock = true;}else{lock = false;}
if(worldBuilder.wb_start == true){setVobLocked(worldBuilder.vob, lock)}
}
else{
addMessage(255, 0, 0, "Użyj: /lock <1> <0>");}
return 1;
}
});
function translateToBoolean(value)
{
local clasz = false;
if(value == "YES"){clasz = true}
return clasz;
}
// SIMPLE EXAMPLE TO GETINSTANCE
Code: local List = [
"MIN_LOB_PLANKS_2X4M.3DS",
"MIN_LOB_PLANKS_2X5M.3DS",
"MIN_LOB_PLANKS_3X11M.3DS",
"MIN_LOB_PLANKS_3X7M.3DS",
"MIN_LOB_STANDINGWORKPLANK_5X7M.3DS",
"MIN_LOB_STOMPERSTAND.3DS",
"MIN_LOB_STONE_V3_50.3DS",
"MIN_LOB_WINKELSTEG.3DS",
"MIN_LOB_WORKPLANK_4X6M.3DS",
"MIN_LOB_WORKPLANK_5X7M.3DS",
"MIN_ORE_BIG_V1.3DS",
"MIN_ORE_BIG_V2.3DS",
];
function getInstance(id)
{
foreach (i,val in List)
{
if (i == id){
return val.tostring();
}
}
};
WORLD BUILDNER alpha
Możliwości :
- Możliwość postawienia i zapisania wielu vobów.
- Możliwe jest wczytywanie i zapisywanie map.
- Rotacja vobami.
- Poruszanie nimi.
- Ustalenie kolizji z graczem w trybie rzeczywistym.
- Ustawienie trybu zamkniętego dla danego voba. Np. drzwi.
- Proste i szybkie operacje na zmianach voba.
Dodane wkrótce :
- System dodania klucza w trybie rzeczywistym.
- Możliwość ustawienia prędkości VOB'a.
- Skoordynowanie poruszania się z rotacją voba.
- Ulepszona praca kamery nad vobem.
RE: WB Script - Kladvey - 06.01.2016
Where writing it code? I'm try using command - not reaction on system.
RE: WB Script - AJJ - 07.01.2016
I think on the client-side scripts
(Возможно в клиентских скриптах, попробуй создать файл и закинуть все это, и подключить в конфиге)
RE: WB Script - Razir - 07.01.2016
You can ask the entire script?
RE: WB Script - Profesores - 07.01.2016
(07.01.2016, 19:52)Razir Wrote: You can ask the entire script? Kurwa Razir, jeśli nie umiesz angielskiego to nie pisz, bo zacznę Ci osty wpierdalać za te bezsensowne posty.
RE: WB Script - Quarchodron - 15.02.2016
Big Update! Version : Alpha 0.1
RE: WB Script - Bimbol - 15.02.2016
Maybe better getInstance like this:
Squirrel Script function getInstance(id) { if (id >= 0 && id < List.len()) return List[id] return null; };
Edit. Performance of this code is O(1), but your code is O(n).
RE: WB Script - Quarchodron - 15.02.2016
Ok. Thx. I say..it is only example.
RE: WB Script - Bimbol - 15.02.2016
I know, but most of scriptes will use this example
|