ID:1765786
 
Keywords: admin, ckey, key
(See the best response by Mightymo.)
Code:
proc/adminjoin(mob/M)
var/playerkey = ckey.(M.key)
if(playerkey == "name")
usr.admin = 1
return
//mob
// DM
// key = "name"
// admin = 1
//


Problem description:

I am trying to assign a 1 to the admin variable when the player matches the name placeholder, I am a bit stuck on how to do it i have tried a few things like above and think that it can be done with ckey or key but am not entirely sure how
the commented out bit was working but the player model would disappear when i did that, and i am unsure why it was not due to code running from having admin cause i tested by assigning admin by default.

could i please get some advice Thanks :)

Best response
var/playerkey = ckey.(M.key)

should be
var/playerkey = ckey(M.key)


However, since this is a proc, I would highly advise against using usr in it.
Personally, I would use switch(M.ckey) then if("[ckey]") M.admin=1
I would actually create a list, I think. It would be easier to add to.
var/list/admins = list("mightymo","nnaaaahh","fxstriker")
proc/adminjoin(mob/M)
if(ckey(M.key) in admins)
M.admin = 1
In response to Mightymo
I don't remember why I strayed from that, but I had some issue with using a list for comparing text that way.
In response to Mightymo
Mightymo wrote:
I would actually create a list, I think. It would be easier to add to.
var/list/admins = list("mightymo","nnaaaahh","fxstriker")
proc/adminjoin(mob/M)
if(ckey(M.key) in admins)
M.admin = 1


Better:
mob/proc/adminjoin
if(ckey in admins)
admin = 1

This should be a mob proc, not a global proc taking a mob as an argument.
Code:
var/list/admins = list("fxstriker")
proc/adminjoin(mob/M)
if(ckey(M.key) in admins)
M.admin = 1
admin()
return


Thanks for the help guys, was trying a few things, I like the list idea i was thinking short term but future proofing these sorts of things is a good idea :) i am getting this error when the proc is run when it is called on Login()

runtime error: Cannot read null.key
proc name: adminjoin (/proc/adminjoin)
usr: Fxstriker (/mob/player)
src: null
call stack:
adminjoin(null)
Fxstriker (/mob/player): Login()


am i missing something simple ?
I don't know why you made it a global proc lol what Lummox suggested is extremely easy and much more easy on the eyes
In response to Fxstriker
The way you have it you would need to pass a mob.
adminjoin(M)

If you do as Lummox suggests (and you should), you would call it as
M.adminjoin()

Both assume you have a mob M.
Here's my reasoning for making it a mob proc: When you write a proc, you should think about what it should belong to. Which item does it primarily act upon? Does it make more sense as a global proc, or does it interact mostly with a single mob, obj, etc.?
Yeah i understand why to use a mob proc i was messing with a few things at one stage it was a verb and i got that to work but ideally no one would see a verb saying make me admin if name matches xD

I am still a little new to beyond so i am a bit confused about a few of the best / common practices

should this
var/list/admins = list("fxstriker")
proc/adminjoin(mob/M)


be like this instead ? cause this is throwing a compile error

var/list/admins = list("fxstriker")
proc/M.adminjoin()


i am calling it from a log in proc like this

mob
Login()
ability()
Spawn()
adminjoin()


Not this:
proc/M.adminjoin()

This:
mob/proc/adminjoin()
In response to Fxstriker
To clarify, using
M.adminjoin()

would be for if you were calling it from outside of the mob itself, not for when you declare the proc. The declaration is as Lummox puts it. Sorry if I wasn't clear.