manuelhimmler Posted November 24, 2009 Share Posted November 24, 2009 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
robhol Posted November 24, 2009 Share Posted November 24, 2009 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"; Link to comment
manuelhimmler Posted November 25, 2009 Author Share Posted November 25, 2009 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
eAi Posted November 25, 2009 Share Posted November 25, 2009 What are you actually trying to do? Link to comment
manuelhimmler Posted November 25, 2009 Author Share Posted November 25, 2009 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
subenji99 Posted November 25, 2009 Share Posted November 25, 2009 Lua isn't PAWN, you can define an array anywhere. Link to comment
manuelhimmler Posted November 25, 2009 Author Share Posted November 25, 2009 The experience was in LUA... Link to comment
DutchCaffeine Posted November 25, 2009 Share Posted November 25, 2009 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
50p Posted November 25, 2009 Share Posted November 25, 2009 http://www.lua.org/pil/2.5.html -.-' Link to comment
manuelhimmler Posted November 25, 2009 Author Share Posted November 25, 2009 ok thanks community, i thought it would be shorter than write everything like name, type in " "! But thanks! Link to comment
madis Posted November 26, 2009 Share Posted November 26, 2009 Yeah, the easiness of Lua tables are really impressive. Link to comment
Dark Dragon Posted November 26, 2009 Share Posted November 26, 2009 lua is easy in general, it takes care for you of almost anything Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now