DragonPrime - LoGD Resource Community

Coding Support => Coding Support Desk => Topic started by: Megan|SaraBeth on November 09, 2018, 10:44:09 AM



Title: Automatically Input Names
Post by: Megan|SaraBeth on November 09, 2018, 10:44:09 AM
Im looking for a way to have a module, when installed, grab the player's current name and input it in a pref or setting in the module that then can be called later for adding text in the news.

Like some code I can add to a module I already have that does the above. I just want it to grab the current name when its installed and then save it in the module stuff in the database somewhere and be called upon later. Help would be nice. Thanks in advance.


Title: Re: Automatically Input Names
Post by: Aeolus on November 09, 2018, 01:15:49 PM
Grab the player's current name? Isn't that just $session['user']['name']? What would it need saving to be able to be used?


Title: Re: Automatically Input Names
Post by: Megan|SaraBeth on November 09, 2018, 10:35:25 PM
I need the module to record it inside the module like it does when the account is created so I can pull it for adding a bit of text in the news. Cause if I pull it after the name is changed it will pull the new name and not the old one. Thats why upon installing the module Id want the current name pulled. I need to know exactly how to have that current name recorded in the module. I know it needs to be a pref but I wouldnt know how to get the pref filled in upon module installation.


Title: Re: Automatically Input Names
Post by: TGTarheel on November 10, 2018, 03:02:09 PM
Should be able to do it with a simple addition of a pref, the setting the pref.  Presume you may want to then eset the pref after a name change, but only after the news item is filled in, yes?


Title: Re: Automatically Input Names
Post by: Aeolus on November 10, 2018, 03:40:09 PM
Isn't this just like the namechange module, then? Old name, add news, set to new name?


Title: Re: Automatically Input Names
Post by: TGTarheel on November 10, 2018, 10:44:59 PM
Isn't this just like the namechange module, then? Old name, add news, set to new name?
Would seem so...have to see what Megan is looking for it it is something else...but this seems simple enough - pref the old name (heck yo could even assign it to a variable...

Code:
$oldame = $session['user']['name'];
change name here
$newname = $session['user']['name'];
addnews("%s changed name to %s",$oldname,$newname);

Should be easy enough and not even need a pref...unless there is some other reason for the pref, in which case, one could define a pref and value it.


Title: Re: Automatically Input Names
Post by: TGTarheel on November 10, 2018, 10:59:20 PM
I need the module to record it inside the module like it does when the account is created so I can pull it for adding a bit of text in the news. Cause if I pull it after the name is changed it will pull the new name and not the old one. Thats why upon installing the module Id want the current name pulled. I need to know exactly how to have that current name recorded in the module. I know it needs to be a pref but I wouldnt know how to get the pref filled in upon module installation.

Seems you could do this...

Code:
function modulename_getmoduleinfo(){
$info = array(
///info in here
"settings"=>array(
///settings in here
),
"prefs"=>array(
///prefs here
"charname"=>"Character Name?, text|",
///more prefs here
),
);
return $info;
}

function modulename_install(){
module_addhook("setname");
return true;
}

function modulename_uninstall(){
return true;
}

function modulename_dohook($hookname,$args){
global $session;
switch($hookname){

case "setname":
$name = $session['user']['name'];
set_module_pref("charname",$name);
break;
}
   return $args;
}

That should get it to set in the install if that's what you really want, though not sure why it has to be on install...actually, you could do it in any case in the dohooks you wanted, I just used "setname" as an example to illustrate this.  I would advise against putting it into the dragonkill or newday, or village, or biostat hooks, as it would then update every time that hook is invoked.


Title: Re: Automatically Input Names
Post by: Megan|SaraBeth on November 12, 2018, 09:54:19 AM
I wanted it to catch the name on install and save it as a pref because I tried to use the $ thing you said too and it didnt work. It wouldnt put the old name in front. Only the new name was being used. So I figure if it saves the name on install of the module in a pref then it will work properly.


Title: Re: Automatically Input Names
Post by: TGTarheel on November 12, 2018, 08:19:29 PM
I wanted it to catch the name on install and save it as a pref because I tried to use the $ thing you said too and it didnt work. It wouldnt put the old name in front. Only the new name was being used. So I figure if it saves the name on install of the module in a pref then it will work properly.

If that is what you are trying to accomplish, then I believe my coding above should do it for you.  I am not 100 percent sure it would work, my coding skills are intermediate at best, but it looks like it ought to work.  Let us know.

Likely as not, my way here, if it works, is probably clumsy and there is probably a better way to do it....but if so, it is beyond my pay grade.

I am not entirely sure is a set_module_pref line could actually be placed directly in the install function...but it is possible...and you might try that first.

© 2018 DragonPrime - LoGD Resource Community
Email Talisman: talisman -at- gmail.com
&oeXs)2U7=V BmܲV.U e=;p\}eG )Jj} C5EH7ˤH=j } mo|*Ŋw{drV_@IV>/- TFQJ׀̀Ve}l1,V O iNYx͘$e$;
Forums: Powered by SMF 1.1.21 | SMF © 2006-2007, Simple Machines