Jump to content

RPG-X2-Lua Programming


  • You cannot reply to this topic

21 replies to this topic

#1 Harry Young

Harry Young

    Ubergames Lead Lua Coder

  • UberGames Developer
  • 291 posts

Posted 18 May 2011 - 12:28 PM

Thought it might be a good idea to start a thread where Lua-Problems for RPGX2 can be discussed centrally. I'm gonna start right away:

I have written a script which should Move a thing from A to B. The Code is:

function testtrain()
	ent = entity.Find(ASUO-Intrepid);
	mover.ToPosition(ent, 100, -12288, 16384, 8192);
end

It is hooked up to a usable and when I use it I get:

[COLOR="Yellow"]Lua: testtrain error running lua script: [string
"scripts/lua/dsss-mammoth/dsss-mammoth.lua"]:21: attempt to perform
arithmetic on global 'ASUO' (a nil value)[/COLOR]

Since there seems to be an issue withe the targetname (which is unique) i tried to alter that so I got

function testtrain()
	ent = entity.Find(ASUOIntrepid);
	mover.ToPosition(ent, 100, -12288, 16384, 8192);
end

And

[COLOR="Yellow"]Lua: testtrain error running lua script: [string
"scripts/lua/dsss-mammoth/dsss-mammoth.lua"]:21: bad argument #1 to 'Find'
(string expected, got nil))[/COLOR]
Anyone knowing what I'm up to here?

#2 GSIO01

GSIO01

    UberGames Developer

  • UberGames Developer
  • 1,021 posts

Posted 18 May 2011 - 04:47 PM

It's a good idea to create such a thread.

Your code is incorrect, it should be:
function testtrain()
	ent = entity.Find("ASUOIntrepid");
	mover.ToPosition(ent, 100, -12288, 16384, 8192);
end

A string which is what the function takes as argument has to be inside "" in Lua (and many other programming languages).

#3 Harry Young

Harry Young

    Ubergames Lead Lua Coder

  • UberGames Developer
  • 291 posts

Posted 18 May 2011 - 04:50 PM

Result:
Entity_Find - entity 'ASUOIntrepid' not found!
[COLOR="Yellow"]Lua: testtrain error running lua script: [string
"scripts/lua/dsss-mammoth/dsss-mammoth.lua"]:22: bad argument #1 to
'ToPosition' (game.entity expected, got nil)[/COLOR]


#4 GSIO01

GSIO01

    UberGames Developer

  • UberGames Developer
  • 1,021 posts

Posted 19 May 2011 - 06:17 AM

Seemingly the entity find function is not able to find your entity. Please note that the function is case sensitive so make sure targetname in the script and the entity are the same. What actual class is the entity you want to move of? Check if it really is there (it might have been removed by the game due to errors) with the getEntByTargetname command which is searching for entities the same way as the lua function does.

#5 Harry Young

Harry Young

    Ubergames Lead Lua Coder

  • UberGames Developer
  • 291 posts

Posted 19 May 2011 - 11:59 AM

It's a misc_model and I guess thats the problem here...

#6 GSIO01

GSIO01

    UberGames Developer

  • UberGames Developer
  • 1,021 posts

Posted 19 May 2011 - 12:15 PM

Yeah that wont work ... I suggest you use q3map2 to bind the misc_model to a func_static (caulk + origin brush) an move the func_static.

#7 Harry Young

Harry Young

    Ubergames Lead Lua Coder

  • UberGames Developer
  • 291 posts

Posted 19 May 2011 - 12:53 PM

Okay, I'm going to try that

#8 Harry Young

Harry Young

    Ubergames Lead Lua Coder

  • UberGames Developer
  • 291 posts

Posted 19 May 2011 - 03:03 PM

Okay I got it working, thanks.

Just to be sure on this: luaThink is for Non-brush-Ents what luaUse is for usables, right?

#9 GSIO01

GSIO01

    UberGames Developer

  • UberGames Developer
  • 1,021 posts

