Jump to content

How to use enum (PWN) in LUA???


manuelhimmler

Recommended Posts

Hello script-whizes!

How to use this PWN-Code in LUA?

enum vehs
{
model,
ccolor1,
ccolor2,
};
new cvehicle[MAX_VEHICLES][vehs]

For Example in PWN I can write something in these varables:

cvehicle[2][model]

cvehicle[2][ccolor1]

cvehicle[2][ccolor2]

Instead of 2 i can change it to any vehicleid under the maximum (MAX_VEHICLES)

I would to load something from MYSQL in such variables, but I don't know to define them, here i give an example how I wanted to use such variables:

PlayerInfo[player][health]

PlayerInfo[player][level]

...

Please help me.

Link to comment
You can just use strings.

The equivalent Lua code is soemthing like

cvehicle = {};
cvehicle[1] = {}; -- or any other number, obviously
 
cvehicle[1]["name"] = "foo";
OR
cvehicle[1].name = "bar";

Thanks but instead of 1 should be a player or something and I have the experience, that I can't define an array in a function

Link to comment

I would to load something from MYSQL in such variables, but I don't know to define them, here i give an example how I wanted to use such variables:

PlayerInfo[player][health]

PlayerInfo[player][level]

I wanted many player-values to write in such variables, like setElementData(player,"player.health",100), but better an shorter is

PlayerInfo[player][health]=100

Link to comment

Look, enums in pawno are almost like tables in lua.

Uhm yes, now i get to fast he, now let me give you some examples:

Enum in pawno:

enum ePlayerInfo  {
    name,
    type,
    Float:lastX,
    Float:lastY,
    Float:lastX,
};
 
// to store the player info
new gPlayerInfo[MAX_PLAYERS][ePlayerInfo];
 
public function onPlayerConnect(player) {
    gPlayerInfo[player][name] = getPlayerName(player);
    gPlayerInfo[player][type] = 0;
}

That was an easy example for how to use enum in pawno, but this aint the samp forum, and eAi, and every other mta developer or big mta fan will be angry on me now. Because i brought a little bit of samp to here. But please before you all going to slep me, let me explain now the lua table. Uhm that is where it goes about he?

The lua table is almost the same as enum, but the eisier!

-- Writing some good old lua
gPlayerInfo = {}; -- make a table
 
function playerJoin() 
    gPlayerInfo[source]["name"] = getPlayerName(source);
    gPlayerInfo[source]["type"] = 0; -- just a normal player.
end
 
addEventHandler("onPlayerJoin", getRootElement(), playerJoin);

It works allmost the same, and btw. the code is a bit more smaller. Uninstall sa-mp and play and script for MTA!

Alexander.

P.S. Look into the admin resource sourcecode and you can find in one of the scripts an enum thing, look there for some advanced usage of lua.

Link to comment

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...