Wizard Actions

General Chat, Comments
Post Reply
User avatar
KyleMassacre
Posts: 573
Joined: Wed Nov 27, 2013 12:42 pm

Wizard Actions

Post by KyleMassacre »

Ok, I have an issue here. I am trying to create a module that will award people for winning something. The thing is that some of the wizard actions I can not allow like adding a stat to a user if I want to be able to add an item to a users inventory or the other way around. The reason being is because of the $userId variable which you cant set in the table editor and because that is a global variable for the current logged in user it tends to muck things up.
Here is my function I am trying to create:

Code: Select all

function RewardEventWinner($eventId,$user)
{
    global $db,$userId;
    $userId = $user;
    $award = $db->Execute("select event_prize from koth_events where id = ?",$eventId);
    if(!$award->EOF)
    {
        $userStats = UserStat::LoadStats($user);
        NWEval($award->fields[0]);
        UserStat::SaveStats(NULL,$user);
        $db->Execute("update users set stats_modified = 'yes' where id = ?", $user);
    }
}
If I take out the global for the $userId and what is on line 4 I wont be able to award an Item and can only award a stat change. And If I keep those lines in I can add an Item but when it comes to a stats change it gives that user my amount of that stat.

Is there anyone here who can maybe think of a work around?
User avatar
62896dude
Posts: 516
Joined: Thu Jan 20, 2011 2:39 am

Re: Wizard Actions

Post by 62896dude »

I'm not sure I fully understand the problem, but couldn't you make a stat change the equivalent of rewarding an item? For example, you award a shield, which has an item id of 35. You then set that field in the user's table to 35. I'm just spit-balling though.
Languages: C++, C#, Javascript + Angular, PHP
Programs: Webstorm 2017, Notepad++, Photoshop
Current Project: HP Destiny
User avatar
KyleMassacre
Posts: 573
Joined: Wed Nov 27, 2013 12:42 pm

Re: Wizard Actions

Post by KyleMassacre »

I know what you mean but that is a lot more work for me and will be a lot less for whoever picks this up. Inside the table editor for NWE I can make it so it uses "wizard actions". For example, inside there is a bunch of functions that someone can use like Add Item which translates in the database which gets ran through that "NWEval()" to something like: Item::AddInventoryObject($itemId,$qty); The problem I am having is that there is a third parameter of that particular Class::Object for the user's id which is set to the global variable $userId if param 3 is null. The table editor doesn't allow for you to put in a user id. Similar to what you would see here:
http://imgur.com/3ay9Lfh

This allows it to be a lot more dynamic but the problem is that it all relies on the global $userId which is the current logged in user i.e. $_SESSION['userid'].

But now that I am thinking about all this, I created a module back where I kind of needed to do the same thing but was done through an external file so maybe I can try performing a HTTP request through cURL. Maybe that way I can trick the file into thinking that the server is logged in for the user
User avatar
62896dude
Posts: 516
Joined: Thu Jan 20, 2011 2:39 am

Re: Wizard Actions

Post by 62896dude »

I see what you're saying now. Yeah you might be able to trick the file, or is it not possible to just change the module so that the third parameter isn't automatically the active session's userid? Or would that mess up too many other aspects of the module?
Languages: C++, C#, Javascript + Angular, PHP
Programs: Webstorm 2017, Notepad++, Photoshop
Current Project: HP Destiny
User avatar
KyleMassacre
Posts: 573
Joined: Wed Nov 27, 2013 12:42 pm

Re: Wizard Actions

Post by KyleMassacre »

62896dude wrote:I see what you're saying now. Yeah you might be able to trick the file, or is it not possible to just change the module so that the third parameter isn't automatically the active session's userid? Or would that mess up too many other aspects of the module?
I think the latter would happen. I know you don't use NWE but the beauty about this engine is that it's supposed to be plug and play. Meaning I can't/don't touch any file that is outside of the modules directory and I am "not supposed" to touch any existing table in the database, though I think there are times when there can be an exception like setting a default and hopefully who ever created the module/table names their columns in their queries. And I can't touch any file that is not in my module directory. So there lies my problem since I am kind of limited on ways I can get this done. I think the HTTP request is probably my only option at this time.

I was thinking of possibly trying a combo of like exploding the function, getting the arguments of that function and a call_user_func_array but that would get a little hairy I think with all the possibilities there are in the wizard actions table especially since not everything in there is a Class::Method pair but an $object[array_key]->method type deal as well so forecasting all the potential possibilities could be a lot of work
KaL
Posts: 344
Joined: Mon Jan 13, 2014 5:44 am

Re: Wizard Actions

Post by KaL »

How about if you use the if statement:

Example:

If ($result->field[0] == userstats)
{
Userstats(level,$num,$user);
}
Else
{
NWEval(result->field[0]);
}

That's why I write my own table. It's longer but I copy and paste
User avatar
KyleMassacre
Posts: 573
Joined: Wed Nov 27, 2013 12:42 pm

Re: Wizard Actions

Post by KyleMassacre »

Yeah that's too much work. Then if someone creates an new wizard then I need to update for that.
Post Reply

Return to “General”