DragonPrime - LoGD Resource Community
Welcome Guest
  • Good evening, Guest.
    Please log in, or register.
  • December 11, 2018, 12:40:57 AM
Home Forums News Downloads Login Register Advanced Search
* * *
DragonPrime Menu
Login
 
 
Resource Pages
Search

Pages: [1]   Go Down
  Print  
Author Topic: Automatically Input Names  (Read 533 times)
0 Members and 2 Guests are viewing this topic.
Megan|SaraBeth
Mod God
*****
Offline Offline

Posts: 1065



View Profile WWW
« 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.
Logged

Aeolus
Mod God
*****
Offline Offline

Posts: 1912


You're welcome.


View Profile WWW
« Reply #1 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?
Logged

Megan|SaraBeth
Mod God
*****
Offline Offline

Posts: 1065



View Profile WWW
« Reply #2 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.
Logged

TGTarheel
Codemeister
****
Offline Offline

Posts: 491


View Profile
« Reply #3 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?
Logged
Aeolus
Mod God
*****
Offline Offline

Posts: 1912


You're welcome.


View Profile WWW
« Reply #4 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?
Logged

TGTarheel
Codemeister
****
Offline Offline

Posts: 491


View Profile
« Reply #5 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.
Logged
TGTarheel
Codemeister
****
Offline Offline

Posts: 491


View Profile
« Reply #6 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.
« Last Edit: November 10, 2018, 11:06:50 PM by TGTarheel » Logged
Megan|SaraBeth
Mod God
*****
Offline Offline

Posts: 1065



View Profile WWW
« Reply #7 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.
Logged

TGTarheel
Codemeister
****
Offline Offline

Posts: 491


View Profile
« Reply #8 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.
« Last Edit: November 12, 2018, 08:22:37 PM by TGTarheel » Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  


*
DragonPrime Notices
Welcome to DragonPrime - The LoGD Resource Community!

Support Us
No funds raised yet this year
Your help is greatly appreciated!
Recent Topics
DragonPrime LoGD
Who's Online
56 Guests, 0 Users
Home Forums News Downloads Login Register Advanced Search