Jump to content
  • 0

Item distribution...


Hijirikawa

Question


  • Group:  Members
  • Topic Count:  19
  • Topics Per Day:  0.01
  • Content Count:  193
  • Reputation:   41
  • Joined:  07/21/16
  • Last Seen:  

I'm trying to make a script wherein an item is randomly given to a person inside a party, however, I have no idea  as to how to remove the person from the list if he's offline or if he's not in the same map as the person who killed the mob, if any small snippet or hint is given, I would really appreciate it.

Thanks in advance.

I had an experiement before and came up with this, but I don't think it's really that good, nor does it exclude offline members or members outside of the map.

 

		getpartymember .@partyid,2;
		.@rand = rand($@partymembercount);
		.@getsloot = $@partymemberaid[.@rand];
		getpartymember .@partyid,0;
		.@getname$ = $@partymembername$[.@rand];
		dispbottom "Loot has been assigned to: "+$@partymembername$[.@rand];
        detachrid;
        attachrid(.@getsloot);
		.@cid = getcharid(0,.@getname$);
        if(strcharinfo(3,.@cid) != .@map_name$){
			dispbottom "You failed to get the item because you are not in the same map as your party members.";
			end;
		}

 

Edited by Hijirikawa
Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

  • Group:  Members
  • Topic Count:  16
  • Topics Per Day:  0.01
  • Content Count:  38
  • Reputation:   1
  • Joined:  01/09/17
  • Last Seen:  

Couldn't you set up a loop? There should be scripts in your custom folder with examples of finding out where someone is or if he's online. Shifty assassin is one example.  

I think those functions return 0 if the players not online or can't be found, so you might be able to set it up so that if the function returns 0 you return to the beginning of the loop and do a re-roll basically. 

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  19
  • Topics Per Day:  0.01
  • Content Count:  193
  • Reputation:   41
  • Joined:  07/21/16
  • Last Seen:  

Oh thanks for the heads up. I'll check that part then, I haven't really looked at that NPC at all.

So I took a look at it, I believe my best bet would be to run a loop and check if the character is on the same map as to where the monster was killed, if not, he will be taken off the list of members who could receive the reward whilst offline members will also be treated the same way.

I suppose using getpartymember should be used, though do I need to copy the array to another array, or just leave it as is and just edit it as I see fit? perhaps copying it into a temporary array and making that temporary array my main array to base it will be the best way just to avoid discrepancies because I have no idea if that party array might get changed or something later on in the script.

Edited by Hijirikawa
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  16
  • Topics Per Day:  0.01
  • Content Count:  38
  • Reputation:   1
  • Joined:  01/09/17
  • Last Seen:  

Well, I'd assume the script is going to be run at a particular time within an instance or on the death of a mob/end of a quest, etc? If that's the case the script should be run just at that moment, which would preclude any circumstance where someone getting credit/not getting credit for being there or in the party would occur. If it's run anytime before the actual reward is given, then there's a chance that party changes or deaths would be a problem.

I'm still haven't gotten to familiar with the coding, but if possible I would get the id's of the party members who were responsible to the kill/completion and put those into a list, then check each of those to see who's online, then do the random pick. So I think the base array would probably be the better choice but it's probably possible to simplify it. I don't know off the top of my head though.

Link to comment
Share on other sites

  • 0

  • Group:  Forum Moderator
  • Topic Count:  33
  • Topics Per Day:  0.01
  • Content Count:  1268
  • Reputation:   382
  • Joined:  02/03/12
  • Last Seen:  

19 hours ago, Hijirikawa said:

I'm trying to make a script wherein an item is randomly given to a person inside a party, however, I have no idea  as to how to remove the person from the list if he's offline or if he's not in the same map as the person who killed the mob, if any small snippet or hint is given, I would really appreciate it.

Thanks in advance.

This isn't really the typical way of doing something like you've requested but I wanted to show that it can be done pretty easily with addrid.

prontera,162,186,1	script	addrid_test	100,{
	function	addrid_func	{
		.@enter = 1;
		setd( ".map_"+getarg(0)+"$", getarg(1) );
		addrid( 2, 0, getarg(0) );
		.@map$ = getd( ".map_"+getcharid(1)+"$" );
		if( strcharinfo(3) == .@map$ )
			setd( ".party_"+getcharid(1)+"$["+getarraysize( getd( ".party_"+getcharid(1)+"$" ) )+"]", getcharid(3) );
		if( .@enter ) return rand( getarraysize( getd( ".party_"+getcharid(1)+"$" ) ) ); else end;
	}
	.@party_id = getcharid(1);
	.@rand = addrid_func( .@party_id, strcharinfo(3) );
	.@lucky_aid = getd( ".party_"+.@party_id+"$["+.@rand+"]" );
	getitem 512, 10, .@lucky_aid;
	announce "Loot has been assigned to: "+rid2name( .@lucky_aid )+".", bc_pc|bc_area;
	setd( ".map_"+.@party_id+"$", "" );
	deletearray getd( ".party_"+.@party_id+"$" );
	end;
}

 

Link to comment
Share on other sites

  • 0

  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10015
  • Reputation:   2348
  • Joined:  10/28/11
  • Last Seen:  

this should work too :D



getpartymember getcharid(1);
.@count = $@partymembercount;
copyarray .@pt_aid, $@partymemberaid, .@count;
.@i = -1;
do {
	if ( .@i >= 0 && .@count ) {
		deletearray .@pt_aid[.@i],1;
		.@count--;
	}
	if ( .@count ) {
		.@i = rand( .@count );
		if ( attachrid( .@pt_aid[.@i] ) ) {
			if ( strcharinfo(3) == .@map$ ) {
				.@aid = .@pt_aid[.@i];
			}	
			detachrid;
		}
	}
} while( .@aid <= 0 && .@count );

if ( .@aid ) {
	getitem 512,1,.@aid;
	getitem 512,2,.@aid;
	getitem 512,3,.@aid;
}

 

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  303
  • Reputation:   117
  • Joined:  12/10/16
  • Last Seen:  

I made this function a long time ago.

	// callfunc "party_randomattach",party,required map to be in;
function    script    party_randomattach    {
    .@party = getarg(0,getcharid(1));
    .@map$ = getarg(1,""); 
    if(.@party){
        getpartymember(.@party,1,.@party_cid);
        getpartymember(.@party,2,.@party_aid);
        .@n = $@partymembercount;
        for(;.@i<.@n;.@i++){
            if(isloggedin(.@party_aid[.@i],.@party_cid[.@i])){
                attachrid(.@party_aid[.@i]);
                if(.@map$!=""&&.@map$!=strcharinfo(3))
                    deletearray(.@party_aid[.@i],1);
            }else
                deletearray(.@party_aid[.@i],1);
        }
        attachrid(.@party_aid[rand(getarraysize(.@party_aid))]);
    }
    return;
}
// callfunc "party_randomattach",.@party_id,"payon"; getitem 512,5;
// callfunc "party_randomattach",getcharid(1),strcharinfo(3); getitem 513,5;
// callfunc "party_randomattach"; getitem 512,5;
	

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...