PDA

View Full Version : Finding Variables / Functions


RPRaiden
04-21-2004, 16:30
When making scripts where do you find the variables or functions ect to use in the plugins ... what I mean is say I wanted to make a command that edits ones name, i.e. amx_name <target> <name>. Where do I get the info on variables to use for editing that persons name.

I want to start on a Role System plugin, when a player joins the server automaticly adds [Civ] to the end of his/her name and it can be changed by using amx_role <role> as long as its in a list located in a .txt file.

IceMouse[WrG]
04-21-2004, 16:47
We'll you should first think of all the ways to set a name... First is the command name, and the other way is to setinfo name... So then you would look through the incs that could do one of the functions(There happends to be one to execute a command, and one to set a users info), and decide which is better for your purpose

RPRaiden
04-22-2004, 15:57
]We'll you should first think of all the ways to set a name... First is the command name, and the other way is to setinfo name... So then you would look through the incs that could do one of the functions(There happends to be one to execute a command, and one to set a users info), and decide which is better for your purpose

but where exactly do I look,

IceMouse[WrG]
04-22-2004, 17:37
Addons\amxx\scripting\includes

RPRaiden
04-22-2004, 17:38
thanks m8

RPRaiden
04-22-2004, 17:42
]We'll you should first think of all the ways to set a name... First is the command name, and the other way is to setinfo name... So then you would look through the incs that could do one of the functions(There happends to be one to execute a command, and one to set a users info), and decide which is better for your purpose

Is it possible to define a variable to be the original name and then use the command name variablename[Civ]. Wish the variablename being the players original name.

i.e.

Player has entered the game, (Define Player as existingname) then the plugin adds the role to the end of there name by using name "existingname[Civ]" (Civ being the role, existing name being the variable)

RPRaiden
04-22-2004, 17:54
hold on why am I trying to make it harder formyself, couldnt I just do:

name "%NAME%[Civ]" as the command?

xeroblood
04-22-2004, 17:54
// Assuming you know the ID of the player...
new username[32]
get_user_name( id, username, 31 )



Edit: is %NAME% used in HL Engine as a reference to the current name??

RPRaiden
04-22-2004, 18:10
This is what i've currently got basing my code on the join_leave plugin.


// Role Adder v1.0 by RPRaiden
// When client connect to a game the console automaticly
// adds a role to the end of the players name.


#include <amxmodx>

public plugin_init() {
register_plugin("Role Adder","1.0","RPRaiden")
register_cvar("amx_rolechange","1")
register_cvar("amx_roleone", "Name %name%[Civ]")
}

public client_putinserver(id){
new user[32], len
user[0] = id
len = get_user_name(id,user[1],31)
set_task(2.0, "addrole", 0, user,len + 2)
return PLUGIN_CONTINUE
}

public client_disconnect(id){
new user[32], len
user[0] = id
len = get_user_name(id, user[1], 31)
set_task(2.0, "removerole", 0, user, len + 2)
return PLUGIN_CONTINUE
}


