Xierra Posted March 6, 2010 Share Posted March 6, 2010 Hi guys I have a problem. When I create an xpeffects function (addXpEffect), and I want to make it work on another resource. It's a client-side script. But how can I do it? Should I export functions? If yes, How? Because I got an error "ERROR:.../deathmatch/resources/test/aaa.lua:2:Trying to call global "addXpEffect" (a nil value)" The script (aaa.lua): function xpea() string = addXpEffect("AA", "+1000", {r=100, g=0, b=0}) --the xpeffects function. if (string) then outputChatBox("It's working!") else outputChatBox("no it's not working") end end addCommandHandler ( "xp", xpea) Meta.xml: <meta> <script src="aaa.lua" /> meta> Can you guys learn me the easy way of exporting functions from another resource? Link to comment
Xeno Posted March 6, 2010 Share Posted March 6, 2010 Sorry, i dont understand what its for? Link to comment
karlis Posted March 6, 2010 Share Posted March 6, 2010 first of all i think holding RGB in table is not best way, second: u need export function by adding <export function="name" type="client" /> to meta.xml third: use exports.callressourcename:functionname() Link to comment
Mr.Hankey Posted March 6, 2010 Share Posted March 6, 2010 First of all please try indenting your code That improves the readability pretty much. Anyway I guess you rather want to call an exported function than exporting a function yourself so in this case you need to make use of the call function which allows you to call exported functions of other resources. Assuming that you're trying to use my xpeffects resource you also need to correct some other mistakes: First of all it's addXPEffects with both X and P being capital letters, secondly the function doesn't return anything so the "string" variable will always be nil and last the color argument needs to be a table in this form {r, g, b}. So in the end your code should look something like this: function xpea () exports.xpeffects:addXPEffect ( "AA", "+1000", {100, 0, 0} ) end addCommandHandler ( "xp", xpea ) Link to comment
Xierra Posted March 6, 2010 Author Share Posted March 6, 2010 Yeah. Now it "Nearly" works. It says: ERROR: call: failed to call 'xpeffects:addXPEffect' What should I do? (Hey and thanks mr.hankey, i'm practicing you know) This is used for my edit of the cs_sounds resource. Link to comment
Mr.Hankey Posted March 6, 2010 Share Posted March 6, 2010 Make sure that the xpeffects resource is running (Edit:) and that you're using it clientside as the server-side function would be addPlayerXPEffect which also takes a player argument. Link to comment
Xierra Posted March 6, 2010 Author Share Posted March 6, 2010 I already activated the resource. but still not working ;( uhh, I guess this is xpeffect's fault: WARNING: xp_server.lua: Bad argument @ 'triggerClientEvent' - Line: 2 Link to comment
Mr.Hankey Posted March 6, 2010 Share Posted March 6, 2010 look at the syntax of addPlayerXPEffects: addPlayerXPEffect ( player, title, description, color ) As i said it also takes a player element as first argument which is probably what you forgot and thus causing that error. Link to comment
Xierra Posted March 6, 2010 Author Share Posted March 6, 2010 At last it's working! Thanks Hankey. Link to comment
Xierra Posted March 7, 2010 Author Share Posted March 7, 2010 Before I end this topic, the syntax ( player, title, description, color ) In cs_sounds, It doesn't have "player" inside the function, but the script have argument "killer" Will it ok if I write something like: (killer, "AA", "+1000", {200,200,200}) I'm not sure yet because Nobody is gonna test it for me. A little tip: I am trying to make use of xpeffects script, that's why I edit cs_sounds script. Link to comment
Gamesnert Posted March 7, 2010 Share Posted March 7, 2010 I'm not sure if I understand what you mean, but the name shouldn't matter. Naming a variable "player" or "killer" or "cake" won't change its content. EDIT: Ok, that was a stupid mistake of mine. Thanks 50p. Link to comment
50p Posted March 7, 2010 Share Posted March 7, 2010 I'm not sure if I understand what you mean, but the name shouldn't matter. Naming a variable* "player" or "killer" or "cake" won't change its content. Link to comment
Xierra Posted March 7, 2010 Author Share Posted March 7, 2010 Hah, that should be an argument not variable! Link to comment
Gamesnert Posted March 7, 2010 Share Posted March 7, 2010 Hah, that should be an argument not variable! An argument is also a variable. 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