Posted 19 May 2011 - 06:11 PM

luaThink is a function that gets called if any entities think function is called which is done regularly on many function. luaUse is alwasy called if an entity is used this is also the case for non brush entities.

#10 Harry Young

Harry Young

    Ubergames Lead Lua Coder

  • UberGames Developer
  • 291 posts

Posted 19 May 2011 - 06:41 PM

Ah, okay, that was the last piece I needed for this Puzzle. Now it's just setting up the radiant-Side (Quite some Booleans and relays I'm looking at) and then finish up the lua-code. Thanks for your help, Gsio ^^

#11 Harry Young

Harry Young

    Ubergames Lead Lua Coder

  • UberGames Developer
  • 291 posts

Posted 21 May 2011 - 10:37 PM

Okay, here is another question:

ent.SetKeyValue(entity ent, string key, string value) or ent:SetKeyValue(string key, string value)
Sets a key-value pair for ent like in Radiant. Only works if the key is part of fi elds_t
(predefi ned keys).

What exactly is 'fields_t', Where can I find them and what does that mean for definitions in radiant vs in lua (like target_turbolift where for 'deck' you have to use 'health' instead)

#12 GSIO01

GSIO01

    UberGames Developer

  • UberGames Developer
  • 1,021 posts

Posted 22 May 2011 - 06:59 AM

Yeah new that question would come up sooner or later. here is fields_t as it is right now:

field_t fields[] = {
{"classname", FOFS(classname), F_LSTRING},
{"origin", FOFS(s.origin), F_VECTOR},
{"model", FOFS(model), F_LSTRING},
{"model2", FOFS(model2), F_LSTRING},
{"spawnflags", FOFS(spawnflags), F_INT},
{"speed", FOFS(speed), F_FLOAT},
{"target", FOFS(target), F_LSTRING},
{"paintarget", FOFS(paintarget), F_LSTRING},
{"targetname", FOFS(targetname), F_LSTRING},
{"message", FOFS(message), F_LSTRING},
{"team", FOFS(team), F_LSTRING},
{"splashDamage", FOFS(splashDamage), F_INT},
{"splashRadius", FOFS(splashRadius), F_INT},
{"wait", FOFS(wait), F_FLOAT},
{"random", FOFS(random), F_FLOAT},
{"count", FOFS(count), F_INT},
{"material", FOFS(s.powerups), F_INT},
{"health", FOFS(health), F_INT},
{"light", 0, F_IGNORE},
{"dmg", FOFS(damage), F_INT},
{"angles", FOFS(s.angles), F_VECTOR},
{"angle", FOFS(s.angles), F_ANGLEHACK},
{"pos2", FOFS(pos2), F_VECTOR},
{"apos1", FOFS(apos1), F_VECTOR},
{"apos2", FOFS(apos2), F_VECTOR},
{"swapname", FOFS(swapname), F_LSTRING}, //RPG-X Modification | Phenix | 13/06/2004
{"truename", FOFS(truename), F_LSTRING},
{"falsename", FOFS(falsename), F_LSTRING},
{"truetarget", FOFS(truetarget), F_LSTRING},
{"falsetarget", FOFS(falsetarget), F_LSTRING},
{"booleanstate", FOFS(booleanstate), F_INT},
{"distance", FOFS(distance), F_FLOAT},
{"targetname2", FOFS(targetname2), F_LSTRING },
{"bluename", FOFS(bluename), F_LSTRING},
{"greensnd", FOFS(greensound), F_LSTRING},
{"yellowsnd", FOFS(yellowsound), F_LSTRING},
{"redsnd", FOFS(redsound), F_LSTRING},
{"bluesnd", FOFS(bluesound), F_LSTRING},
{"targetShaderName", FOFS(targetShaderName), F_LSTRING},
{"targetShaderNewName", FOFS(targetShaderNewName), F_LSTRING},
#ifdef G_LUA
{"luaThink", FOFS(luaThink), F_LSTRING},
{"luaTouch", FOFS(luaTouch), F_LSTRING},
{"luaUse", FOFS(luaUse), F_LSTRING},
{"luaHurt", FOFS(luaHurt), F_LSTRING},
{"luaDie", FOFS(luaDie), F_LSTRING},
{"luaFree", FOFS(luaFree), F_LSTRING},
{"luaTrigger", FOFS(luaTrigger), F_LSTRING},
{"luaReached", FOFS(luaReached), F_LSTRING},
{"luaReachedAngular", FOFS(luaReachedAngular), F_LSTRING},
{"luaSpawn", FOFS(luaSpawn), F_LSTRING},

{"luaParm1", FOFS(luaParm1), F_LSTRING},
{"luaParm2", FOFS(luaParm2), F_LSTRING},
{"luaParm3", FOFS(luaParm3), F_LSTRING},
{"luaParm4", FOFS(luaParm4), F_LSTRING},
{"luaEntity", FOFS(luaEntity), F_INT},
#endif
{NULL}
};


