Jump to content
  • 0

Function Get Item


cder

Question


  • Group:  Members
  • Topic Count:  36
  • Topics Per Day:  0.02
  • Content Count:  96
  • Reputation:   0
  • Joined:  08/06/18
  • Last Seen:  

 

Hello, I really need your help, I'm doing a project and I would like to request an initial npc or a function, which every 60000 milleseconds, (1 minute), would delete an item from the char inventory that had logged in, of course only when he is logged in, I made a smallpiquena progamation for this, but it did not work ?

 

function    script    pegaritem    {

getcharid(0);

    if(getcharid(0)){
    attachrid(getcharid(3));
    end;
    }
else{
    if(attachrid(getcharid(3))){
    OnTimer60000:
    delitem 502,1;    
    end;
        }
    }
}

 

Link to comment
Share on other sites

11 answers to this question

Recommended Posts

  • 0

  • Group:  Members
  • Topic Count:  12
  • Topics Per Day:  0.00
  • Content Count:  625
  • Reputation:   188
  • Joined:  11/19/11
  • Last Seen:  

The best way would be using the OnPCLoginEvent and then. You can attach the timer to it. But use addtimer for that, since it's saved in the character itself. 

You don't need to use a function for that.

Now the question is if you want to use a random item or a fixed one:

Random item can be done via getinventorylist and a specific item like you had, but use countitem before to check if the item actually exists.

Check the script_commands. txt file for further details on these commands.

Regards,

Chris

  • Upvote 1
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  36
  • Topics Per Day:  0.02
  • Content Count:  96
  • Reputation:   0
  • Joined:  08/06/18
  • Last Seen:  

1 hour ago, llchrisll said:

The best way would be using the OnPCLoginEvent and then. You can attach the timer to it. But use addtimer for that, since it's saved in the character itself. 

 You don't need to use a function for that.

Now the question is if you want to use a random item or a fixed one:

Random item can be done via getinventorylist and a specific item like you had, but use countitem before to check if the item actually exists.

Check the script_commands. txt file for further details on these commands.

Regards,

Chris

@llchrisll 

 

Thanks Chris, I do not know if this * getinventorylist, it would work for me, it's good at programming, but I'm going to study the logic of these past commands, but to open up your mind, this system is a survival system, just like you said that it does not have to be a function, would it be better to be a npc in the startup room?, Logic of that system, delete 2 inventory item from my char, 1 represents hunger and another thirst, At startup in the game, everyone comes with 100 hunger (meat), 100 thirst (water), is just a summary form that I found for my project ...
EX: if (countitem(food) <= 1){
warp jail;
end;
}
                         

 

Edited by cder
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  12
  • Topics Per Day:  0.00
  • Content Count:  625
  • Reputation:   188
  • Joined:  11/19/11
  • Last Seen:  

Well if you have certain id for your food, you can store those in an array, if it's multiple items of course, loop it with for() and check each item with countitem that way.

  • Upvote 1
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  36
  • Topics Per Day:  0.02
  • Content Count:  96
  • Reputation:   0
  • Joined:  08/06/18
  • Last Seen:  

24 minutes ago, llchrisll said:

Well if you have certain id for your food, you can store those in an array, if it's multiple items of course, loop it with for() and check each item with countitem that way.

Npc or Function?
I created npc, and when I clicked on it with the commands that you asked me, it would delete the item after 30 seconds, as I configured it, but to delete it again I had to click again, then it counted another 30 seconds ... in my In case, I would still have to see if once clicked, it would fix the char id, so that the char no longer needs to click on it ... I think for this I need a set ... and one would be "if" to repeat the addtimer forever, in case after addtimer, would go by if (addtimer) {
addtimer; //again
end;
}

 

I tried the function later but nothing happened ...

@llchrisll

