Skull Random In monsters

eduardbean

Member
Joined
Nov 26, 2010
Messages
124
Reaction score
11
Descrição:
Nome : Monster Skull randomicas
Versão : 8.54

Well the open Soucer and goes : luascript.cpp and search:

Code:
int32_t LuaScriptInterface::luaGetPlayersOnline(lua_State* L)
{
	//getPlayersOnline()
	ScriptEnviroment* env = getEnv();
	AutoList<Player>::iterator it = Player::autoList.begin();
 
	lua_newtable(L);
	for(int32_t i = 1; it != Player::autoList.end(); ++it, ++i)
	{
		lua_pushnumber(L, i);
		lua_pushnumber(L, env->addThing(it->second));
		pushTable(L);
	}
	return 1;
}
beneath it Add this :

Code:
int32_t LuaScriptInterface::luaCheckSpawnMonster(lua_State* L)
{
	ScriptEnviroment* env = getEnv();
	AutoList<Monster>::iterator it = Monster::autoList.begin();
 
	lua_newtable(L);
	for(int32_t i = 1; it != Monster::autoList.end(); ++it, ++i)
	{
		lua_pushnumber(L, i);
		lua_pushnumber(L, env->addThing(it->second));
		pushTable(L);
	}
	return 1;
}
Now Look for these lines
Code:
//getPlayersOnline()
	lua_register(m_luaState, "getPlayersOnline", LuaScriptInterface::luaGetPlayersOnline);
beneath it Add this :

Code:
//checkSpawnMonster()
	lua_register(m_luaState, "checkSpawnMonster", LuaScriptInterface::luaCheckSpawnMonster);
NOW IN LUASCRIPT.H SEARCH THIS LINE:

Code:
static int32_t luaGetPlayersOnline(lua_State* L);
E bote isso embaixo dela:
Code:
static int32_t luaCheckSpawnMonster(lua_State* L);
Eventually the system, Now you two ways to use this script

1° Talkactions (when you speak the command it will give a random skull for each monster, the more if he dies will come without skull)

Data/Talkactions/Scripts

Code:
function onSay(cid, words, param, channel)
	local m = checkSpawnMonster

	for _, mid in ipairs(m) do
		local mpos = getThingPos(mid)
		doCreatureSetSkullType(mid, math.random(1, 5))
	end
	return 0
end
Now create a tag and use the system.

2 way, Globalevents (now respawn every skull comes with it, + it takes about a thousandth of a second to add the skull.)

Data/globalevents/scripts

Code:
function onThink(interval, lastExecution, thinkInterval)
    local m = checkSpawnMonster()
    local sex = {1, 2} -- numero da skull ou seja, desenho do sexo

	for _, mid in ipairs(m) do
		local mpos = getThingPos(mid)
		if (getCreatureSkullType(mid) == 1) or (getCreatureSkullType(mid) == 2) then
		else
		    doCreatureSetSkullType(mid, math.random(1, #sex))
		end
	end
	return 0
end
Data/Globalevents/Globalevents.xml

Code:
	<globalevent name="sex" interval="0" event="script" value="sex.lua"/>
Good guys this script a friend made for me

If u use please ++rep
 

Adrenaline

Waiting for God
Joined
Jun 13, 2011
Messages
80
Reaction score
6
Location
Poland
mmm.. i use it.. now i need random level before name monster ^^ "12 lvl Rat" "51 lvl Demon" :D
 

Adrenaline

Waiting for God
Joined
Jun 13, 2011
Messages
80
Reaction score
6
Location
Poland
I have question.. this modification charge the server?.. can lag server? :SSSS

@Edit
Shit modification :/ idea great but really LAG server .. not recommend
 
Last edited:

KylerXX

Active Member
Joined
Jun 24, 2010
Messages
439
Reaction score
27
Its normal, the interval is 0, you need a creature event function, for example onSpawn(cid), you can find on the C++ Codes section.
 

Zaxuhe

C++ PHP
Joined
Jan 1, 2008
Messages
228
Reaction score
4
if a lot of monsters are spawned it will lag, because it calls lua, it should be implemented when spawned and not to call a new lua function because doing so will burn a lot of resources.
 
OP
E

eduardbean

Member
Joined
Nov 26, 2010
Messages
124
Reaction score
11
I've tested the script by talkaction and was at all without crashing the server (all at the same time)
 

maikons

Member
Joined
Aug 1, 2015
Messages
153
Reaction score
8
Why not work in 0.4?

Code:
In file included from luascript.h:33:0,
                 from luascript.cpp:18:
luascript.cpp: In member function ‘virtual void LuaInterface::registerFunctions()’:
luascript.cpp:1408:51: error: ‘LuaScriptInterface’ has not been declared
     lua_register(m_luaState, "checkSpawnMonster", LuaScriptInterface::luaCheckS
                                                   ^
/usr/include/lua5.1/lua.h:260:53: note: in definition of macro ‘lua_pushcfunction’
 #define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0)
                                                     ^
luascript.cpp:1408:5: note: in expansion of macro ‘lua_register’
     lua_register(m_luaState, "checkSpawnMonster", LuaScriptInterface::luaCheckS
     ^
luascript.cpp: At global scope:
luascript.cpp:9307:9: error: ‘LuaScriptInterface’ has not been declared
 int32_t LuaScriptInterface::luaCheckSpawnMonster(lua_State* L)
         ^
luascript.cpp: In function ‘int32_t luaCheckSpawnMonster(lua_State*)’:
luascript.cpp:9309:36: error: ‘getEnv’ was not declared in this scope
     ScriptEnviroment* env = getEnv();
                                    ^
luascript.cpp:9317:20: error: ‘pushTable’ was not declared in this scope
         pushTable(L);
                    ^
 

heba

Veteran OT User
Joined
Aug 5, 2011
Messages
1,346
Reaction score
167
for 0.4
Code:
int32_t LuaInterface::luaCheckSpawnMonster(lua_State* L)
{
    ScriptEnviroment* env = getEnv();
    AutoList<Monster>::iterator it = Monster::autoList.begin();
    lua_newtable(L);
    for(int32_t i = 1; it != Monster::autoList.end(); ++it, ++i)
    {
        lua_pushnumber(L, i);
        lua_pushnumber(L, env->addThing(it->second));
        pushTable(L);
    }
    return 1;
}
Code:
    //checkSpawnMonster()
    lua_register(m_luaState, "checkSpawnMonster", LuaInterface::luaCheckSpawnMonster);
 

jel

Well-Known Member
Joined
Mar 22, 2014
Messages
34
Reaction score
2

Westwol

Member
Joined
Sep 19, 2018
Messages
55
Reaction score
13
How many arguments are you passing through the function? Post the line.

Anyways you could always do:
C++:
skull = uniform_random(0, 5);
 
Top