Anything that is not included can't be used with this function now.

As for the second part of your question:
As you have noticed some entities such as target_turbolift use keys like 'deck' which are not in fields_t. These are named in such a way to make your work easier but are stored in objects of the struct representing the entity (gentity_s). For example 'deck' is an int value and in the code it is stored in the int variable health of gentity_s .

I might find a way to make SetKeyValue work for those keys but for now if you need to know where to store on just feel free to asked here.

#13 Harry Young

Harry Young

    Ubergames Lead Lua Coder

  • UberGames Developer
  • 291 posts

Posted 22 May 2011 - 09:26 AM

Thanks, might be good if you add them to the Lua tutorial next time.

#14 Harry Young

Harry Young

    Ubergames Lead Lua Coder

  • UberGames Developer
  • 291 posts

Posted 22 May 2011 - 12:45 PM

Okay, I believe I am at the point where I need some of these information. I am Planning to boost the einterprise-e-v2-alerts with the target_alert (for one can't really say console-control won't be helpful with those small buttons)

#15 GSIO01

GSIO01

    UberGames Developer

  • UberGames Developer
  • 1,021 posts

Posted 22 May 2011 - 08:03 PM

ok here we go ... syntax key -> field means the key key is saved into the field field.

greename -> swapname
yellowname -> truename
redname -> falsename
bluename -> bluename
greentarget -> truetarget
yellowtarget -> falsetarget
redtarget -> paintarget
bluetarget -> targetname2

greenshader, yellowshader, redshader, blueshader get parsed and not stored directly

#16 Harry Young

Harry Young

    Ubergames Lead Lua Coder

  • UberGames Developer
  • 291 posts

Posted 23 May 2011 - 10:14 AM

Hm... It crashed... but I guess that's due to the map. I'm simply going to skip that.

#17 Harry Young

Harry Young

    Ubergames Lead Lua Coder

  • UberGames Developer
  • 291 posts

Posted 10 July 2011 - 07:59 PM

Okay, Gsio, could you please break func_forcefield down for me? I have an issue here where I have to convert a func_door to a func_forcefield and get the forcefield toggeled on and off within a second.

#18 Harry Young

Harry Young

    Ubergames Lead Lua Coder

  • UberGames Developer
  • 291 posts

Posted 10 July 2011 - 09:42 PM

Strike that, seems like I found a bug by wich lua-spawned target_delays do either work like relays or only have a minimal delay regardless of it's wait-value.

#19 GSIO01

GSIO01

    UberGames Developer

  • UberGames Developer
  • 1,021 posts

Posted 11 July 2011 - 08:48 AM

Add it to the bugtracker I'll check it once I have time again.

#20 Harry Young

Harry Young

    Ubergames Lead Lua Coder

  • UberGames Developer
  • 291 posts

Posted 11 July 2011 - 10:33 AM

Will do.

Is there a way to create a similar delay by a luaUse-function?



0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users