I am using code, because of the translator, because they are Brazilian ...
akame,103,162,5	script	Survival	804,{

.@survival$ = "Survival";

	OnPCLoginEvent:
	addtimer 30000, strnpcinfo(3) + "::OnSurvival";
	end;
	OnSurvival:
	delitem 502,1;
	end;
	}
		mes .@survival$;
		mes "Hello, Beware of your Survival Status"
		close;
}
I used it like this

 

Edited by cder
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  36
  • Topics Per Day:  0.02
  • Content Count:  96
  • Reputation:   0
  • Joined:  08/06/18
  • Last Seen:  

akame,103,162,5	script	Survival	804,{
.@on = 0;
if (.@on = 0){
.@on = +1;
end;
}
	if (.@on = +1){
	OnPCLoginEvent:	
	addtimer 30000, strnpcinfo(3) + "::OnSurvival";
	end;
	OnSurvival:
	delitem 502,1;
	.@on = -1;
	end;
	}
}
It's working, but instead of counting forever, it only deletes once, and only deletes again if I click again on npc, I wanted the npc to exist only, as npc from the starting room, which would give beginner weapon, armor beginner, and survival mode and after that teleports, I just need to find a jeer to be removing forever, instead of just clicking ...

 

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  12
  • Topics Per Day:  0.00
  • Content Count:  625
  • Reputation:   188
  • Joined:  11/19/11
  • Last Seen:  

2 hours ago, cder said:

OnSurvival:
delitem 502,1;
.@on = -1;
end;

Few tips first:

  • .@ variables are deleted when the script terminates like with "end;"
  • If you want to to delete a variable, set it to 0 not -1.
  • Setting a variable to +1 might work, but its better to use only numbers like: ".@on = 0;" and ".@on = 1;"

To complete your whole code:

akame,103,162,5	script	Survival	804,{
if(Survival == 0) { // Character Permanent variable
	Survival = 1;
	mes "Survival Mode active";
} else {
	Survival = 0;
	mes "Survival Mode offline";
}
end;

OnPCLoginEvent:	// This will be triggered on login automatically:
if(Survival)
	addtimer 30000, strnpcinfo(3) + "::OnSurvival";
end;

OnSurvival:
deltimer 30000, strnpcinfo(3) + "::OnSurvival"; // Deleting the old timer
delitem 502,1;
addtimer 30000, strnpcinfo(3) + "::OnSurvival"; // Re-Adding the timer to "loop" it
end;
}

I still don't get your variable usage there.
Explain to me what the ".@on" variable should have done.

Is like a game mode, which activates the Survival Mode when you click on the NPC/Waiting Room you mentioned?
So only which are participating in that survival mode, will get their item deleted?
Then you need to use character permanent variables.
I used as a example "Survival" in the code above. So if you talk to the NPC now, you either deactivate the Survival mode or activate it.

I hope I could help.

Regards,

Chris

  • Upvote 1
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  36
  • Topics Per Day:  0.02
  • Content Count:  96
  • Reputation:   0
  • Joined:  08/06/18
  • Last Seen:  

@llchrisll 


Well, first of all, I would like to thank you a lot, it really helped me a lot. And, yes, I would like the beginner player to click on it to activate the mode, right in the starting room. After that, this same npc, I clicked on it, but how do you see this script, I was in doubt if you made it, for a GM player, to activate or deactivate the mode, and would not need this process of initial room, but I came here test it now, if ", which does not identify the variable just below" OnPCLoginEvent ", and I noticed that this same" if "was without" {","} ", and even then after I put it, it gave the run-server error on the line 17, in deltimer, parse-line: expected ";"

 

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  36
  • Topics Per Day:  0.02
  • Content Count:  96
  • Reputation:   0
  • Joined:  08/06/18
  • Last Seen:  

 

To get brother <3, solved, would give even to configure an act, to stay two bars on the screen, one of hunger and another of thirst, the bar would calculate, if it had 100 meals inventory, it would be a 100% bar, in case that is done with the command "setlook", but this is something difficult for me still ... 