public addrole(user[]) {
if (get_cvar_num("amx_rolechange")==0){
return PLUGIN_HANDLED
}
if (get_cvar_num("amx_rolechange")==1){
set_user_info(index,const info[],const value[])

at the moment im trying to get the plugin to add the role to the users name, so I found set_user_info, I pasted the command in and now im trying to find out where to put it. In the existing code it says:

public joined_msg(user[]) {
if (get_cvar_num("amx_join_leave")==0){
return PLUGIN_HANDLED
}
if (get_cvar_num("amx_join_leave")==1){
new message[192]
get_cvar_string("amx_joined_message", message, 191)
replace(message, 191, "%name%", user[1])
set_hudmessage(0, 225, 0, 0.05, 0.55, 0, 6.0, 6.0, 0.5, 0.15, 3)
show_hudmessage(0, message)
return PLUGIN_CONTINUE
}
return PLUGIN_CONTINUE

But thats used to make a message on the hud. I will greatly appriciate it if you could tell me what each line does from get_cvar_string (which I understand the command just not the message and 191) down to replace.

xeroblood
04-22-2004, 18:25
public joined_msg(user[]) {
if (get_cvar_num("amx_join_leave")==0){
return PLUGIN_HANDLED
}
if (get_cvar_num("amx_join_leave")==1){

// Creates a String type variable of SIZE 192 Characters
new message[192]

// This next line gets the Value of the CVAR from the Server and puts
// the value into your 'message' variable created above. the 191 is
// only SIZE - 1 (or 192-1) this is because an Array of 192 used as a
// String needs a Null-Terminating character to mark the End of the
// String of characters (in C/C++ this Null Character is a \0 )
get_cvar_string("amx_joined_message", message, 191)

// This function will Replace any occurence of "%name%"
// with the value of user[1] in the variable 'message'
replace(message, 191, "%name%", user[1])

// This sets the properties for displaying a HUD Message
// Look in include file (amxmodx.inc) for more info on it..
set_hudmessage(0, 225, 0, 0.05, 0.55, 0, 6.0, 6.0, 0.5, 0.15, 3)

// this function shows the String 'message' on the screen using the
// properties set from above
show_hudmessage(0, message)

// return PLUGIN_CONTINUE means end the function and pass control
// back to AMXX. (PLUGIN_CONTINUE is used here probably because
// this function was called by a Registered Event, and the Event should
// not stop here, rather Continue with other plugins also calling this event)
return PLUGIN_CONTINUE
}

// if the IF statement from above is false, then this function does
// nothing, and returns control back to AMXX (like above comment).
return PLUGIN_CONTINUE


This function, of course, will need to be called (and I am assuming it is being triggered by an event)

Hope that helps..

RPRaiden
04-22-2004, 18:32
that was a great help, thanks m8.
Dont suppose you could "Translate" this?
native set_user_info(index,const info[],const value[]);

DFA-Haplo
04-22-2004, 20:19
Can anyone tell me where to find or look for a list of Events? Like I learned that DeathMsg is an event but what are names of others? I dug through the Includes.

QwertyAccess
04-22-2004, 20:34
you have to look in the HLDSK i think

xeroblood
04-22-2004, 21:00
@RPRaiden:

This function sets differnet types of info on the player specified by 'index', the 'info' variable is the type of info you want to set on the specified player, 'value' is the new Value of the specified players info.

For name, you would use "name" as the 'info', and 'value' would be the new player name...

set_user_info( playerID, "name", "xeroblood" )

@DFA-Haplo:
I found this once long ago on AMX forums (they are all HL events, not AMX/X specific), i forget who originally wrote/posted it, but here it is..

DFA-Haplo
04-23-2004, 01:19
thank you xeroblood.

QwertyAccess
04-23-2004, 01:35
nice

RPRaiden
04-23-2004, 17:06
cheers xeroblood, I know know what the info and value are for most of the things. Index is a little bit tricky but its not too bad now. You helped me out so many times now, cheers. btw can %name%[Civ] be used as the value?

RPRaiden
04-23-2004, 17:57
Okay ive got a plugin to a stage I wish to test it at. Basicly I want it so when the player joins the game the plugin adds [Civ] to there name, thats the first stage. I commented out the cvar register_cvar("amx_rolechange","1") because if its set to 0, and I join then it wont change my role unless its set too 1 and then because im not connecting it wont set a role on me unless I reconnect which I cant without remaking the server.

// Role Adder v1.0 by RPRaiden
// When client connect to a game the console automaticly
// adds a role to the end of the players name.
// WARNING: BETA , UNTESTED AND WILL PROPERLY FUCK U UP :P!
// WARNING: IM A N00B SCRIPTER
// WARNING: THIS IS THE 3RD WARNING! :P!
// ------------------------------------------------------------
// TO Enable tpye "amx_rolechange 1" and the rolechanger will change roles.
// Enjoy - [email protected]
// ------------------------------------------------------------

#include <amxmodx>

public plugin_init() {
register_plugin("Role Adder","1.0","RPRaiden")
//register_cvar("amx_rolechange","1")
register_cvar("amx_roleone", "Name %name%[Civ]")
}

public client_putinserver(id){
new user[32], len
user[0] = id
len = get_user_name(id,user[1],31)
set_task(2.0, "addrole", 0, user,len + 2)
return PLUGIN_CONTINUE
}

//public client_disconnect(id){
// new user[32], len
// user[0] = id
// len = get_user_name(id, user[1], 31)
// set_task(2.0, "removerole", 0, user, len + 2)
// return PLUGIN_CONTINUE
//}


public addrole(user[]) {
// if (get_cvar_num("amx_rolechange")==0){
// return PLUGIN_HANDLED
// }
if (get_cvar_num("amx_rolechange")==1){

new role[192]
get_cvar_string("amx_roleone", role, 191)
replace (role, 191, "%name%", user[1])
set_user_info( user[1],"name","%name%[Civ]")
remove_task(0, 0);
}
return PLUGIN_CONTINUE
}


I compile it and get the error:

rolechange.sma(49) : warning 217: loose identation

I understand theres a error in rolechange.sma on line 49, but line 49 but the actual error itself is over my head. Can you help me?

IceMouse[WrG]
04-23-2004, 18:30
It isn't an error... It's a warning to inform you that you might have made a mistake... That one is often a copy&paste error... It will run fine

RPRaiden
04-23-2004, 18:40
yay
EDIT: it doesnt work :(, I made a lan game and nothing happened to my name :(

IceMouse[WrG]
04-23-2004, 19:03
// Role Adder v1.0 by RPRaiden
// When client connect to a game the console automaticly
// adds a role to the end of the players name.
// WARNING: BETA , UNTESTED AND WILL PROPERLY FUCK U UP :P!
// WARNING: IM A N00B SCRIPTER
// WARNING: THIS IS THE 3RD WARNING! :P!
// ------------------------------------------------------------
// TO Enable tpye "amx_rolechange 1" and the rolechanger will change roles.
// Enjoy - [email protected]
// ------------------------------------------------------------

#include <amxmodx>

public plugin_init() {
register_plugin("Role Adder","1.0","RPRaiden")
//register_cvar("amx_rolechange","1")
register_cvar("amx_roleone", "Name %name%[Civ]")
}

public client_putinserver(id){
new user[32], len
user[0] = id
len = get_user_name(id,user[1],31)
set_task(2.0, "addrole", 0, user,len + 2)
return PLUGIN_CONTINUE
}

//public client_disconnect(id){
// new user[32], len
// user[0] = id
// len = get_user_name(id, user[1], 31)
// set_task(2.0, "removerole", 0, user, len + 2)
// return PLUGIN_CONTINUE
//}


public addrole(user[]) {
// if (get_cvar_num("amx_rolechange")==0){
// return PLUGIN_HANDLED
// }
if (get_cvar_num("amx_rolechange")==1){

new role[192]
get_cvar_string("amx_roleone", role, 191)
replace (role, 191, "%name%", user[1])
set_user_info( user[1],"name","%name%[Civ]")
remove_task(0, 0);
}
return PLUGIN_CONTINUE
}

Change
//register_cvar("amx_rolechange","1")
to
register_cvar("amx_rolechange","1")

RPRaiden
04-23-2004, 19:14
but nobody can join the server so when I activate the cvar from 0 to 1 it wont change my name because Im not "connecting".??

*EDIT:That worked, thanks m8..... allthough I need to define a variable to store the users existing name and then call upon that variabe in the set_user_info instead of using %name& because it changes my name from "RPRaiden" to " name [Civ]"

IceMouse[WrG]
04-23-2004, 19:16
JUST DO IT

RPRaiden
04-23-2004, 19:29
Sorry should of told you I was trying it, I just said what I though. Your a genius :P

Look at my previous post ^^

IceMouse[WrG]
04-23-2004, 19:34
Switch
new role[192]
get_cvar_string("amx_roleone", role, 191)
replace (role, 191, "%name%", user[1])
set_user_info( user[1],"name","%name%[Civ]")
remove_task(0, 0);
with
new role[192]
new name[33];
get_user_name(user[0],name,33);
get_cvar_string("amx_roleone", role, 191)
replace (role, 191, "%name%", name)
set_user_info( user[0],"name",role)

RPRaiden
04-23-2004, 19:38
Cheers, could you enlighten me on what I was doing wrong , I noticed the changes and understood a vast majority of them. for example, get_user_name, I understood what that was there too do and why you did it.

Cheers again

IceMouse[WrG]
04-23-2004, 19:42
First of all, you weren't using role to change the name, you were setting thier name to "%name%[Civ]" and we know that %'s don't show up in HL names, so it showed up as " name [Civ]" in game.
NEXT, you were using user[1] in the loop, when it doesn't exist... You needed to use user[0]
And last, you were replacing "%name%" with user[1], which IF it existed would put in a number(If it was user[0], it would put in thier id), so you had to get thier name, first

RPRaiden
04-23-2004, 19:45
okay I understand that now , I based some of my code upon plugins I read through.

It works but with some disadvantages:
Upon connect it changes my name from Raiden to Name Raiden[Civ] , but if I type name "Raiden" in the console it doesnt do anything because it believes my name is still "Raiden". This can be the advantage to prevent people from removing the additional role and prevent them becoming roleless. but the "Name" before has to go, ill atempt it tomorrow or soon.

IceMouse[WrG]
04-23-2004, 19:49
Thats because you have the cvar set to "Name %name%[Civ]"

Make it "%name%[Civ]"

And basically copy and paste the client_putinserver(id) code into a public client_setinfo(id)//(If thats a forward... Look it up) function so that it will switch back if they change names

RPRaiden
04-24-2004, 09:19
public client_setinfo(id)// I cannot find the in the include, whicih one is it in? and also could be a little more clear on what you mean about placing the client_putinserver into the client_setinfo

IceMouse[WrG]
04-24-2004, 13:33
Copy all the code from
public client_putinserver(id)
{
...
}
To
public client_infochanged(id)
{
...
}
It's in amxmodx.inc

RPRaiden
04-24-2004, 14:43
eh?
I understand that now because if user changes there info it will add the role again but you said setinfo?, nm. cheers