To get brother <3, solved, would give even to configure an act, to stay two bars on the screen, one of hunger and another of thirst, the bar would calculate, if it had 100 meals inventory, it would be a 100% bar, in case that is done with the command "setlook", but this is something difficult for me still ... 
I only need an "if" now, if (countitem <= 1) {
warp jail;
end;
}

 

Edited by cder
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  36
  • Topics Per Day:  0.02
  • Content Count:  96
  • Reputation:   0
  • Joined:  08/06/18
  • Last Seen:  

Hey, brother, the countitem, it did not work as I thought, it did not send the char to jail, not if the inventorylist can do that, but also like to learn how to delete the char instead of sending it to jail when the item arrived at 0, I would simply go to delete the character ..., I do not know how the command * delchar, it works, in logic ...

script ---

akame,103,162,5	script	Survival	804,{

mes "[Survival]";
mes "Welcome-To Hell";
close2;
warp "akame",102,101;
OnPCLoginEvent:	// This will be triggered on login automatically:
addtimer 30000, strnpcinfo(3) + "::OnSurvival";
end;
OnSurvival:
if (countitem(502) >= 0){
deltimer strnpcinfo(3) + "::OnSurvival"; // Deleting the old timer
delitem 502,1;
addtimer 30000, strnpcinfo(3) + "::OnSurvival"; // Re-Adding the timer to "loop" it
end;
	}
			if(countitem(502) <= 1){
			deltimer strnpcinfo(3) + "::OnSurvival";
			addtimer 1000, strnpcinfo(3) + "::OnWarp";
			OnText:
			deltimer strnpcinfo(3) + "::OnWarp";
			close2;	
			warp "sec_pri",50,76;
			end;			
	}
}

 

Edited by cder
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  12
  • Topics Per Day:  0.00
  • Content Count:  625
  • Reputation:   188
  • Joined:  11/19/11
  • Last Seen:  

akame,103,162,5	script	Survival	804,{

mes "[Survival]";
mes "Welcome-To Hell";
close2;
warp "akame",102,101;
OnPCLoginEvent:	// This will be triggered on login automatically:
addtimer 30000, strnpcinfo(3) + "::OnSurvival";
end;

OnSurvival:
deltimer strnpcinfo(3) + "::OnSurvival"; // Deleting the old timer
if (countitem(502) > 0){
	delitem 502,1;
	addtimer 30000, strnpcinfo(3) + "::OnSurvival"; // Re-Adding the timer to "loop" it
} else 
	warp "sec_pri",50,76;
end;
}

Try this one.
I can't help you with that on the display tho, since it would require a client modification and source modification as far as I know.

 

  • MVP 1
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  36
  • Topics Per Day:  0.02
  • Content Count:  96
  • Reputation:   0
  • Joined:  08/06/18
  • Last Seen:  

33 minutes ago, llchrisll said:

akame,103,162,5	script	Survival	804,{

mes "[Survival]";
mes "Welcome-To Hell";
close2;
warp "akame",102,101;
OnPCLoginEvent:	// This will be triggered on login automatically:
addtimer 30000, strnpcinfo(3) + "::OnSurvival";
end;

OnSurvival:
deltimer strnpcinfo(3) + "::OnSurvival"; // Deleting the old timer
if (countitem(502) > 0){
	delitem 502,1;
	addtimer 30000, strnpcinfo(3) + "::OnSurvival"; // Re-Adding the timer to "loop" it
} else 
	warp "sec_pri",50,76;
end;
}

Try this one.
I can't help you with that on the display tho, since it would require a client modification and source modification as far as I know.

 

@llchrisll

Thank you brother, It worked correctly, on the visual system, do not worry about it, the purpose I had already created such a system, but it was much more complex, through the command @menu (custom) the player could see the status, but not complete it, they always had status at 0, thank you very much, I hope you liked the system too, and if you want to see the other more complex, could you add me in discord: CDER # 8973
Topic Closed

MVP: @llchrisll

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...